I have a data frame like this:
2015 | 2016 | 2017
-----+------+------
1.2 | 5.2 | 5.6
9.1 | 3.7 | 4.3
.../...
and I'd like to box plot the values of the column for each year.
The only way I found is to manually change the data frame (imported from CSV file) into:
Year | Value
-----+-------
2015 | 1.2
... | ...
2016 | 5.2
... | ...
2017 | 5.6
... | ...
and use (if CPV is the name of my data frame):
ggplot(CPV, aes(x=factor(Year), y=Time)) + geom_boxplot()
First question: can I get the same result with the first form of data frame?
Second question: can I have the same plot if I have a "Value" column, and for each year, the count of occurences of this value:
Value | 2015 | 2016 | ...
------+------+------+---
1 | 0 | 5 | ...
1.1 | 4 | 1 | ...
ANSWER
Use the second form of the table for the box plot.
To get to this form, use the
melt
function from thedata.table
package.