我想绘制同一地块中一年中不同季节(分组为冷或暖)的时间序列数据,并确定两个时期。我怎样才能做到这一点?
可重复数据如下:
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"))
以下这些代码将为两个时期创建两个单独的图:
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"))
以下代码创建了一个图,但两个周期没有明确的划分。我的愿望是在一个地块中为两个时期创建可识别的情节。
with(chicago,plot(date,death,pch=".", ylab= expression("Mortality Count"), main = "Daily Mortality from 1987-2000"))
答案 0 :(得分:1)
查看?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"))
这对你有用吗?