2012-10-14 28 views
2

GGPLOT2集群

有人可以点我在正确的方向,以使像这样的瓦特/ GGPLOT2一个阴谋?即使只是功能类型。

我一直在ggplot2环顾四周,找不到像这样的东西。

+2

您可以指定哪些是您尝试创建的情节的基本功能? (例如:你关心颜色?关于点上的'抖动?等等) –

回答

8

我假设图的基本特征是: a)所述X轴是分类的,并 b)中的点的X位置稍微改变, c)中的一些。总结统计(我用中位数)。 如果这是你在找什么,

require(ggplot2) 
require(plyr) 

#define the data 
lev <- gl(2, 10, 20, labels=c("I", "II")) 
y <- runif(20) 
df <- data.frame(lev, y) 

#calculate the medians - I'm guessing that's what the horiz lines are? 
meds <- ddply(df, .(lev), summarise, med = median(y)) 

ggplot(df, aes(x=lev, y=y, colour=lev)) + 
    geom_point(position="jitter") + 
    theme_bw() + 
    scale_colour_manual(values=c("red", "darkblue")) + 
    geom_errorbar(data=meds, aes(x=lev, y=med, ymin=med, ymax=med)) 

您可以使用annotate()添加数字和小支架,如果这是非常重要的。 enter image description here

+0

这看起来不错,但是还是有更多的聚合点,就像抖动和中心的混合? – Doug

+1

用'position = position_jitter(width = 0.05)'替换'position =“jitter”'。然后,您可能想要类似地调整误差栏的位置; 'geom_errorbar(width = 0.1,aes(...' –

+0

非常好!尽可能少的点(因为@Doug似乎想使它更规则),我会建议使用'geom_dotplot(binaxis =“y “,stackdir =”center“)'而不是带有抖动的geom_point。[docs](http://docs.ggplot2.org/current/geom_dotplot.html)有一些非常相似的数据。 –