I am attempting to make a 2 by 2 plot, where each subplot has y-axis lines allowing the viewer to better see the magnitude of values.
I then arrange them using grid_arrange_shared_legend
(requires library(lemon)
to work), so that I can use a single legend for this combined plot.
If I look at the individual plots, they have the correct grid lines, specified by theme(panel.grid.major.y=element_line)
, but once they are plotted together those lines disappear.
Any idea why?
Subplot alone
Combined into 2x2
EDITED to include reproducible example plus images
#making data frame
ASumm <- data.frame("Days" = c("1 Day","2 Days","3 Days","4 Days","5 Days","6 days"), "Condition" = c("C","C","T1","T1","T2","T2"), "mean"= c(20,40,60,80,100,70), "se"=c(3,5,3,8,4,8))
#Specifying graph components
CondFill<-c("seagreen","darkorange","dodgerblue3") # darker colors from HC code above
pd<-position_dodge(0.3)
labels_DaysNum<-c("1","2","3","4","5","6")
labels_Conditions<-c("Control","Treatment 1","Treatment 2")
TPShape<-c(3,0,2,1,6,11)
#making subplot
APlot <- ggplot(ASumm, aes(x=Days, y=mean, colour=Condition, group=Condition)) +
ggtitle("Subplot") +
geom_point(aes(shape=Days),size=6,position=pd,stroke=1.5) +
scale_shape_manual(values=TPShape) +
scale_color_manual(values=CondFill,labels=labels_Conditions) +
labs(y="Title",shape="Time Point") +
theme_classic(base_size = 40) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=0.3, size=1, position=pd) +
theme(panel.grid.major.y=element_line(colour="grey", size=1),
plot.title = element_text(size = 35, hjust = 0.5),
axis.text.x = element_text(size=27.5, angle=20),
axis.text.y = element_text(size=30),
axis.title.x = element_blank(),
axis.title.y = element_text(size=35)) +
scale_y_continuous(breaks=c(0,20,40,60,80,100),
limits=c(0,110), expand=c(0,0))
#making 2x2 plot with shared legend
grid_arrange_shared_legend(APlot,APlot,APlot,APlot,nrow=2, ncol = 2, position='right')