R - 具有多层(格子)的等高线图

发布于 2025-01-04 00:35:42 字数 1238 浏览 0 评论 0原文

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

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

在此处输入图像描述

我尝试使用 layer() 显示标签以使轮廓更大大于0.6,但不起作用。

  1. 是否可以增加图例中的颜色对比度,以便可以真正清楚什么颜色对应什么级别。什么是颜色选项,我找不到它们?

  2. 最重要的是我想在指定的轮廓间隔(例如+/- 0.2)内绘制一条较粗的黑线?我想我也可以用layer()来做,但我不确定我应该使用什么panel函数。

  3. 另外,我尝试用纯色填充大陆,但我找不到任何东西。 我尝试过使用地图,但它不适用于晶格。

感谢您的帮助。

Here is my code and associated variable structures.

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

enter image description here

I tried to use layer() to show the label just for contour bigger than 0.6, but it doesn't work.

  1. Is it possible to increase the colour contrasts in the legend so it can be really clear what colour responds to what level. What are colour options, i can't find them?

  2. The most important is I want to draw a thicker black line for a specified contour interval (e.g. for +/- 0.2)? I think ican do it with layer() as well, but i am not sure what panel function should i use.

  3. Also, i tried to fill in the continent with a solid colour, but i can't find any thing with it.
    I have tried use map, but it doesn't work for lattice.

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自此以后,行同陌路 2025-01-11 00:35:42

查看 ?panel.levelplot 以了解 contourplot 的其他参数。

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

  2. 使用自定义面板函数,如下所示(使用使用 Santiago Beguería 的博客)。使用lpolygon绘制地图对象:

    生成虚拟数据集:

    <前><代码>库(gstat)

    # 创建结构
    xy <- 展开.grid(1:360, 1:180)
    名称(xy) <- c('x','y')

    # 定义 gstat 对象(空间模型)
    g.dummy <- gstat(公式=z~1, 位置=~x+y, dummy=T, beta=1,
    模型=vgm(psill=0.025,模型='Exp',范围=5),nmax=20)

    # 基于 gstat 对象进行模拟
    yy <- 预测(g.dummy, newdata=xy, nsim=1)
    网格化(yy) = ~x+y

    # 缩放到范围 [-1, 1]
    z <- 矩阵(yy@data[, 1], ncol=180)
    z.scalefac <- (max(z) - min(z)) / 2
    z <- -1 + (z - min(z)) / z.scalefac

  3. 绘图:

    库(格子)
    图书馆(地图)
    
    lon_sst <- seq(-179.5, 179.5, 1)
    lat_sst <- seq(-89.5, 89.5, 1)
    
    colramp <- colorRampPalette(c('红色', '黄色', '白色', '绿色', '蓝色'))
    
    等高线图(z, xlim=c(100, 160), ylim=c(-80, -50), 
      at=seq(-1, 1, 0.2),区域=TRUE,col.regions=colramp,
      row.values=lon_sst,column.values=lat_sst,标签=FALSE, 
      xlab='经度', ylab='纬度',
      面板=函数(在,区域,...){
        panel.contourplot(at=at, 区域=TRUE, ...)
        panel.contourplot(at=c(-0.2, 0.2), lwd=2, 区域=FALSE, ...)
        mp <- 地图(“世界”,“南极洲”,情节= FALSE,填充= TRUE)
        lpolygon(mp$x, mp$y, fill=TRUE, col='gray')
    })
    

示例输出

Take a look at ?panel.levelplot for additional arguments to contourplot.

  1. You can use the col.regions argument, which will take either a vector of colours that you'd like to correspond to your intervals, or a color ramp function (e.g. below).

  2. Use a custom panel function, something like this (using a spatially autocorrelated dummy dataset generated using a method given on Santiago Beguería's blog). Use lpolygon to plot the map object:

    Generate dummy dataset:

    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
    
  3. Plot:

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

example output

空‖城人不在 2025-01-11 00:35:42

Q1:您需要使用 llinespanel.lines 以及上一个问题中用于大陆轮廓的相同数据来执行此操作

Q2:

?panel.contour

...其中它说“lwd”是一个可用选项,我怀疑您会使向量的第七个元素 = 2。

Q3:可能是一个填充参数,但必须指出的是,您严重阻碍了我们测试解决方案的努力包括数据和您的数据的链接 准备。

Q1: You will need to use llines or panel.lines with the same data you used for the continental outlines in the previous question to do that

Q2:

?panel.contour

.... Wherein it says that "lwd" is an available option and I suspect that you would make the seventh element of a vector = 2.

Q3: Probably a fill argument, but it must be noted that you are seriously inhibiting our efforts at testing solutions by not including a link to the data and your data preparation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文