I am trying to output a graph and table for each group to one page of a PDF (one page for each group). I am nearly there but I am just having trouble with the final step. I have both a table and a plot on the same page but the table is on top of the plot. When I move it outside of the plot window it disappears.
Is there a way I can put the graph underneath the plot (which is outside of the plot window)?
Here is my code:
lss <- read.csv(file="WithBlanksFilled_4.csv",head=TRUE, sep=",") # read in csv and name columns
st<-lss$server_type
tenant <- lss$tenant_n
date<- lss$date_time
ss <- lss$Max_load_source_size
df1 <- data.frame(st, tenant, date, ss)
#Create graph which will then be populated by output of dlply
library(ggplot2)
library(scales)
library(grid)
library(gridExtra)
library(gtable)
p<-ggplot(df1, aes(x=as.Date(date, "%d/%m/%Y %H:%M"), y=ss))+geom_point()+labs(x="Date", y="Load Source Size")+facet_wrap(~st+tenant, ncol=1)+scale_x_date(breaks = date_breaks("week"), minor_breaks=date_breaks("1 day"), labels = date_format("%d-%b"), limits = c(as.Date("2014-09-06"), as.Date("2014-12-01"))) + theme(axis.text.x = element_text(size=5, color="grey"), plot.margin=unit(c(1,1,5,1), "cm"), panel.border=element_blank()) +ylim(0,NA)
#p1 <- ggplot_gtable(ggplot_build(p))
#p1$layout$clip[p1$layout$name=="panel"] <- "off"
#Grouping by t&st
library(plyr)
plots<-dlply(df1, .(st, tenant), function(df1) p %+% df1 %+% annotation_custom(tableGrob(df1), ymin=-2, ymax=-2))
#outputting graphs table to PDF.
pdf(file = file.path("<filepath>.pdf"), onefile=TRUE)
plots
dev.off()