Ellen
unread,Oct 31, 2012, 12:24:40 PM10/31/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggp...@googlegroups.com
Dear all,
I have a problem using the grid.arrange function in the gridExtra package to put multiple plots in one window. I want to plot seven scatterplots (dataset 1) and one barchart (dataset 2), and the latter seems to be compressed laterally (such that you cannot even see the bars!) when I save the image as a pdf. In attach you can find the dput output with the two datasets. Below you can find the code I used to create the plots.
plot.H.poc<-ggplot(div.env,aes(res.POC.SED,res.H.SED))+geom_point()
plot.H.poc<-plot.H.poc+geom_smooth(method="lm",formula=y~poly(x,2),se=F,colour="black")+opts(panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())+labs(x="POC",y="H'")
plot.H.SED<-ggplot(div.env,aes(res.SED.POC,res.H.POC))+geom_point()
plot.H.SED<-plot.H.SED+geom_smooth(method="lm",se=F,colour="black")+opts(panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())+labs(x="SED",y="H'")
plot.J.SVI<-ggplot(div.env,aes(SVI,J))+geom_point()+geom_smooth(se=F,method="lm",colour="black")+labs(y="J'",x="SVI")+opts(panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())
plot.EG18.poc<-ggplot(div.env,aes(res.POC.SVI,res.EG18.SVI))+geom_point()
plot.EG18.poc<-plot.EG18.poc+geom_smooth(method="lm",se=F,colour="black")+opts(panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())+labs(x="POC",y="EG(18)")
plot.EG18.SVI<-ggplot(div.env,aes(res.SVI.POC,res.EG18.POC))+geom_point()
plot.EG18.SVI<-plot.EG18.SVI+geom_smooth(method="lm",se=F,colour="black")+opts(panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())+labs(x="SVI",y="EG(18)")
plot.TD.SED<-ggplot(div.env,aes(SED,TD))+geom_point()+geom_smooth(method="lm",se=F,colour="black")+opts(panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())
plot.MI.SVI<-ggplot(div.env,aes(SVI,MI))+geom_point()+geom_smooth(method="lm",se=F,colour="black")+opts(panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())
varpart.plot<-ggplot(varpart,aes(div,fraction))+geom_bar(colour="black",aes(fill=as.factor(var_expl)))+labs(x="",y="Fraction of variation explained (%)")+opts(panel.grid.major=theme_blank(),panel.rid.minor=theme_blank())+scale_fill_manual(values=c("#F5F5F5","#C0C0C0","#696969","white"),guide=guide_legend(" "))+coord_cartesian(ylim=c(0,100))+scale_x_discrete(labels=c("EG(18)","H'","J'","MI","TD"))
library(gridExtra)
pdf("div_env.pdf")
grid.arrange(plot.H.poc,plot.H.SED,plot.J.SVI,plot.EG18.poc,plot.EG18.SVI,plot.TD.SED,plot.MI.SVI,varpart.plot,clip=F)
dev.off()
Does anybody know how to solve this problem?
Thanks!
Ellen