了解带有'抖动'的箱线图

时间:2015-07-25 18:57:31

标签: r ggplot2

我正在研究一个大型数据集,研究几个地理区域的疾病病例,其中蓟作为预测因素之一。我试过用抖动创建盒子图,但是不能很清楚地解释它。有人可以帮忙吗?

以下是代码:

ggplot(factor(Region), Cases, data=orf, geom=c("boxplot", "jitter"),                            
      main=" Cases by Thistles and Regions",fill=factor(Thistles),                          
      xlab="Regions", ylab="Number of cases")

这是一个非常大的数据集,所以这里只是一小部分:

Region  Thistles    Cases
    1   1           40
    1   2           0
    1   1           8
    1   3           73
    1   3           0
    1   1           26
    1   2           0
    1   1           45
    1   4           0
    1   4           22
    1   0           0
    2   3           46
    1   0           10
    2   1           6
    2   1           539
    2   1           0
    2   2           0
    2   1           60
    2   1           0
    2   1           10
    2   3           0
    2   3           29
    3   2           0
    3   4           35
    3   3           100
    3   2           0
    3   1           550
    3   2           0
    3   3           1
    3   5           67
    3   1           0
    3   2           90

http://plnkr.co/edit/P81QUK2vl3DttwzQmwM4?p=preview

1 个答案:

答案 0 :(得分:4)

这些情节说明了@RHertel在评论中提出的观点。

enter image description here

library(ggplot2)

p1 = ggplot(iris, aes(x=Species, y=Sepal.Length)) +
     geom_point(aes(fill=Species), size=5, shape=21, colour="grey20") +
     geom_boxplot(outlier.colour=NA, fill=NA, colour="grey20") +
     labs(title="Not Jittered")


p2 = ggplot(iris, aes(x=Species, y=Sepal.Length)) +
     geom_point(aes(fill=Species), size=5, shape=21, colour="grey20",
                position=position_jitter(width=0.2, height=0.1)) +
     geom_boxplot(outlier.colour=NA, fill=NA, colour="grey20") +
     labs(title="Jittered")

library(gridExtra)
png("jittering.png", height=5, width=10, units="in", res=100)
grid.arrange(p1, p2, nrow=1)
dev.off()
相关问题