【问题标题】:ggplot2: geom_point() dodge shape but NOT colorggplot2:geom_point() 闪避形状但不是颜色
【发布时间】:2017-07-18 14:10:13
【问题描述】:

我正在尝试在 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))

是否可以将闪避位置限制为仅一种美学?我搜索了文档和堆栈溢出,但还没有找到任何东西。

【问题讨论】:

  • ggplot(data=x) + geom_point(aes(xVar, Value, color=Color), position=position_dodge(width=.5)) + geom_point(aes(xVar,Value,shape=Shape))怎么样
  • 我没有看到任何其他选择,只是按照 juan 的建议复制这些点。如何在一个位置有一个点的形状,而在另一个位置有颜色?
  • @PaulEndymion,无需重复。

标签: r ggplot2


【解决方案1】:

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

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

【讨论】:

  • 不错!我想我一开始没有得到这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多