【问题标题】:Boxplot of table using ggplot2使用ggplot2的表格箱线图
【发布时间】:2013-02-25 16:15:15
【问题描述】:

我试图用我的数据绘制一个箱线图,在 R 中使用“ggplot”,但我做不到。谁能帮我吗? 数据如下表:

Paratio  ShapeIdx  FracD   NNDis   Core
-3.00    1.22    0.14    2.71    7.49
-1.80    0.96    0.16    0.00    7.04
-3.00    1.10    0.13    2.71    6.85
-1.80    0.83    0.16    0.00    6.74
-0.18    0.41    0.27    0.00    6.24
-1.66    0.12    0.11    2.37    6.19
-1.07    0.06    0.14    0.00    6.11
-0.32    0.18    0.23    0.00    5.93
-1.16    0.32    0.15    0.00    5.59
-0.94    0.14    0.15    1.96    5.44
-1.13    0.31    0.16    0.00    5.42
-1.35    0.40    0.15    0.00    5.38
-0.53    0.25    0.20    2.08    5.32
-1.96    0.36    0.12    0.00    5.27
-1.09    0.07    0.13    0.00    5.22
-1.35    0.27    0.14    0.00    5.21
-1.25    0.21    0.14    0.00    5.19
-1.02    0.25    0.16    0.00    5.19
-1.28    0.22    0.14    0.00    5.11
-1.44    0.32    0.14    0.00    5.00

而我真正想要的是每列的箱线图,没有任何“逐列”关系。

【问题讨论】:

    标签: r ggplot2 boxplot


    【解决方案1】:

    ggplot2 需要特定格式的数据。在这里,您需要x=y=,其中y 将是值,x 将是相应的列ID。使用meltreshape2包到melt数据,得到这种格式的数据,然后绘制。

    require(reshape2)
    ggplot(data = melt(dd), aes(x=variable, y=value)) + geom_boxplot(aes(fill=variable))
    

    【讨论】:

    • 非常感谢!!真的奏效了……还有一个问题:我怎样才能排除那个传说?
    • + theme(legend.position="none")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 2017-10-13
    相关资源
    最近更新 更多