All:
For the last few days I have been trying to create a single page in
PDF with 8 viewports. Four of the viewports are to hold graphics
developed using ggplot2. The other four are to hold simple printouts
of data frames. Creating and placing the four graphs has been real
easy! Getting the data frames to print in the correct viewports has
been a nightmare. The best I can do is to have all the tables print
in the middle of the page, over the graphs and over each other. At
this point, I do not want to learn Latex, Weave (in its various
flavors) and the like. I still need to master R more before I feel
comfortable adding additional layers of complexity. Also,
restrictions on my computer do not allow me to install all Latex
completely. Anyway, here are the key excerpts from the code. If
anyone has any ideas, I would be very appreciative.
Thanks!
Gene
##### Helper function to push individual viewports
##### Source: Hadley, ggplot2, p. 154)
vplayout <- function(x, y)
{
viewport(layout.pos.row = x, layout.pos.col = y)
}
##### Generate Report Page
create_page <- function(rate_ticker)
{
# Assign function outputs to variables
p1 <- full_plot(rate_ticker) # graph
p2 <- daily_diff_plot(rate_ticker) # graph
p3 <- daily_hist_plot(rate_ticker) # graph
p4 <- daily_scatter_plot(rate_ticker) # graph
p5 <- table_1(rate_ticker) # dataframe
p6 <- table_2(rate_ticker) # dataframe
p7 <- table_3(rate_ticker) # dataframe
# Structure the page
plot.new()
pushViewport(viewport(layout = grid.layout(4,2)))
# place graphs in their inidividual viewports - NOTE: This works
fine
print(p1, vp = vplayout(1,1), newpage = FALSE)
print(p2, vp = vplayout(1,2), newpage = FALSE)
print(p3, vp = vplayout(2,1), newpage = FALSE)
print(p4, vp = vplayout(2,2), newpage = FALSE)
# place tables in their inidividual viewports - NOTE: The tables
print oput, but they overwrite the
# graphs and each other.
pushViewport(viewport(layout = grid.layout(3,1)))
par(new = TRUE)
textplot(p5, halign = "center", valign = "center", show.rownames =
FALSE)
pushViewport(viewport(layout = grid.layout(3,2)))
par(new = TRUE)
textplot(p6[1:15,], halign = "center", valign = "center",
show.rownames = FALSE)
pushViewport(viewport(layout = grid.layout(4,1)))
par(new = TRUE)
textplot(p7[1:15,], halign = "center", valign = "center",
show.rownames = FALSE)
}
##### Call function (pass ticker) to generate page
pdf.options(height = 11, width = 8.5, paper = "letter")
pdf("./Output/June2009.pdf")
create_page("US0003M")
dev.off()