如何为R中的给定表中的每一行生成boxplot?

时间:2016-02-02 14:33:56

标签: r matrix boxplot

我在文本文件中有以下格式的数据:

#Position   Mean    Median  Lower_Quartile  Upper_Quartile  10th_Percentile 90th_Percentile
1   33.79097948291701   34.0    34.0    34.0    34.0    34.0
2   33.79898508246205   34.0    34.0    34.0    34.0    34.0
3   33.81967715123146   34.0    34.0    34.0    34.0    34.0
4   33.821820727065926  34.0    34.0    34.0    34.0    34.0
5   33.82225819152194   34.0    34.0    34.0    34.0    34.0
6   37.62032459862636   38.0    38.0    38.0    38.0    38.0
7   37.61853099435671   38.0    38.0    38.0    38.0    38.0
8   37.574522070081805  38.0    38.0    38.0    38.0    38.0
9   37.54608688044097   38.0    38.0    38.0    37.0    38.0

每行用于生成箱线图。我想生成一个图表,在一个图表中显示来自上表中所有行的箱线图,按位置排序。默认的boxplot选项将每列加载到boxplot中。如何改变?

我的初始方法是使用默认的boxplot命令,为每个列提供boxplot。

1 个答案:

答案 0 :(得分:1)

鉴于df包含您的数据,您可以尝试

library(ggplot2)
ggplot(df, aes(as.factor(Position))) +
  geom_boxplot(aes(ymin = X10th_Percentile, lower = Lower_Quartile, middle = Median, upper = Upper_Quartile, ymax =X90th_Percentile), stat = "identity")