只要 fu5 是一个因素,重新排序函数就可以做到这一点。但请注意 as.integer 来检索因子的数字排序。
library(ggplot2)
df = read.csv(text="
sp5,fu5,o5
spa,c,1
spd,c,2
spb,a,3
spc,b,4
", stringsAsFactors = TRUE)
ggplot(df, aes(x = reorder(sp5, as.integer(fu5)), y = o5, fill = fu5)) +
geom_col() +
theme(axis.text.x = element_text(angle = 60, hjust = 1))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句