使用ggplot2时闪避不起作用 [英] Dodge not working when using ggplot2
本文介绍了使用ggplot2时闪避不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在类似问题上看到了一些帖子,但找不到合适的解决方案。由于我的数据(下面可重现的例子)中的 count
有重复,所以我需要在彼此的侧面打印重叠点。人们正在使用 position_dodge
,但不知何故下面的例子不适合我。
library('ggplot2')
myData = data.frame(split = c(rep('a', 10),rep('b',10)),count = c(20,27,21,20,24,23,21,25,22,22,35,37,32,32,32,32,31 ,33,32,31))
p = ggplot(myData,aes(split,count))+ geom_point(aes(color = split),position = position_dodge(width = 0.3))
p
#获取警告
ymax未定义:使用y调整位置
解决方案
在这种情况下,您需要 position_jitter()
不闪避。
<$ p $ b $> $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ code>
其他选择是使用 geom_dotplot()
。
ggplot(myData,aes(split,count))+
geom_dotplot(aes(fill = split),binaxis =y,stackdir =center)
I saw a couple of posts on the similar problem but couldn't find a proper solution. Since the count
in my data (reproducible example below) has duplicates, I need to print the overlapping points on the side of each other. People are using position_dodge
but somehow the example below is not working for me.
library('ggplot2')
myData = data.frame(split = c(rep('a',10), rep('b',10)), count = c(20,27,21,20,24,23,21,25,22,22,35,37,32,32,32,32,31,33,32,31))
p = ggplot(myData, aes(split, count)) + geom_point(aes(colour=split), position=position_dodge(width=0.3))
p
#Getting the warning
ymax not defined: adjusting position using y instead
解决方案
In this case you need position_jitter()
not dodge.
ggplot(myData, aes(split, count)) + geom_point(aes(colour=split),
position=position_jitter(width=0.3))
Other alternative is to use geom_dotplot()
.
ggplot(myData, aes(split, count)) +
geom_dotplot(aes(fill=split),binaxis = "y",stackdir="center")
这篇关于使用ggplot2时闪避不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文