I created a layout and I added the legend at the end of last graph plot 4, please see the code below (I deleted the codes of ploe 2 and plot 3 since they are similar to plot 1). But the last graph of plot 4 will become out of shape if I do so See picture. How can I add the legend at the bottom of whole layout with even-sized images?
library(foreign)
library(ggplot2)
library(dplyr)
library(readxl)
library(scales)
library(tidyverse)
Sys.setlocale("LC_TIME", "English")
X0_40cm <- read_excel("C:/Users/Connie/Desktop/LAI/Wheat_F_2018.xlsx")
plot1 <- ggplot(X0_40cm, aes(Date,LAI,group=1))+
geom_point(data=subset(X0_40cm, Condition=="Measured"),col="blue")+
geom_line(data=subset(X0_40cm, Condition=="Simulated"),col="black")+
scale_y_continuous(limits = c(0,3)) +
labs(title="Winter wheat of F plot in 2018",y="LAI",x="Date")+
theme_update(plot.title=element_text(hjust=0.5))
plot1
X200cm <- read_excel("C:/Users/Connie/Desktop/LAI/Maize_F_2019.xlsx")
plot4 <- ggplot(mapping = aes(Date, LAI, color = Condition, linetype = Condition, shape = Condition))+
geom_point(data=subset(X200cm, Condition=="Measured"))+
geom_line(data=subset(X200cm, Condition=="Simulated"))+
scale_color_manual(values = c("blue", "black")) +
scale_linetype_manual(values=c(NA,1)) +
scale_shape_manual(values=c(19,NA)) +
theme(legend.position="bottom",legend.key.size=unit(0.1,'cm'),legend.key.width=unit(0.5,'cm'),legend.title=element_blank())+
scale_y_continuous(limits = c(0,8)) +
labs(title="Summer maize of F plot in 2019",y="LAI",x="Date")
theme_update(plot.title=element_text(hjust=0.5))
plot4
library(grid)
grid.newpage()
pushViewport(viewport(layout=grid.layout(4,1)))
print(plot1, vp=viewport(layout.pos.row = 1, layout.pos.col = 1))
print(plot2, vp=viewport(layout.pos.row = 2, layout.pos.col = 1))
print(plot3, vp=viewport(layout.pos.row = 3, layout.pos.col = 1))
print(plot4, vp=viewport(layout.pos.row = 4, layout.pos.col = 1))
dev.new()