2016-01-24 81 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