Home > Back-end >  How to boxplot list by names in R?
How to boxplot list by names in R?

Time:11-03

I have a list of lists, I want to boxplot it by grouping it by names.

Here is the resume of my data:

enter image description here

e.g.: I want 4 box: LB, SD, LI and RN.

Is that possible or do I have to convert it to dataframe?

CodePudding user response:

We need to stack the list into a dataframe, then plot:

#example data, list has duplicated names
x <- list(aa = 1:3, aa = 6:8, bb = 4:8, cc = 5:10)

boxplot(values ~ ind, data = stack(x))

enter image description here

CodePudding user response:

You can make it in this way too:

my_boxplot <- do.call(boxplot, 
                      list(list(aa = runif(15, min=0, max=1), 
                                bb = runif(15, min=-1, max=2), 
                                cc = runif(15, min=1, max=4), 
                                dd = runif(15, min=-3, max=7)))) 

enter image description here

But why you don't want to convert list into data frame? With ggplot2 you can make cooler visuals.

  • Related