首页 > 解决方案 > 数组(不同的日期,值),箱线图:x - 日期,y - 值

问题描述

我是使用 R 的新手。我有这样的数据:

Date;Value

2019-01-31;125

2019-01-31;127

2019-01-31;120

2019-01-31;116

2019-01-31;119

...

2019-02-01;222

2019-02-01;233

2019-02-01;225

2019-02-01;222

2019-02-01;222

...


2019-02-02;111

2019-02-02;234

2019-02-02;876

2019-02-02;234

2019-02-02;983

...

现在我有两个月的数据,但还会有更多。一天 = 288 条记录。

我想创建类似这样的箱线图 https://imgur.com/a/kO1iSPA where V12 = date1, v11 = date2, ...

图片来源:为矩阵绘制箱线图和叠加数据点

我已阅读上述主题,但我有一个不同的数组。你可以帮帮我吗?

标签: rboxplot

解决方案


如果你有一个数据框,你可以使用库ggplot2和函数geom_boxplot()来为每个日期创建一个箱线图。

df <- data.frame(
  Date  = c(rep('2019-01-31', 50), rep('2019-02-01', 50)),
  Value = round(rnorm(100, 150, 50))
)

library(ggplot2)
library(dplyr)

df %>% 
  ggplot(aes(x = Date, y = Value)) + 
  geom_boxplot()

推荐阅读