希望它会很容易理解。与 here 的例子基本相同.
使用
ggplot(mtcars, aes(factor(cyl), fill = factor(vs))) +
geom_bar(position = position_dodge(preserve = "single"))
但我收到
Error in position_dodge(preserve = "single") :
unused argument (preserve = "single")
/. ggplot2 版本 2.2.1那么如何修改代码
ggplot(mtcars, aes(factor(cyl), fill = factor(vs))) +
geom_bar(position = "dodge")
不要像下面那样得到这个超宽的酒吧,但和那里一样。
最佳答案
该参数已添加到 position_dodge
在开发版in january .它还没有在 CRAN 上。
一种解决方法是计算 ggplot2 之外的统计数据:
ggplot(as.data.frame(with(mtcars, table(cyl = factor(cyl), vs = factor(vs)))),
aes(factor(cyl), y = Freq, fill = factor(vs))) +
geom_col(position = "dodge") +
scale_fill_discrete(drop = FALSE)
这是有效的,因为零计数包含在传递给 geom 的数据中。
关于r - ggplot2 道奇重叠 - 保留每个元素的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45728723/