[R] Adding text for written comments to bottom of graphs
pjmiller_57 at yahoo.com
Sat Mar 31 17:41:38 CEST 2012
What you've done is very interesting. Went through and tried to understand all the steps. Reminded me of studying languages in years gone by. Always found it easier to read and understand a sentence than to construct a sentence of one's own. This is particularly true when you're just learning.
Think I basically get it. You've got a function (make_title) that creates the title for each graph. You've got another function (make_graph) that actually creates each graph and gives it a title using the first function. You're then applying the make_graph function to each value of key_line in the TestData dataframe using dlply. dlply is being used instead of by() because you want to start with a data frame and then end up with a list.
Next, you use a function called make_annotation to add the comment lines to each graph. The make_annotation function uses arrangeGrob() from the gridExtra package. You apply the function using llply this time because you are starting out with a list and want to end up with a list.
Finally, you're outputting the annotated plots to the pdf destination which can handle multiple plots if you specify "multiple_pages.pdf". This seems a lot better than outputting individual graphs and then inserting them into a Word document as I have been doing. The height and width of the page are determined by the height and width options.
At this point, was hoping you could help with refining the output. I've looked at the help page for pdf() and can't see how to modify the code in the ways I'd like. Online searches and an examination of my various R books haven't turned up much either.
So here's what I'd like to do if possible:
1. Get the output to open at 100% magnification. This would be nice but isn't all that important.
2. Add a document title to the top of just the first page (e.g., "Regimen Patterns for Study X").
3. Add 1 inch margins around the page.
4. Make the comment lines roughly (or exactly) the same width as the graphs and justify the text under the graphs.
5. Shrink the size of each graph/comment combination so it's possible to fit two such combinations on a page.
More information about the R-help