Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boxplot of table using ggplot2

Tags:

r

ggplot2

boxplot

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".

like image 833
felifrei Avatar asked Feb 25 '13 16:02

felifrei


People also ask

How do you make a boxplot in a table in R?

In R, boxplot (and whisker plot) is created using the boxplot() function. The boxplot() function takes in any number of numeric vectors, drawing a boxplot for each vector. You can also pass in a list (or data frame) with numeric vectors as its components.

How do you make a boxplot in ggplot2?

In ggplot2, geom_boxplot() is used to create a boxplot. Let us first create a regular boxplot, for that we first have to import all the required libraries and dataset in use. Then simply put all the attributes to plot by in ggplot() function along with geom_boxplot.

What do Ggplot Boxplots show?

The boxplot compactly displays the distribution of a continuous variable. It visualises five summary statistics (the median, two hinges and two whiskers), and all "outlying" points individually.

How do you make a boxplot in a single column in R?

First of all, create a data frame with single numerical column and create the boxplot for that column using boxplot function. Then, create the same boxplot with show. names argument set to TRUE.


1 Answers

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

like image 119
Arun Avatar answered Oct 08 '22 17:10

Arun