0

I have this plot, but i want to change around the order of the X axis labels. It should start with the site number (eg. X27a, X28a, W15c, W17c) Then the group (eg. A, B, C, D) and then the last one. So basically i want the very bottom row of labels at the top.

How do i reorder it?

Graph with incorrect order of X axis labels

Code

ggplot(data = inf, aes(x = COMPARTMENT, y = MI, fill = SPECIES)) +
geom_bar(stat = "identity") +
scale_y_continuous(expand = c(0, 0), limits = c(-0.1, 12.5), breaks = 2*c(0:6)) +
theme_bw() +
facet_grid(~COMP.COMP*REGION, switch = "x", scales = "free_x", space = "free_x") +
theme(strip.text.x = element_text(size = 10)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5, size = 10)) +
theme(panel.spacing = unit(0, "lines"), 
    strip.background = element_blank()) +
scale_fill_manual(name = "SPECIES",
                values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2")) +
ylab("Average infestation rate (%)") +
xlab("Compartment by Comparable Groups by Region") +
theme(panel.grid.major.y = element_line("lightgray"),
    panel.grid.major.x = element_blank()) +
theme(axis.line = element_line(color = "black"),
    legend.position = "right",
    legend.title=element_text())

0 Answers0