This is my first post, so go easy. Up until now (the past ~5 years?) I've been able to either tweak my R code the right way or find an answer on this or various other sites. Trust me when I say that I've looked for an answer! I have a working script to create the attached boxplot in basic R. http://i.stack.imgur.com/NaATo.jpg
This is fine, but I really just want to "jazz" it up in ggplot, for vain reasons. I've looked at the following questions and they are close, but not complete: Why does a boxplot in ggplot requires axis x and y? How do you draw a boxplot without specifying x axis?
My data is basically like "mtcars" if all the numerical variables were on the same scale. All I want to do is plot each variable on the same boxplot, like the basic R boxplot I made above. My y axis is the same continuous scale (0 to 1) for each box and the x axis simply labels each month plus a yearly average (think all the mtcars values the same on the y axis and the x axis is each vehicle model). Each box of my data represents 75 observations (kind of like if mtcars had 75 different vehicle models), again all the boxes are on the same scale. What am I missing?
ggplot
requires data in long format. You need to convert your data to long format with, e.g.,tidyr::gather
orreshape2::melt
. This will not demo well onmtcars
since (a) mtcars doesn't have ID variables for the x axis (though we could convert the rownames to a column) and (b) it wouldn't look very nice with some discrete data and almost nothing on the same scale. But if you get your data in long format, your ggplot should be as easy asggplot(long_data, aes(x = variable, y = value)) + geom_boxplot()
. – Gregor Thomas