使用ggplot的多个箱形图 [英] Multiple boxplots using ggplot

查看:121
本文介绍了使用ggplot的多个箱形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像附加的数据框,有6列和1000行(分隔标签)。列标题(0,30,60,120,240和360)是时间序列(0代表0分钟,30代表30分钟等等)。我想在单个图中使用ggplot2创建对应于列的6个盒形图,请记住,它们需要根据时间差异进行间隔。看起来我需要融化这些专栏,但无法想出一个办法。任何帮助将不胜感激。

  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

解决方案

您是否尝试过使用融化?

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


I have a dataframe that looks like the one attached, with 6 columns and 1000 rows (tab separated). 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). 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. 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()

这篇关于使用ggplot的多个箱形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆