【发布时间】:2017-05-12 18:09:21
【问题描述】:
set.seed(357)
x <- data.frame(name = sample(letters, 10), val = runif(10), stringsAsFactors = F)
x[c(2,6),"name"] <- c("k","k")
ggplot(x, aes(x = name, y = val)) + theme_bw() + geom_bar(stat = "identity")
如何以与 x$name 相同的顺序绘制轴? (是的,k 是重复的,我希望它像这个轴一样显示在图中:c k g f o k s v t q)
过去我曾经这样做过:
x$name <- factor(x$name, levels = x$name[order(x$val)], ordered = T)
wich 不再起作用了,这要归功于: http://r.789695.n4.nabble.com/factors-with-non-unique-quot-duplicated-quot-levels-have-been-deprecated-since-2009-are-more-depreca-td4721481.html
这不是重复的:ggplot: order of factors with duplicate levels 他的数据结构完全不同。
另外,我尝试在 x_scale_discrete 中设置限制。没用。
【问题讨论】: