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

时间:2017-07-18 14:10:13

标签: r ggplot2

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

是否可以将躲闪位置限制在一个美学范围内?我已经搜过文档和堆栈溢出但尚未发现任何东西。

1 个答案:

答案 0 :(得分:5)

group决定躲避,所以可以做到:

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

enter image description here

相关问题