本文介绍了ggplot2:geom_point()避开形状但不显示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用geom_point()在ggplot2中获得一个具有映射到x,y,颜色和形状的变量的图,并避开颜色而不是形状的位置.
I'm trying to get a plot in ggplot2 with geom_point() having variables mapped to x, y, color and shape and to dodge the position for color but not shape.
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))
是否可以将躲闪位置限制在一种美学之上?我已经搜索过文档并发现堆栈溢出,但是还没有发现任何东西.
Is it possible to restrict the dodge position to just one aesthetic? I've scoured documentation and stack overflow but haven't found anything yet.
推荐答案
group
确定躲避,因此可以这样做:
The group
determines dodging, so one can do:
ggplot(x,aes(xVar,Value,color=Color,shape=Shape,group=Shape))+
geom_point(position=position_dodge(width=.5))
这篇关于ggplot2:geom_point()避开形状但不显示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!