简体   繁体   中英

Boxplot of multiple columns in `R` using ggplot

I simply wanted to create a boxplot of three numeric columns of a dataframe in R . The dataframe looks like this:

  no_filter                      filter1                   filter2
1 0.7223437                    0.7376562                    0.7418750
2 0.7223437                    0.7376562                    0.7418750
3 0.7262500                    0.7276562                    0.7289062

I had a look here How to create one box plot using multiple columns and argument "split" , but didn't really get my head around it. So if anyone has an idea, would be super appreciated. In the best case with gpplot

With ggplot , we may need to reshape into 'long' format

library(dplyr)
library(tidyr)
df1 %>% 
  pivot_longer(cols = everything()) %>% 
  ggplot(aes(x = name, y = value)) +
      geom_boxplot()

在此处输入图像描述

###data

df1 <- structure(list(no_filter = c(0.7223437, 0.7223437, 0.72625), 
    filter1 = c(0.7376562, 0.7376562, 0.7276562), filter2 = c(0.741875, 
    0.741875, 0.7289062)), class = "data.frame", row.names = c("1", 
"2", "3"))

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