数组(不同的日期,值),箱图:x - 日期,y - 值

问题描述 投票:0回答:1

我是新用的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的箱形图,其中V12 = date1v11 = date2,...

图片来源:Plot boxplot and overlayed data points for matrix

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

r boxplot
1个回答
0
投票

如果您有数据框,则可以使用库ggplot2和函数geom_boxplot()为每个日期创建一个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()
© www.soinside.com 2019 - 2024. All rights reserved.