创建一个boxplot,ggplot2

时间:2016-05-04 20:23:58

标签: r ggplot2 boxplot

我有以下数据集:

depth <- data.frame(Sample = c("AD_001", "AD_009", "AD_017", "AD_025", 
                           "AD_033", "AD_041", "AD_049", "AD_057", 
                           "AD_065", "AD_073", "AD_081", "AD_089"), 
                median = c(12, 13, 11, 12, 12, 12, 13, 13, 14, 15, 15, 13), 
                granular_first_quartile = c(5, 6, 5, 6, 5, 6, 6, 6, 7, 7, 7, 6), 
                granular_third_quartile = c(23, 25, 21, 22, 23, 23, 24, 25, 27, 28, 28, 24))

并且想要创建一个箱线图但是,我生成的图表没有相同的x字段。

ggplot(depth, aes(as.factor(Sample))) + geom_boxplot(aes(middle = median, lower = granular_first_quartile, upper = granular_third_quartile, ymin = granular_first_quartile, ymax = granular_third_quartile), stat = 'identity') + coord_flip()

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您已拥有所有(中位数,第1季度和第3季度),只需指定loweruppermiddleymin和{{1} }

(仅供参考,https://en.wikipedia.org/wiki/Box_plot#/media/File:Boxplot_vs_PDF.svg

ymax