2016-01-24 51 views
-1

我试图用gglot将使用grid.text制作的注释制作的数字保存到使用ggsave的tiff中。但是,ggsave不包含注释。我尝试使用grid.arrange和arrangeGrob(如以前的帖子中所建议的),但它表示既没有找到函数。自从发布这些答案以后,似乎对这些软件包进行了一些更改?ggsave()带注释后的ggplot()

{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)

回答

0

相反的grid.text(),尝试annotate()。这是因为grid.text()添加了一个外部注释,该注释实际上并未保存在您的图的结构中(https://stackoverflow.com/a/12115836)。

在非常简单的例子,下面的代码创建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) 
+0

请详细说明这个答案。 – ppovoski