R - 具有多个层(晶格)的轮廓图

Yu *_*eng 1 r panel map contour lattice

这是我的代码和相关的变量结构.

Correlation_Plot = contourplot(cor_Warra_SF_SST_JJA, region=TRUE, at=seq(-0.8, 0.8, 0.2), 
labels=FALSE, row.values=(lon_sst), column.values=lat_sst,
xlab='longitude', ylab='latitude')

Correlation_Plot = Correlation_Plot + layer({ ok <- (cor_Warra_SF_SST_JJA>0.6);
            panel.text(cor_Warra_SF_SST_JJA[ok]) })
Correlation_Plot

     # this is the longitude (from -179.5 to 179.5) , 360 data in total
    > str(lon_sst) 
     num [1:360(1d)] -180 -178 -178 -176 -176 ...

     # this is the latitude (from -89.5 to 89.5), 180 data in total 
    > str(lat_sst) 
     num [1:180(1d)] -89.5 -88.5 -87.5 -86.5 -85.5 -84.5 -83.5 -82.5 -81.5 -80.5 ...

     # This is data set corresponding to longitude and latitude  
     > dim(cor_Warra_SF_SST_JJA) 
       [1] 360 180
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我试图用于layer()显示大于0.6的轮廓标签,但它不起作用.

  1. 是否有可能增加图例中的颜色对比度,因此可以非常清楚什么颜色响应什么级别.什么是颜色选项,我找不到它们?

  2. 最重要的是我想在指定的等高线间隔画一条较粗的黑线(例如+/- 0.2)?我认为ican也是如此layer(),但我不确定我panel应该使用什么功能.

  3. 此外,我试图用纯色填充大陆,但我找不到它的任何东西.我尝试过使用map,但它不适用于格子.

谢谢你的帮助.

jba*_*ums 5

看看?panel.levelplot有关的其他参数contourplot.

  1. 您可以使用col.regions参数,该参数将采用您想要与您的间隔对应的颜色矢量,或颜色斜坡函数(例如下面).

  2. 使用自定义面板函数,类似于此(使用在SantiagoBeguería博客上给出的方法生成的空间自相关虚拟数据集).用lpolygon绘制地图的对象:

    生成虚拟数据集:

    library(gstat)
    
    # create structure
    xy <- expand.grid(1:360, 1:180)
    names(xy) <- c('x','y')
    
    # define the gstat object (spatial model)
    g.dummy <- gstat(formula=z~1, locations=~x+y, dummy=T, beta=1,    
      model=vgm(psill=0.025,model='Exp',range=5), nmax=20)
    
    # make a simulations based on the gstat object
    yy <- predict(g.dummy, newdata=xy, nsim=1)
    gridded(yy) = ~x+y
    
    # scale to range [-1, 1]
    z <- matrix(yy@data[, 1], ncol=180)
    z.scalefac <- (max(z) - min(z)) / 2
    z <- -1 + (z - min(z)) / z.scalefac
    
    Run Code Online (Sandbox Code Playgroud)
  3. 情节:

    library(lattice)
    library(maps)
    
    lon_sst <- seq(-179.5, 179.5, 1)
    lat_sst <- seq(-89.5, 89.5, 1)
    
    colramp <- colorRampPalette(c('red', 'yellow', 'white', 'green', 'blue'))
    
    contourplot(z, xlim=c(100, 160), ylim=c(-80, -50), 
      at=seq(-1, 1, 0.2), region=TRUE, col.regions=colramp,
      row.values=lon_sst, column.values=lat_sst, labels=FALSE, 
      xlab='longitude', ylab='latitude',
      panel = function(at, region, ...) {
        panel.contourplot(at=at, region=TRUE,  ...)
        panel.contourplot(at=c(-0.2, 0.2), lwd=2, region=FALSE, ...)
        mp <- map("world", "antarctica", plot = FALSE, fill=TRUE)
        lpolygon(mp$x, mp$y, fill=TRUE, col='gray')
    })
    
    Run Code Online (Sandbox Code Playgroud)

示例输出