在将几个ggplot2图形与grid.arrange相结合之后,我试图导出一个大型的清晰图像(RStudio)。我试图导出单击“缩放”按钮时看到的清晰图形,但是当我单击“导出”按钮时,它仅导出缩略图,看起来一点也不专业。我曾尝试使用rangingGrob和ggsave(ggpubr),但它仍会导出我无法使用的图形。如何从此数据中导出高质量的图形?我可以使用截屏工具,但我需要一些更好的东西质量。
我尝试过的最简单的方法是右键单击缩放后的图形,然后单击“保存图像”,但是它将其保存为我无法使用的“所有文件”格式。
万一有人需要它们,以下是我将在此代码中使用的所有数据集(出于示例目的更改了数据):https://drive.google.com/open?id=1_6Mhx3VBrgVmMZpuGuJxz2YVmDcSyiAo
#library(ggplot2)
nine <- ggplot(mean9, aes(x=genotype, y=height, fill=factor(rate)))+
geom_bar(stat="identity", width=0.6, position="dodge", color="black")+
scale_fill_discrete(name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
xlab("Genotype")+ylab("Height")+
geom_errorbar(aes(ymin= mean9$height,ymax=mean9$height+sd9$sd), width=0.2, position = position_dodge(0.6))+
ggtitle("9 DAT Height")+
scale_fill_brewer(palette='PRGn', name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
theme(plot.title = element_text(hjust=0.5))
fifteen <- ggplot(mean15, aes(x=genotype, y=height, fill=factor(rate)))+
geom_bar(stat="identity", width=0.6, position="dodge", col = "black")+
scale_fill_discrete(name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
xlab("Genotype")+ylab("Height")+
geom_errorbar(aes(ymin= mean15$height,ymax=mean15$height+sd15$sd), width=0.2, position = position_dodge(0.6))+
ggtitle("15 DAT Height")+
scale_fill_brewer(palette='PRGn', name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
theme(plot.title = element_text(hjust=0.5))
twentyone <- ggplot(mean21, aes(x=genotype, y=height, fill=factor(rate)))+
geom_bar(stat="identity",width=0.6, position="dodge", col = "black")+
scale_fill_discrete(name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
xlab("Genotype")+ylab("Height")+
geom_errorbar(aes(ymin= mean21$height,ymax=mean21$height+sd21$sd), width=0.2, position = position_dodge(0.6))+
ggtitle("21 DAT Height")+
scale_fill_brewer(palette='PRGn', name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
theme(plot.title = element_text(hjust=0.5))
twentyseven <- ggplot(mean27, aes(x=genotype, y=height, fill=factor(rate)))+
geom_bar(stat="identity",width=0.6, position="dodge", col="black")+
scale_fill_discrete(name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
xlab("Genotype")+ylab("Height")+
geom_errorbar(aes(ymin= mean27$height,ymax=mean27$height+sd27$sd), width=0.2, position = position_dodge(0.6))+
ggtitle("27 DAT Height")+
scale_fill_brewer(palette='PRGn', name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
theme(plot.title = element_text(hjust=0.5))
thirtyfive <- ggplot(mean35, aes(x=genotype, y=height, fill=factor(rate)))+
geom_bar(stat="identity",width=0.6, position="dodge", col="black")+
scale_fill_discrete(name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
xlab("Genotype")+ylab("Height")+
geom_errorbar(aes(ymin= mean35$height,ymax=mean35$height+sd35$sd), width=0.2, position = position_dodge(0.6))+
ggtitle("35 DAT Height")+
scale_fill_brewer(palette='PRGn', name="Herbicide Rate", labels=c("0X", "1X", "4X", "8x"))+
theme(plot.title = element_text(hjust=0.5))
library(gridExtra)
###Arranges the plot how I need them to look:
grid.arrange(nine, fifteen, twentyone,
twentyseven, thirtyfive,
nrow=2, ncol=3, top= "Tembotrione Height")
这是我尝试的第一件事:
grid.arrange(nine, fifteen, twentyone,
twentyseven, thirtyfive,
nrow=2, ncol=3, top= "Tembotrione Height")
然后这个:
g <- arrangeGrob(nine, fifteen, twentyone,
twentyseven, thirtyfive,
nrow=2, ncol=3, top= "Tembotrione Height")
ggsave(file="tembo_height.png",g)
输出图如下:
显然这不起作用。
提前谢谢大家!