简体   繁体   中英

How to boxplot list by names in R?

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

Here is the resume of my data:

在此处输入图片说明

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

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

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))

在此处输入图片说明

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)))) 

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM