时间序列级别图上的叠加点

时间:2017-11-10 23:05:31

标签: r plot lattice levelplot

我有一个使用时间序列温度数据的水平图。级别图如下所示:

Date<-as.Date(c("2017-01-01","2017-01-01","2017-01-01","2017-01-02","2017-01-02","2017-01-02","2017-01-03","2017-01-03","2017-01-03","2017-01-4","2017-01-4","2017-01-4"))
Date<-as.POSIXct(Date)
Y<-c(1,2,3,1,2,3,1,2,3,1,2,3)
Temp<-c(20,23,25,19,20,21,18,19,20,13,17,19)
DF<-data.frame(Date,Y,Temp)


dev.new(width=15, height=6)
levelplot(Temp ~ Date * Y, data = DF,ylim=c(3,1),
  xlab = "TimeStamp", ylab = "Temp",
  main = "Test", aspect=0.4,
  col.regions =colorRampPalette(c('blue','red')),at=seq(13, 25, length.out=120))

我想在这个情节上叠加3分。理想情况下,我希望1月1日Y = 2,1月2日Y = 2.3,1月3日Y = 1.2

1 个答案:

答案 0 :(得分:2)

您可以使用LocalTime中的layer,如下所示:

latticeExtra

哪个输出:

enter image description here

如果您希望这些点稳定,可以尝试library(latticeExtra) p <- levelplot(Temp ~ Date * Y, data = DF,ylim=c(3,1), xlab = "TimeStamp", ylab = "Temp", main = "Test", aspect=0.4, col.regions = colorRampPalette(c('blue','red')), at=seq(13, 25, length.out=120)) p + layer(panel.points(c(DF$Date[1], DF$Date[4], DF$Date[7]), c(2, 2.3, 1.2), pch = 1, col = "black"))