0

我有这个情节,但我想改变 X 轴标签的顺序。它应该以站点编号(例如 X27a、X28a、W15c、W17c)开始,然后是组(例如 A、B、C、D),然后是最后一个。所以基本上我想要最底部的标签行在顶部。

我该如何重新排序?

X 轴标签顺序不正确的图形

代码

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())
4

0 回答 0