ggplot2:geom_point()躲避形状但不是颜色

4

我正在尝试使用ggplot2中的geom_point()绘制图形,将变量映射到x、y、颜色和形状,并闪避颜色的位置,但不是形状。

x=tibble(Color=c(rep('A',12),rep('B',12),rep('C',12)),
     Shape=rep(c(rep('A',3),rep('B',3),rep('C',3),rep('D',3)),3),
     xVar=rep(c('A','B','C'),12),
     Value=rnorm(36))

ggplot(x,aes(xVar,Value,color=Color,shape=Shape))+
     geom_point(position=position_dodge(width=.5))

有没有可能将闪避位置限制在一个审美上?我已经查阅了文档和Stack Overflow,但还没有找到相关的内容。


1
如何使用 ggplot(data=x) + geom_point(aes(xVar, Value, color=Color), position=position_dodge(width=.5)) + geom_point(aes(xVar,Value,shape=Shape)) - juan
1
我看不到其他选择,只能像Juan建议的那样复制这些点。你怎么能在一个位置上拥有一个点的形状,而在另一个位置上拥有颜色呢? - Paul Endymion
@PaulEndymion,无需重复。 - Axeman
1个回答

11
组决定了躲避,因此可以这样做:

group决定了闪避,所以可以这样做:

ggplot(x, aes(xVar, Value, color = Color, shape = Shape, group = Shape))+
  geom_point(position = position_dodge(width = .5))

enter image description here


1
不错!我想我一开始没有理解问题。 - Paul Endymion

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接