2017-11-10 98 views
1

我有一個使用時間序列溫度數據的水平圖。級別圖如下所示:時間序列水平圖上的覆蓋點

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

回答

2

您可以使用layerlatticeExtra這樣的:

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")) 

哪輸出這樣的:

enter image description here

你可以嘗試pch = 19如果你想點固體。