I am trying to represent my data as box plots and my data frame currently looks as follows:
V1 V2 V3 V4 V5
1 1 12.18 FEMALE A_ambiguus Host
2 2 11.81 FEMALE A_ambiguus Host
3 3 10.70 MALE A_ambiguus Host
4 4 11.07 MALE A_ambiguus Host
5 5 7.95 FEMALE A_ameliae Parasite
6 6 7.42 FEMALE A_ameliae Parasite
I run the following script and produce a figure with species (V4) as the x-axis, total length (V2) as the y-axis, ordered by V2, and colored by V5.
box <- ggplot(TL_sub, aes(x = V4, y = V2, group = V4)) +
scale_y_continuous(name = "TL (mm)") +
theme(axis.text.x=element_text(angle = 45, hjust = 1)) +
geom_boxplot(aes(fill=Condition)) +
aes(x=reorder(V4,V2),y=V2,label=TL)
box
The problem is that when I then run
box + facet_grid(. ~ V5)
The goal is to create two plots separated by sex (V3), but it does not work. I get the following error:
Error in combine_vars(data, params$plot_env, cols, drop = params$drop) :
At least one layer must contain all variables used for facetting
I can provide the full data set if needed.
Any help would be great! Thanks, Steven M.