How to pass a list of ggplot2?

I am trying to make boxplot a list of values ​​in ggplot2, but the problem is that it does not know how to handle lists, what should I try?

eg:.

k <- list(c(1,2,3,4,5),c(1,2,3,4),c(1,3,6,8,14),c(1,3,7,8,10,37))
k
[[1]]
[1] 1 2 3 4 5

[[2]]
[1] 1 2 3 4

[[3]]
[1]  1  3  6  8 14

[[4]]
[1]  1  3  7  8 10 37

If I pass kin an argument to boxplot(), it will process it flawlessly and create a nice (well, not very nice ... hehehe) boxplot with a range of all values ​​in the form of the Y axis and (each element) as the X axis.

How can I achieve the same effect with ggplot2? I think dataframes or matrices are not an option because vectors have different lengths.

thank

+5
source share
1 answer

, . ggplot2 , . , :

d <- data.frame(x = unlist(k), 
                grp = rep(letters[1:length(k)],times = sapply(k,length)))
ggplot(d,aes(x = grp, y = x)) + geom_boxplot()

enter image description here

, melt , , . , - .

+8

All Articles