使用ggplot2的表格Boxplot [英] Boxplot of table using ggplot2

查看:180
本文介绍了使用ggplot2的表格Boxplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用R中的'ggplot'来绘制箱子图和我的数据,但我无法做到。谁能帮我吗?
数据如下表所示:

I'm trying to plot a boxplot graph with my data, using 'ggplot' in R, but I just can't do it. Can anyone help me out? The data is like the table below:

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

我真正想要的是每个栏目的箱型图,没有任何关系按列排列。

And what I exactly want is a boxplot of each column, without any relation "column by column".

推荐答案

ggplot2 需要特定格式的数据。在这里,你需要 x = y = 其中 y 将是值, x 将是相应的列ID。使用 melt reshape2 包到 melt 获取数据这个格式的数据,然后绘图。

ggplot2 requires data in a specific format. Here, you need x= and y= where y will be the values and x will be the corresponding column ids. Use melt from reshape2 package to melt the data to get the data in this format and then plot.

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

这篇关于使用ggplot2的表格Boxplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆