我想要两个ggplots对齐并且x轴长度相同。不知怎的,它不起作用。这是我的代码:
#5cm_Four治疗颜色不同
d1<-ggplot(MyDataMoistWinkler[550:10000,], aes(x=betterDate)) +
geom_line(aes(y=VerticalTillHigh5cm, color="Vertical Till High Disturbance 5cm"))+
geom_line(aes(y=VerticalTillLow5cm, color="Vertical Till Low Disturbance 5cm"))+
geom_line(aes(y=StripST5cm, color="Strip Till in row"))+
geom_line(aes(y=StripNT5cm, color="Strip Till between row"))+
geom_line(aes(y=Disc5cm, color="Double Disc"))+
xlab("Date")+
ylab("Volumetric Water Content [m3/m3]")+
scale_y_continuous(limits = c(0, NA))+
theme(text = element_text(size = 11, colour = "black"))+
theme(legend.title=element_blank())+
#theme(panel.background = element_blank(), panel.grid = element_line( size=.5, colour="black" ) )+
theme(axis.text = element_text(size = 15, colour = "grey"))+# changes axis labels
theme(axis.title = element_text(size = 15))+ # change axis titles
theme(text = element_text(size = 15, colour = "black"))+ # this will change all text size # (except geom_text)
theme(strip.text.x = element_text(size = 15, colour = "black", angle =NULL))+
ggtitle("Moisture in 5cm, in Winkler MB")
d2<-ggplot(MyDataMoistWinkler[550:10000,], aes(x=betterDate, y=AccumulatedRainfall)) +
geom_line(aes(y=AccumulatedRainfall, color="Accumulated Rainfall"))+
xlab("Date ")+
ylab("Accumulated Rainfall [mm]")+
scale_y_continuous(limits = c(0, NA))+
theme(text = element_text(size = 11, colour = "black"))+
theme(legend.title=element_blank())+
#theme(panel.background = element_blank(), panel.grid = element_line( size=.5, colour="black" ) )+
theme(axis.text = element_text(size = 15, colour = "grey"))+# changes axis labels
theme(axis.title = element_text(size = 15))+ # change axis titles
theme(text = element_text(size = 15, colour = "black"))+ # this will change all text size # (except geom_text)
theme(strip.text.x = element_text(size = 15, colour = "black", angle =NULL))+
ggtitle("Precipitation in mm, in Winkler MB")
require(gridExtra)
grid.arrange(d1, d2, ncol=1)
答案 0 :(得分:0)
library(grid)
grid.draw(rbind(ggplotGrob(d1), ggplotGrob(d2)))
可能有效