I am struggling to make a legend that I want for my graph. Here is what the graph currently looks like (it’s not a final version, I know it’s not super pretty)
I am frustrated by the fact that I can’t seem to combine the legends into one using patchwork or ggarrange packages. I am used to using scale_fcn_manual() and making the aesthetic calls identical, then calling for “collected” legends in patchwork(). However, because the data within each plot is actually different, it is still making them into 3 separate plots, despite the fact that I have all possible treatment options in my code.
Does anyone know how to either create an entirely new legend from scratch or fix my code? I have tried using a common legend using ggarrange() as well, but got a similar result. Below, I will include my ggplot code and also what I would LIKE the figure to look like, manually edited on Paint. Thanks!
plot_size_p = ggplot (filter(snail_size, food %in% c("C","J","K","L")), aes(x = week, y = mean_size, color = food, shape=infected, linetype=infected)) +
theme_bw()+
theme(plot.title = element_text(hjust = 0.5,vjust=-1))+
theme(legend.position = "right")+
theme(legend.title.align=0.5)+
labs(color = "Resource Type",
linetype = "Parasite Status",
shape = "Parasite Status")+
ggtitle("PnSupplement")+
xlab("Week")+
ylab("Mean Shell Diameter (mm)")+
geom_linerange(aes(ymin=mean_size-SEM_size, ymax=mean_size+SEM_size, color=food)) +
geom_point (aes(color = food, shape=infected)) +
geom_line (aes(color = food, linetype=infected))+
scale_x_continuous(breaks=seq(0,max(exp_size$week),by=4), limits=c(0,max(exp_size$week)))+
scale_y_continuous(breaks=seq(6,15,by=2), limits=c(5.5,15.5))+
scale_color_manual(breaks = c("F","I","H","G","L","K","J","O","N","M","C"),labels = c("100% Pleco Wafers","High N","Med N","Low N","High P","Med P","Low P","High (N+P)","Med (N+P)","Low (N+P)", "Baseline"),values = c("green4", brewer.pal(9, "Reds")[7],brewer.pal(9, "Reds")[6],brewer.pal(9, "Reds")[5],brewer.pal(9, "Blues")[7],brewer.pal(9, "Blues")[6],brewer.pal(9, "Blues")[5],brewer.pal(9, "Purples")[7],brewer.pal(9, "Purples")[6],brewer.pal(9, "Purples")[5], "grey"))+
scale_linetype_manual(breaks=c(0,1), labels=c("Uninfected","Infected"), values=c(1,2))+
scale_shape_manual(breaks=c(0,1), labels=c("Uninfected","Infected"), values=c(19,17))
plot_size_n = ggplot (filter(snail_size, food %in% c("C","G","H","I")), aes(x = week, y = mean_size, color = food, shape=infected, linetype=infected)) +
theme_bw()+
theme(plot.title = element_text(hjust = 0.5,vjust=-1))+
theme(legend.position = "right")+
theme(legend.title.align=0.5)+
labs(color = "Resource Type",
linetype = "Parasite Status",
shape = "Parasite Status")+
ggtitle("NnSupplement")+
xlab("Week")+
ylab("Mean Shell Diameter (mm)")+
theme(axis.title.y = element_blank(),
axis.text.y = element_blank())+
geom_linerange(aes(ymin=mean_size-SEM_size, ymax=mean_size+SEM_size, color=food)) +
geom_point (aes(color = food, shape=infected)) +
geom_line (aes(color = food, linetype=infected))+
scale_x_continuous(breaks=seq(0,max(exp_size$week),by=4), limits=c(0,max(exp_size$week)))+
scale_y_continuous(breaks=seq(6,15,by=2), limits=c(5.5,15.5))+
scale_color_manual(breaks = c("F","I","H","G","L","K","J","O","N","M","C"),labels = c("100% Pleco Wafers","High N","Med N","Low N","High P","Med P","Low P","High (N+P)","Med (N+P)","Low (N+P)", "Baseline"),values = c("green4", brewer.pal(9, "Reds")[7],brewer.pal(9, "Reds")[6],brewer.pal(9, "Reds")[5],brewer.pal(9, "Blues")[7],brewer.pal(9, "Blues")[6],brewer.pal(9, "Blues")[5],brewer.pal(9, "Purples")[7],brewer.pal(9, "Purples")[6],brewer.pal(9, "Purples")[5], "grey"))+
scale_linetype_manual(breaks=c(0,1), labels=c("Uninfected","Infected"), values=c(1,2))+
scale_shape_manual(breaks=c(0,1), labels=c("Uninfected","Infected"), values=c(19,17))
plot_size_np = ggplot (filter(snail_size, food %in% c("C","M","N","O")), aes(x = week, y = mean_size, color = food, shape=infected, linetype=infected)) +
theme_bw()+
theme(plot.title = element_text(hjust = 0.5,vjust=-1))+
theme(legend.position = "right")+
theme(legend.title.align=0.5)+
labs(color = "Resource Type",
linetype = "Parasite Status",
shape = "Parasite Status")+
ggtitle("(N+P)nSupplement")+
xlab("Week")+
ylab("Mean Shell Diameter (mm)")+
theme(axis.title.y = element_blank(),
axis.text.y = element_blank())+
geom_linerange(aes(ymin=mean_size-SEM_size, ymax=mean_size+SEM_size, color=food)) +
geom_point (aes(color = food, shape=infected)) +
geom_line (aes(color = food, linetype=infected))+
scale_x_continuous(breaks=seq(0,max(exp_size$week),by=4), limits=c(0,max(exp_size$week)))+
scale_y_continuous(breaks=seq(6,15,by=2), limits=c(5.5,15.5))+
scale_color_manual(breaks = c("F","I","H","G","L","K","J","O","N","M","C"),labels = c("100% Pleco Wafers","High N","Med N","Low N","High P","Med P","Low P","High (N+P)","Med (N+P)","Low (N+P)", "Baseline"),values = c("green4", brewer.pal(9, "Reds")[7],brewer.pal(9, "Reds")[6],brewer.pal(9, "Reds")[5],brewer.pal(9, "Blues")[7],brewer.pal(9, "Blues")[6],brewer.pal(9, "Blues")[5],brewer.pal(9, "Purples")[7],brewer.pal(9, "Purples")[6], brewer.pal(9, "Purples")[5], "grey"))+
scale_linetype_manual(breaks=c(0,1), labels=c("Uninfected","Infected"), values=c(1,2))+
scale_shape_manual(breaks=c(0,1), labels=c("Uninfected","Infected"), values=c(19,17))
size_plots = wrap_plots(plot_size_p,plot_size_n,plot_size_np, nrow = 1, ncol = 3)+
plot_layout(guides = "collect")
size_plots