Fine tuning ggplot2's geom boxplot

后端 未结 2 946
执念已碎
执念已碎 2021-01-12 14:54

I have this data.frame

my.df = data.frame(mean = c(0.045729661,0.030416531,0.043202944,0.025600973,0.040526913,0.046167044,0.029352414,0.021477789,0.02758052         


        
2条回答
  •  天涯浪人
    2021-01-12 15:29

    Here's what worked for me:

    p1 = ggplot(data = my.df, aes(factor(replicate), color = factor(parent.origin)))
    p1 = p1 + geom_boxplot(aes(fill = factor(parent.origin),lower = mean - std.dev, 
         upper = mean + std.dev, middle = mean, ymin = mean - 3*std.dev, 
         ymax = mean + 3*std.dev), position = position_dodge(width = 0), width = 0.5, 
             alpha = 0.5, stat="identity") + 
         facet_wrap(~group, ncol = 4)+
         scale_fill_manual(values = c("red","blue"),labels = c("maternal","paternal"),
             name = "parental allele")+
         scale_colour_manual(values = c("red","blue"),labels = c("maternal","paternal"),
             name = "parental allele")
    

    The width value within the position_dodge parameter determines the separation between the red and blue boxes per each replicate, and the other width parameter controls the width o he box. The alpha value controls transparency.

提交回复
热议问题