如何在R中制作时间序列盒子图 [英] How to make a timeseries boxplot in R

查看:295
本文介绍了如何在R中制作时间序列盒子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用 ggplot2 来制作一个时间系列boxplot。

I'm trying to make a time series boxplot using ggplot2.

个人。

我需要使用我的数据在月份内制作时间序列箱。

I need to make a timeseries boxplot by month with my data.

我认为我的问题

p <- ggplot(mydata, aes(factor(date), measure))

推荐答案

更新: OP澄清多年必须分开处理。

Updated: Based on OP's clarification that multiple years have to be handled separately.

library(ggplot2)

#generate dummy data
date_range <- as.Date("2010/06/01") + 0:400
measure <- runif(401)
mydata <- data.frame(date_range, measure)

# create new columns for the months and years, and 
# and a year_month column for x-axis labels
mydata$month <- format(date_range, format="%b")
mydata$year <- as.POSIXlt(date_range)$year + 1900
mydata$year_month <- paste(mydata$year, mydata$month)
mydata$sort_order <- mydata$year *100 + as.POSIXlt(date_range)$mon

#plot it
ggplot(mydata) + geom_boxplot(aes(x=reorder(year_month, sort_order), y=measure))

img src =https://i.stack.imgur.com/wD1z5.pngalt =希望这可以帮助你向前迈进

Which produces:

这篇关于如何在R中制作时间序列盒子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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