简体   繁体   English

同一图中不同季节的时间序列图

[英]Time-series plot for different seasons in the same plot

I would like plot a time series data for different seasons of the year (grouped as cold or warm) in the same plot and identify the two periods. 我想在同一图中绘制一年中不同季节(分为冷或热)的时间序列数据,并确定两个时期。 How can I do that? 我怎样才能做到这一点?

Reproducible data follows: 可复制的数据如下:

library(gamair) 
data(chicago) 
chicago$date<-seq(from=as.Date("1987-01-01"), to=as.Date("2000-12-31"),length=5114)
data.cold <- subset(chicago, quarters(date) %in% c("Q1", "Q4"))
data.warm <- subset(chicago, quarters(date) %in% c("Q2", "Q3"))

These codes below will create two separate plots for the two periods: 以下这些代码将为两个期间创建两个单独的图:

with(data.cold,plot(date,death,pch=".", ylab= expression("Mortality Count"), main = "Daily Mortality in cold season"))
with(data.warm ,plot(date,death,pch=".", ylab= expression("Mortality Count"), main = "Daily Mortality in warm season"))

This following code creates one plot, but there is no clear demarcation of the two periods. 下面的代码创建了一个图,但是没有明确划分两个时期。 My wish is to create identifiable plot for the two periods in a single plot. 我的愿望是在一个图中创建两个时期的可识别图。

with(chicago,plot(date,death,pch=".", ylab= expression("Mortality Count"), main = "Daily Mortality from  1987-2000"))

Have a look at ?points : 看一下?points

with(data.cold,plot(date,death,pch=".", ylab= expression("Mortality Count"), main = "Daily Mortality in cold season"))
with(data.warm ,points(date,death,pch=".", ylab= expression("Mortality Count"), main = "Daily Mortality in warm season", col="red"))
legend("topright", c("cold", "warm"), fill=c("black", "red"))

Does that work for you? 那对你有用吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM