【发布时间】:2015-07-22 08:34:51
【问题描述】:
我真的很喜欢 ggplot2::geom_dotplot() 可以很好地将点堆叠到类别中间的方式,但我似乎无法将它与填充颜色结合起来。
我们来看一个例子:
# test data
tmpData <- data.frame(x=c(rep('x', 3),rep('y', 3)), y=c(1,1,2,1,2,2), fill=rep(c('A', 'B', 'B'), 2))
# Plot without fill color
ggplot(tmpData, aes(x=x, y=y)) +
geom_dotplot(binaxis = "y", stackdir = "center", dotsize=4)
导致这个情节:
但是当我添加填充参数时:
ggplot(tmpData, aes(x=x, y=y, fill=fill)) +
geom_dotplot(binaxis = "y", stackdir = "center", dotsize=4)
填充似乎覆盖了在“x”上完成的分组,导致两个点 (x, 1)(x, 1) 被折叠我希望它们具有不同的颜色。
当我尝试指定组时,填充颜色被忽略:
ggplot(tmpData, aes(x=x, y=y, group=x, fill=fill)) +
geom_dotplot(binaxis = "y", stackdir = "center", dotsize=4)
通过启用堆栈组似乎可以避免崩溃:
ggplot(tmpData, aes(x=x, y=y, fill=fill)) +
geom_dotplot(binaxis = "y", stackgroups=TRUE, stackdir = "center", dotsize=4)
但随后我将数据的中心化为其他 3 个图中的“x”和“y”。
有没有办法将geom_dotplot() 与两个组一起使用并填充?
【问题讨论】:
-
我可以确认
ggplot2 1.0.1中仍然存在这个问题,并且我已经向 Hadley 提出了一个问题:github.com/hadley/ggplot2/issues/1359