2017-07-18 47 views
0

我试图用geom_point()变量映射到x,y,颜色和形状以及躲避颜色但没有形状的位置来获取ggplot2中的图。ggplot2:geom_point()闪避形状,但不是颜色

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

如何'ggplot(数据= X)+ geom_point(AES(XVAR,价值,颜色=颜色),位置= position_dodge(width = .5))+ geom_point(aes(xVar,Value,shape = Shape))' – juan

+1

我没有看到任何其他选项,而是按照juan的建议复制点。你怎么能在一个位置上有一个点的形状,而在另一个位置上的颜色呢? –

+0

@PaulEndymion,不需要重复。 – Axeman

回答

4

group确定躲避,因此可以这样做:

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

enter image description here

+1

不错!我想我首先得不到这个问题。 –