문제

I have gridded data on a pollutant. Each grid is denoted by its left most latitude and longitude. I would like to see how the level of this pollutant varies across grids. For this, I have made a level plot. My code shown below runs fine but the only trouble is that the plotted pollutant does not overlay the grids made using abline. Although I have specified the limit cutoffs for x and y, the values are plotted ahead of these cutoffs.

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

Here is a snippet of my data.

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

How can I get the values to overlay on the grids? Thanks.

도움이 되었습니까?

해결책

Interpretation 1) (If the problem is that you don't see your gridded values) : I think you just need to change the order in your panel function:

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

If you don't want the grid lines over your vales, then move panel.levelplot(...) to the end... you get the idea.

Interpretation 2) (if the problem is that the gridded values are centered rather than aligned to your longlat in the lower left corner:

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

Again, I'm not sure which of these you were asking, so please comment if neither is what you were looking for.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top