我一直在使用下面的代码创建 3 个单独的图,然后使用 ggpubr 包中的 ggarrange 将它们组合成一个图并将其保存为图像。但是,一旦我创建了我的脚本的 Rmd,这个函数就非常喜怒无常,即使它在 Rmd 之外运行良好,也会给我一个错误“Faceting variables must have at least one value”。使用 ggplot2 包中的内容是否有不同的方法来获得相同的结果?还是其他更简单的方法?编辑:我想维护我的图表中的网格,而不是使用复杂的方法来获得cowplot 需要的常见图例。
graph_1 <- ggplot(subset(data_p, Target == "1"), aes(x=as.integer(volume), y=percent_yield, color=Tech.Rep))+
geom_point()+
geom_smooth(se=FALSE)+
facet_wrap(~sample)+
ggtitle(paste("Graph 1"))+
ylab("PERCENT YIELD")+
scale_x_discrete(limits= levels(data_p$volume))+
ylim(min=-150, max=150)+
theme(axis.text.x=element_text(size=10,angle=85,hjust=1,vjust=1))+
theme(legend.position="none")+
geom_ribbon(aes(ymax=100, ymin=50), alpha = 0.2, fill="green", col="green")+
geom_ribbon(aes(ymax=0, ymin=0), alpha = 0.2, fill="black", col="black", size=1.0)
graph_2 <- ggplot(subset(data_p, Target == "2"), aes(x=as.integer(volume), y=percent_yield, color=Tech.Rep))+
geom_point()+
geom_smooth(se=FALSE)+
facet_wrap(~sample)+
ggtitle(paste("Graph 2"))+
ylab("PERCENT YIELD")+
scale_x_discrete(limits= levels(data_p$volume))+
ylim(min=-150, max=150)+
theme(axis.text.x=element_text(size=10,angle=85,hjust=1,vjust=1))+
theme(legend.position="none")+
geom_ribbon(aes(ymax=100, ymin=50), alpha = 0.2, fill="green", col="green")+
geom_ribbon(aes(ymax=0, ymin=0), alpha = 0.2, fill="black", col="black", size=1.0)
graph_3 <- ggplot(subset(data_p, Target == "3"), aes(x=as.integer(volume), y=percent_yield, color=Tech.Rep))+
geom_point()+
geom_smooth(se=FALSE)+
facet_wrap(~sample)+
ggtitle(paste("Graph 3"))+
ylab("PERCENT YIELD")+
scale_x_discrete(limits= levels(data_p$volume))+
ylim(min=-150, max=150)+
theme(axis.text.x=element_text(size=10,angle=85,hjust=1,vjust=1))+
theme(legend.position="none")+
geom_ribbon(aes(ymax=100, ymin=50), alpha = 0.2, fill="green", col="green")+
geom_ribbon(aes(ymax=0, ymin=0), alpha = 0.2, fill="black", col="black", size=1.0)
ggarrange(graph_1, graph_2, graph_3, ncol=3, nrow=1, common.legend=TRUE, legend= "bottom")
这是组合图的样子: