R 如何在时间序列数据帧中获取汇总表/箱线图?
我有一个包含时间序列的数据帧,如下所示:R 如何在时间序列数据帧中获取汇总表/箱线图?,r,R,我有一个包含时间序列的数据帧,如下所示: example <- data.frame( Date=seq( from=as.POSIXct("2012-1-1 0:00", tz="UTC"), to=as.POSIXct("2012-1-31 23:00", tz="UTC"), by="10 min"), frequency=runif(4459, min=12, max=26)) 我如何分别为每天绘制dropbox?我试过这个: boxplot(example$freqen
example <- data.frame(
Date=seq(
from=as.POSIXct("2012-1-1 0:00", tz="UTC"),
to=as.POSIXct("2012-1-31 23:00", tz="UTC"),
by="10 min"),
frequency=runif(4459, min=12, max=26))
我如何分别为每天绘制dropbox?我试过这个:
boxplot(example$freqency, example$Date, by="day")
如何在天内选择时间数据?我还希望按天计算汇总表,但在这种情况下,我只希望使用每小时的数据,例如0:00、1:00、2:00等
有人能帮我吗?要获得每日频率的摘要,您可以将基本R的聚合与strftime结合使用:
要获得每天的箱线图,我们只需要在ggplot2中为x轴创建一个$day列
要按天获取频率摘要,您可以将基本R中的聚合与strftime结合使用:
要获得每天的箱线图,我们只需要在ggplot2中为x轴创建一个$day列
简单地尝试一下:
天内:
example$str.date <- substring(as.character(example$Date),1,10)
summary.example <- aggregate(frequency~str.date, example, FUN = summary)
library(ggplot2)
ggplot(example, aes(str.date, frequency, group=str.date, fill=str.date)) + geom_boxplot() +
theme(axis.text.x = element_text(angle=90, vjust = 0.5))
每天数小时内:
example$str.date.hrs <- substring(as.character(example$Date),1,13)
summary.example <- aggregate(frequency~str.date.hrs, example, FUN = summary)
library(ggplot2)
ggplot(example[example$str.date=='2012-01-01',], aes(str.date.hrs, frequency, group=str.date.hrs, fill=str.date.hrs)) + geom_boxplot() +
theme(axis.text.x = element_text(angle=90, vjust = 0.5))
简单地尝试一下:
天内:
example$str.date <- substring(as.character(example$Date),1,10)
summary.example <- aggregate(frequency~str.date, example, FUN = summary)
library(ggplot2)
ggplot(example, aes(str.date, frequency, group=str.date, fill=str.date)) + geom_boxplot() +
theme(axis.text.x = element_text(angle=90, vjust = 0.5))
每天数小时内:
example$str.date.hrs <- substring(as.character(example$Date),1,13)
summary.example <- aggregate(frequency~str.date.hrs, example, FUN = summary)
library(ggplot2)
ggplot(example[example$str.date=='2012-01-01',], aes(str.date.hrs, frequency, group=str.date.hrs, fill=str.date.hrs)) + geom_boxplot() +
theme(axis.text.x = element_text(angle=90, vjust = 0.5))
example$str.date.hrs <- substring(as.character(example$Date),1,13)
summary.example <- aggregate(frequency~str.date.hrs, example, FUN = summary)
library(ggplot2)
ggplot(example[example$str.date=='2012-01-01',], aes(str.date.hrs, frequency, group=str.date.hrs, fill=str.date.hrs)) + geom_boxplot() +
theme(axis.text.x = element_text(angle=90, vjust = 0.5))