2016-10-19 20 views
6

yatay çizgi olarak vasıta ekleyin:R ggplot2: I ggplot2 kullanarak bir Boxplot oluşturduk bir Boxplot

library(ggplot2) 

dat <- data.frame(study = c(rep('a',50),rep('b',50)), 
        FPKM = c(rnorm(1:50),rnorm(1:50))) 

ggplot(dat, aes(x = study, y = FPKM)) + geom_boxplot() 

boxplot her kutu boyunca yatay bir çizgi olarak medyan gösterir.

enter image description here

nasıl bu grubun ortalamasını temsil kutusuna kesikli çizgi eklerim?

Teşekkürler!

cevap

10

geom_errorbar ile stat_summary kullanarak arazilere yatay çizgiler ekleyebilirsiniz. Çizgi yataydır, çünkü y minimum ve maksimum y ile aynı şekilde ayarlanır.

ggplot(dat, aes(x = study, y = FPKM)) + 
    geom_boxplot() + 
    stat_summary(fun.y = mean, geom = "errorbar", aes(ymax = ..y.., ymin = ..y..), 
       width = .75, linetype = "dashed") 

enter image description here