I tried to create a plot grid that shows all the interactions from my model in separate panels with ggarrange from the ggpubr package and with plot_grid from the cowplot package. In both cases I get the error message: "Aesthetics must be either length 1 or the same as the data (1068): colour, linetype". Is there a way to arrange plots with different aeshetic lengths?
Here is a code sample for two plots and my attempt at arranging them. Each plot looks fine on its own, but can't be arranged together. The data used for the first have 8 rows and those used for plot 2 have 1068 rows:
library(ggplot2)
library(cowplot)
library(ggpubr)
# Interaction 1
plot1 = ggplot(aes(x=age,y=pred),data=newdat)+
geom_line(data=newdat,aes(x=age,y=pred,colour = newdat$weaned,linetype = newdat$weaned),size=1)+
scale_color_manual(values = c("grey20", "blue"))+
scale_linetype_manual(values=c("dashed", "solid"))
# Interaction 2
plot2 = ggplot(aes(x=NPI,y=pred),data=newdat2)+ fig+
geom_line(data=newdat2,aes(x=NPI,y=pred,colour = as.factor(newdat$density),linetype = as.factor(newdat$density)),size=1)+
scale_color_manual(values = c("blue", "grey20", "black"))
#
# Try to combine 2 plots in a grid
plot_grid(plot2, plot1,labels = c("A","B"), align = "h", ncol = 2)
ggarrange(plot2, plot1,labels = c("A", "B"),ncol = 2, nrow = 2)