简体   繁体   English

使用ggplot在`R`中绘制多列的箱线图

[英]Boxplot of multiple columns in `R` using ggplot

I simply wanted to create a boxplot of three numeric columns of a dataframe in R .我只是想在R中创建一个包含 dataframe 的三个数字列的箱线图。 The dataframe looks like this: dataframe 看起来像这样:

  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.我在这里查看了How to create one box plot using multiple columns and argument "split" ,但我并没有真正理解它。 So if anyone has an idea, would be super appreciated.因此,如果有人有想法,将不胜感激。 In the best case with gpplot在最好的情况下使用gpplot

With ggplot , we may need to reshape into 'long' format使用ggplot ,我们可能需要重塑为“长”格式

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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