I'm using DAPC to analyze the population structure of a GBS dataset. I was able to generate a table with the following:
Population Accession Assigned Membership 1 C. a jal 1 9.051345e-63 2 C. a ancho 2 1.396897e-10 3 C. b toro 3 0.000000e+00 4 C. b b37 1 0.000000e+00 5 C. c mis 1 0.000000e+00 6 C. a jal 2 9.051345e-63 7 C. a ancho 1 1.396897e-10 8 C. b toro 4 0.000000e+00 9 C. b b37 2 0.000000e+00 10 C. c mis 3 0.000000e+00
Then I used ggplot to plot the compoplot (Structure-like):
cap.color <- brewer.pal(n = 7, name = "Set3") ggplot(cap.dapc, aes(x=Accession, y=Membership, fill=Assigned)) + geom_bar(stat='identity') + scale_fill_manual(values = cap.color) + facet_grid(~Population, scales = "free", space = "free_x") + theme(axis.text.x = element_text(angle = 90, hjust = 0, vjust = 0.5)) + xlab("Accession")
That results in a plot ordered alphabetically by sample name and by population. My goal is to change the code in order to samples appear order by the Assigned category and Membership. How can I do that?
I've tried using
cap.dapc$Accession <- factor(cap.dapc$Assigned, levels = rev(unique(cap.dapc$Accession)), ordered=TRUE)