Nesting one factor within another in ggplot figures

26 Views Asked by At

I have two factors in my dataset (LocationTreatment[WebbHardRelease, WebbSoftRelease, SRSHardRelease, and SRSSoftRelease] and Location [Webb, SRS]) that I want to display simultaneously. I would like to display my response variables with these two factors nested within each other on the y-axis.

Here is what my figure currently looks like: enter image description here

I want it to look like this:

enter image description here

Here is the line of code I am currently using to make one of the figures. I can change the other three if I know how to make this one display what I need:

FirstDayDistPlot <- SoftReleaseData %>%
  ggplot(aes(LocationTreatment, FirstDayDist))+
  stat_boxplot(geom ='errorbar', width=0.2)+
  geom_boxplot(color="black", fill="grey", width = 0.3)+
  theme_bw()+  
  theme(text=element_text(family="Helvetica", size=12))+
  theme(axis.line.x.bottom = element_line(color="black"))+
  theme(axis.line.y.left = element_line(color="black"))+
  theme(axis.line.x.top = element_line(color="black"))+
  theme(axis.line.y.right = element_line(color="black"))+
  theme(axis.text.x.bottom = element_text(color="black",size=12))+
  theme(axis.text.y.left = element_text(color="black",size=12))+
  theme(axis.title.x.bottom = element_text(color="black",size=14))+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
  scale_y_continuous(breaks=seq(0,700,100))+
  coord_flip()+
  annotate("text", x=4.4, y=40, label = "(a)", col="black", size = 8, fontface = 1, family = "Helvetica")

FirstDayDistFinal <- FirstDayDistPlot+labs(x=element_blank(), y = "First Day Displacement (m)")

Any suggestions are greatly appreciated. Thanks.

I have looked into forums on the facet_wrap() command, but I can't quite find any examples like mine where I do not want to display a legend, but rather just have the axes tell the whole story for a more condensed figure.

0

There are 0 best solutions below