r - 数组(不同的日期,值),箱线图: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
, ...
图片来源:为矩阵绘制箱线图和叠加数据点
我已阅读上述主题,但我有一个不同的数组。你可以帮帮我吗?
解决方案
如果你有一个数据框,你可以使用库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()
推荐阅读
- python - Pandas 不会以正确的顺序将数据输入到数据框中
- pytorch - 与从文件中读取的相同张量进行比较时,为什么 C++ PyTorch API 中的“is_same”会失败?
- javascript - 模拟 DayJs 默认函数及其链式方法
- javascript - 在 Vue.js 中更改路线时,Bootstrap 4 轮播不滑动
- python - 将对象传递给函数而不在 Python 中进行修改
- nginx - 如何使用“controller.nodeSelector”选项将 nginx-ingress 控制器部署到 Kubernetes 主节点?
- css - 如何在引导程序 4.5 中从移动设备上的行中删除填充?
- visual-studio-code - 如何阻止对象在 fira 代码 iScript 中显示为草书?
- vb.net - 尝试在数据集列表达式中使用 DateDiff 函数
- ruby - Heroku:将 Ruby 应用程序从 Cedar-14 升级到 Heroku-18