简体   繁体   English

使用ggplot的多个箱图

[英]Multiple boxplots using ggplot

I have a dataframe that looks like the one attached, with 6 columns and 1000 rows (tab separated). 我有一个看起来像附加的数据框,有6列和1000行(制表符分隔)。 The column headings (0,30,60,120,240 and 360) are a time series (with 0 representing 0 mins, 30 meaning 30 mins and so on). 列标题(0,30,60,120,240和360)是时间序列(0表示0分钟,30表示30分钟,依此类推)。 I'd like to create 6 boxplots corresponding to the columns using ggplot2 in a single plot, keeping in mind that they need to be spaced based on the time difference. 我想在一个图中使用ggplot2创建6个对应于列的箱形图,请记住它们需要根据时差进行间隔。 It seems I would need to melt the columns, but cant figure out a way to do so. 我似乎需要融化列,但无法找到一种方法。 Any help would be much appreciated. 任何帮助将非常感激。

        0       30       60       120      240     360
1       1       NA       NA       NA       1       1
2       NA      NA       NA       NA       NA      NA
3       NA      NA       1        1        1       1
4       0.5     0.21     0.15     1        0.38    0.8
5       0.63    1        0.86     0.85     0.94    0.91

Did you try just using melt? 你尝试过使用融化吗?

library(reshape2)
ggplot(melt(df), aes(variable, value)) + geom_boxplot()

在此输入图像描述

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

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