R Levelplot未正确打印,值未覆盖在网格上

R Levelplot未正确打印,值未覆盖在网格上,r,lattice,levelplot,R,Lattice,Levelplot,我有一个污染物的网格数据。每个栅格由其最左侧的纬度和经度表示。我想看看这种污染物的水平在电网中是如何变化的。为此,我绘制了一个水平图。下面显示的代码运行良好,但唯一的问题是绘制的污染物没有覆盖使用abline制作的网格。虽然我已经指定了x和y的极限截止值,但这些值是在这些截止值之前绘制的 library(lattice) library(maptools) imap = readShapeSpatial("IND_adm3") pdf("trial2.pdf",w

我有一个污染物的网格数据。每个栅格由其最左侧的纬度和经度表示。我想看看这种污染物的水平在电网中是如何变化的。为此,我绘制了一个水平图。下面显示的代码运行良好,但唯一的问题是绘制的污染物没有覆盖使用abline制作的网格。虽然我已经指定了x和y的极限截止值,但这些值是在这些截止值之前绘制的

    library(lattice)
    library(maptools)
    imap = readShapeSpatial("IND_adm3")
    pdf("trial2.pdf",width=11, height=8)
    levelplot(surface_aod~longitude+latitude,data=s.data,
                  panel = function(...){
                  panel.levelplot(...)
                  panel.abline(v=(71:88),col="dark red")              
                             panel.abline(h=(17:31),col="dark red")    
                   sp.polygons(imap)         
                     }, 
   col.regions = heat.colors(100),aspect="iso", region=TRUE,scales=list(x=list(at=seq(from=71,to=88, by=1)), y=list(at=seq(from=17,to=31,   by=1)),cex=.7, alternating=3),xlim=c(70,90), ylim=c(16,32))
   dev.off()  
这是我的一段数据

 dput(head(s.data))
 structure(list(latitude = c(17L, 18L, 19L, 19L, 20L, 21L), longitude = c(80L, 
 82L, 80L, 81L, 82L, 75L), surface_aod = c(0.2652681, 0.0040855, 
 0.2032517, 0.0929442, 0.1194997, 0.3600747)), .Names = c("latitude", 
 "longitude", "surface_aod"), row.names = c(NA, 6L), class = "data.frame")
如何获得要覆盖在网格上的值?谢谢。

解释1)(如果问题是您没有看到网格化的值): 我认为您只需要更改面板功能中的顺序:

panel = function(...){
                 # panel.levelplot(...) # insead of marking up 
                 # on top of the plotted values
                   sp.polygons(imap) 
                   panel.levelplot(...)   
                   panel.abline(v=(71:88),col="dark red")              
                   panel.abline(h=(17:31),col="dark red")         
                     }
如果您不希望网格线覆盖您的值,请将
panel.levelplot(…)
移动到末尾。。。你明白了

解释2)(如果问题是网格值居中,而不是与左下角的longlat对齐:

# shift the long lat to the cell center. In this case, 
# the centroid is convenetly, .5 up
# and .5 over, so you can do it in-line:
levelplot(surface_aod~I(longitude+.5)+I(latitude+.5),data=s.data,
        panel = function(...){
            panel.levelplot(...)
            panel.abline(v=(71:88),col="dark red")              
            panel.abline(h=(17:31),col="dark red")    
            #sp.polygons(imap)         
        }, 
        col.regions = heat.colors(100),
        aspect="iso", 
        region=TRUE,
        scales=list(x=list(at=seq(from=71,to=88, by=1)), 
                y=list(at=seq(from=17,to=31, by=1)),
                cex=.7, 
                alternating=3),
        xlim=c(70,90), 
        ylim=c(16,32)
)
同样,我不确定您问的是哪一个,因此如果两个都不是您想要的,请发表评论。

解释1)(如果问题是您没有看到网格化的值): 我认为您只需要更改面板功能中的顺序:

panel = function(...){
                 # panel.levelplot(...) # insead of marking up 
                 # on top of the plotted values
                   sp.polygons(imap) 
                   panel.levelplot(...)   
                   panel.abline(v=(71:88),col="dark red")              
                   panel.abline(h=(17:31),col="dark red")         
                     }
如果您不希望网格线覆盖您的值,请将
panel.levelplot(…)
移动到末尾。。。你明白了

解释2)(如果问题是网格值居中,而不是与左下角的longlat对齐:

# shift the long lat to the cell center. In this case, 
# the centroid is convenetly, .5 up
# and .5 over, so you can do it in-line:
levelplot(surface_aod~I(longitude+.5)+I(latitude+.5),data=s.data,
        panel = function(...){
            panel.levelplot(...)
            panel.abline(v=(71:88),col="dark red")              
            panel.abline(h=(17:31),col="dark red")    
            #sp.polygons(imap)         
        }, 
        col.regions = heat.colors(100),
        aspect="iso", 
        region=TRUE,
        scales=list(x=list(at=seq(from=71,to=88, by=1)), 
                y=list(at=seq(from=17,to=31, by=1)),
                cex=.7, 
                alternating=3),
        xlim=c(70,90), 
        ylim=c(16,32)
)

同样,我也不知道你问的是哪一个,所以如果你想问的都不是,请评论。

如果我对你的问题解释错误,请评论。你是说网格值根本不显示,因为它们重叠(我理解的是)或者它们集中在你的x,y坐标上,因此与你的abline网格不一致,或者完全不一致?如果我对你的问题解释错误,请发表评论。你是说网格化的值根本不显示,因为它们重叠(我的理解)或者它们集中在你的x,y坐标上,因此与你的abline网格不符合预期,或者完全是其他东西?我必须集中我的数据。我应该能够发现这个。谢谢Tim我必须集中我的数据。我应该能够发现这个。谢谢Tim