i trying save figures made ggplot annotations made grid.text tiffs using ggsave. however, ggsave not incorporate annotation. tried using grid.arrange , arrangegrob (as suggested in previous posts) says neither function can found. seems changes have been made packages since answers posted?
{r} require(reshape2) require(lsr) require(ggplot2) require(ez) require(grid) require(gridextra) source("summaryse.r")
{r} aggregatebw2 = summaryse(aggregatebw1, measurevar="bw", groupvars=c("cond","iso","within")) figure = ggplot(aggregatebw2, aes(x=cond, y=bw, group=within)) + geom_bar(position=position_dodge(), stat="identity", fill="#999999", colour="black") + facet_grid(iso ~ .) + geom_errorbar(aes(ymin=bw-se, ymax=bw+se), width=.2, position=position_dodge(.9)) + scale_x_discrete(name="surgical condition") + scale_y_continuous(name="body weight (g)") + theme(axis.text.x=element_text(size=18), axis.text.y=element_text(size=18), axis.title.x=element_text(size=22), axis.title.y=element_text(size=22), strip.text.y=element_text(size=18)) #+ grid.text(unit(.985,"npc"),0.5,label = "isoflurane percentage", rot = 270, gp=gpar(fontsize=22), check=true) paperfigure = grid.arrange(figure, ncol = 1, bottom = "footnote") ggsave(file="newbodyweight-final.tiff", paperfigure)
instead of grid.text()
, try annotate()
. that's because grid.text()
adds external annotation not saved in structure of plot (https://stackoverflow.com/a/12115836).
in simplified example, code below created this image:
figure=ggplot(iris, aes(x=sepal.width, y=sepal.length))+ geom_point()+ facet_grid(species~.)+ annotate(geom="text", label = "isoflurane percentage", y=6, x=3) ggsave(file="newbodyweight-final.png", figure)
Comments
Post a Comment