Building a box plot from all columns of data frame with column names on x in ggplot2

ggplot2, r

Solution

You can use `stack` to transform the data frame:

library(ggplot2)
ggplot(stack(df), aes(x = ind, y = values)) +
  geom_boxplot()

Problem

I have a data frame `my.df` of the following structure: ``` A B C 1 1 1 2 2 2 3 4 3 3 5 6 4 NA 7 8 5 NA 9 NA ``` How to build a box plot from it with column names on x axis and all the values on y? There are many answers like: ``` ggplot(melt(my.df), aes(variable, value)) + geom_boxplot() ``` But I don't understand, what I actually should pass as "variable" and "value". I tried `x=colnames(my.df))` and this partially works, however I still have no idea what to do with y.

Original source

Related problems