【发布时间】:2014-04-25 19:56:37
【问题描述】:
我正在使用 ggplot2 生成平均值(不是计数)的堆积条形图。这适用于以下代码:
new.stop <- read.delim("New_stop_data.txt")
A <- ggplot(new.stop, aes(x=Consonant, y=(Duration*1000), fill = Label)) + stat_summary(fun.y="mean", geom="bar") + coord_flip() + theme_bw() + ylab("Duration (ms)") + xlab("Stop")
A + scale_fill_grey()
原则上以这种方式绘制东西可以正常工作并产生以下plot。但是,“投票”和“关闭”级别的顺序应该颠倒,投票在右边。我尝试通过使用 relevel() 和分别使用 factor() 来解决这个问题,如下所示:
new.stop$Label <- relevel(new.stop$Label, ref="vot")
new.stop$Label <- factor(new.stop$Label, levels = c("vot", "closure"), labels=c("VOT", "Closure"))
但是,正如您所见,这只会产生barplot where both values are merged。我什至尝试在 ggplot2 中重新排序,但无济于事。由于此数据不是计数数据(并且 ggplot2 假设您只会将计数数据用于条形图),因此我无法找到任何似乎在这里有用的帮助。非常感谢任何帮助。
PS:就我所做的而言,条形图是典型的。
【问题讨论】:
-
Christian DiCanio 尝试使用
guides(... reverse = T)