我正在尝试并排显示两个图。我尝试了不同的程序包(cowplot,ggpubr),但似乎第二个图每次都覆盖第一个图,这会导致出现两个相同的图。我已经复制了为绘制一张图像而编写的代码,并更改了第二张图的输入。当我分别运行这些部分时,会出现不同的图,但是当我将它们组合时,它们是重复的。谢谢!
plot1 = ggplot(aggregatedsubset, aes(x = aggregatedsubset[[x]], y =
aggregatedsubset[[y]], fill = aggregatedsubset[[group]])) +
geom_area(colour = "black", size = 0.2, alpha = 0.6) +
scale_fill_manual(values = c("blue","deepskyblue1", "dodgerblue1", "
yellow","orange","brown",'darkgreen',"grey37","red","pink")) +
labs( y = ylabel, x = xlabel, fill = legend) +
theme_minimal() +
ylim(0,60000) +
scale_x_continuous(breaks = seq(2015, 2030, by = 3))
plot 2= ggplot(aggregatedsubset, aes(x = aggregatedsubset[[x]], y =
aggregatedsubset[[y]], fill = aggregatedsubset[[group]])) +
geom_area(colour = "black", size = 0.2, alpha = 0.6) +
scale_fill_manual(values = c("blue","deepskyblue1", "dodgerblue1", "
yellow","orange","brown",'darkgreen',"grey37","red","pink")) +
labs( y = ylabel, x = xlabel, fill = legend) +
theme_minimal() +
ylim(0,60000) +
scale_x_continuous(breaks = seq(2015, 2030, by = 3))
ggarrange(plot1,plot2)
plot_grid(plot1,plot2)
我还尝试使用图1 <= ...代替图1 = ...,但这也不起作用
答案 0 :(得分:0)
您是否考虑过使用facet_grid()
?然后,您可以将绘图并排放置在构面中,而不是完全将其分开放置,并从单个变量导出图像。 Check out the documentation here。
类似于:
plot1 = ggplot(aggregatedsubset, aes(x = aggregatedsubset[[x]], y =
aggregatedsubset[[y]], fill = aggregatedsubset[[group]])) +
geom_area(colour = "black", size = 0.2, alpha = 0.6) +
facet_grid(~aggregatedsubset[[group]]) +
.....