【问题标题】:Levelplot not plotted correctly, values not overlaid on gridsLevelplot 未正确绘制,值未覆盖在网格上
【发布时间】:2013-11-06 17:00:23
【问题描述】:

我已经对污染物进行了网格化数据。每个网格由其最左边的纬度和经度表示。我想看看这种污染物的水平如何在网格中变化。为此,我做了一个水平图。下面显示的代码运行良好,但唯一的问题是绘制的污染物没有覆盖使用 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()  

这是我的数据的 sn-p。

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

如何让值叠加在网格上?谢谢。

【问题讨论】:

  • 如果我对您的问题的解释有误,请发表评论。您是说网格值根本不显示,因为它们是重叠的(我的理解)或者它们以您的 x,y 坐标为中心,因此与您的 abline 网格不符合预期,或者完全是其他什么?

标签: r lattice levelplot


【解决方案1】:

解释 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")         
                     }

如果您不希望网格线超过您的 vales,则将 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)
)

再说一次,我不确定您要问的是哪一个,所以如果您都不是您要找的,请发表评论。

【讨论】:

  • 我必须集中我的数据。我应该能够发现这一点。谢谢蒂姆
猜你喜欢
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-23
  • 2013-02-25
  • 2016-09-26
相关资源
最近更新 更多