Hi Leon and @joels -
So I used both methods of mutating the variables here, and it seemed to work to reorder the data in AA_summary
Here is the code I used:
AA_summary <- Aminoacid_data %>%
mutate(Species=factor(Species, levels=c("At", "Ns", "Mc", "Lj", "Ps"))) %>%
group_by(Species, Genotype, Timepoint) %>%
summarise(mean_Asn=mean(Asn), mean_Ile=mean(Ile), mean_Total=mean(Total_amino_acids), sd_Asn=sd(Asn), sd_Ile=sd(Ile), sd_Total=sd(Total_amino_acids))
And the other method, ungrouping after making the AA_summary
dataset and before the mutation:
AA_summary %>%
ungroup() %>%
mutate(Species=factor(Species, levels=c("At", "Ns", "Mc", "Lj", "Ps")))
I realize in my last comment I included a lot of superfluous code when making the figure, so here is a simplified version that hopefully you guys can help me troubleshoot:
test_Asn <- ggplot(AA_summary, aes(x=Genotype, y=mean_Asn, fill=Genotype))+
geom_col(show.legend=FALSE, alpha=1/2, color="black")+
geom_jitter(data=Aminoacid_data, aes(x=Genotype, y=Asn), show.legend=FALSE)+
facet_grid(Species~Timepoint, scales="free_y")
I put this code in after checking to make sure the levels were in the correct order using View(AA_summary)
but it still gave the facet grid in alphabetical order, here is the figure:
test_Asn.pdf (12.5 KB)
Just to reiterate, I want the order of the horizontal panels to be (from top to bottom) "At", "Ns", "Mc", "Lj", "Ps"
Thanks again for all of your help!!
Erik