R - 等高线图

发布于 2025-01-03 07:59:42 字数 1094 浏览 1 评论 0原文

我已经绘制了等高线图,但我需要进行一些改进。这是所使用的数据的结构:

str(lon_sst)
# num [1:360(1d)] -179.5 -178.5 -177.5 -176.5 -175.5 ...

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 ...

dim(cor_Houlgrave_SF_SST_JJA_try)
# [1] 360 180

require(maps)
maps::map(database="world", fill=TRUE, col="light blue")
maps::map.axes()
contour(x=lon_sst, y=lat_sst, z=cor_Houlgrave_SF_SST_JJA_try[c(181:360, 1:180),],
        zlim=c(-1,1), add=TRUE)
par(ask=TRUE)
filled.contour(x = lon_sst, y=lat_sst,
               z=cor_Houlgrave_SF_SST_JJA_try[c(181:360, 1:180),],
               zlim=c(-1,1), color.palette=heat.colors)

在此处输入图像描述 在此处输入图像描述

由于大多数相关性接近于 0,因此很难看到大的相关性。

  1. 我可以让它更容易看到吗,或者我可以更改分辨率以便将其放大吗?目前,轮廓间隔太紧密,因此我看不到轮廓级别。

  2. 在哪里可以看到增量,我将范围设置为(-1,1),我不知道如何手动设置间隔。

  3. 有人可以告诉我如何绘制地图的特定区域,例如从 100 到 160 的经度和从 -50 到 -80 的纬度?我尝试替换 lon_sstlat_sst,但出现尺寸错误。谢谢。

I have plotted a contour map but i need to make some improvements. This is the structure of the data that are used:

str(lon_sst)
# num [1:360(1d)] -179.5 -178.5 -177.5 -176.5 -175.5 ...

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 ...

dim(cor_Houlgrave_SF_SST_JJA_try)
# [1] 360 180

require(maps)
maps::map(database="world", fill=TRUE, col="light blue")
maps::map.axes()
contour(x=lon_sst, y=lat_sst, z=cor_Houlgrave_SF_SST_JJA_try[c(181:360, 1:180),],
        zlim=c(-1,1), add=TRUE)
par(ask=TRUE)
filled.contour(x = lon_sst, y=lat_sst,
               z=cor_Houlgrave_SF_SST_JJA_try[c(181:360, 1:180),],
               zlim=c(-1,1), color.palette=heat.colors)

enter image description here
enter image description here

Because most of the correlations are close to 0, it is very hard to see the big ones.

  1. Can i make it easier to see, or can i change the resolution so i can zoom it in? At the moment the contours are too tightly spaced so I can't see what the contour levels were.

  2. Where can i see the increment, i set my range as (-1,1), i don't know how to set the interval manually.

  3. Can someone tell me how to plot a specific region of the map, like longitude from 100 to 160 and latitude from -50 to -80? I have tried to replace lon_sst and lat_sst, but it has a dimension error. Thanks.

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

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

发布评论

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

评论(2

叹梦 2025-01-10 07:59:42

要回答看似相同的请求的 1 和 3,请尝试:

maps::map(database="world", fill=TRUE, col="light blue", 
                            ylim=c(-80, -50), xlim=c(100,160) )

要解决 2:您的范围比 [-1,1] 小得多。这些轮廓线上的标签是诸如 0.06、-.02 和 0.02 之类的数字。 contour 函数将接受“nlevels”或“levels”参数。一旦你有了放大的部分,你就可以用它来调整轮廓的 z 分辨率。

To answer 1 and 3 which appear to be the same request, try:

maps::map(database="world", fill=TRUE, col="light blue", 
                            ylim=c(-80, -50), xlim=c(100,160) )

To address 2: You have a much smaller range than [-1,1]. The labels on those contour lines are numbers like .06, -.02 and .02. The contour function will accept either an 'nlevels' or a 'levels' argument. Once you have a blown up section you can use that to adjust the z-resolution of contours.

画中仙 2025-01-10 07:59:42

lattice 包中的 contourplot 也可以生成这些类型的等高线图,并且可以轻松绘制等高线和填充颜色。这可能适合也可能不适合您的需求,但通过填充轮廓间隔,您可以取消文本标签,如果您想要高分辨率轮廓,文本标签可能会有点拥挤。

我没有您的海面温度数据,因此下图使用虚拟数据,但您应该得到类似的数据。请参阅 ?contourplot?panel.levelplot 了解可能的参数。

对于您想要的小比例图,覆盖世界地图图可能不合适,特别是考虑到感兴趣的区域位于海洋中。

library(lattice)
contourplot(cor_Houlgrave_SF_SST_JJA_try, region=TRUE, at=seq(-1, 1, 0.25), 
  labels=FALSE, row.values=lon_sst, column.values=lat_sst,
  xlim=c(100, 160), ylim=c(-80, -50), xlab='longitude', ylab='latitude')

此处,at 参数控制计算和绘制等高线的值的位置(从而控制色带中的中断数量)。在我的示例中,轮廓线设置为 -0.75、-0.5、-0.25、0、0.25、0.5、0.75 和 1(-1 为背景)。例如,更改为 at=seq(-1, 1, 0.5) 将在 -0.5、0、0.5 和 1 处生成等高线

。 sstatic.net/X4kQe.png" alt="使用带有虚拟数据的轮廓图的示例">

contourplot in the lattice package can also produce these types of contour plots, and makes it easy to both contour lines and fill colours. This may or may not suit your needs, but by filling contour intervals, you can do away with the text labels, which can get a little crowded if you want to have high resolution contours.

I don't have your sea surface temperature data, so the following figure uses dummy data, but you should get something similar. See ?contourplot and ?panel.levelplot for possible arguments.

For your desired small scale plot, overlaying the world map plot is probably inappropriate, especially considering that the area of interest is in the ocean.

library(lattice)
contourplot(cor_Houlgrave_SF_SST_JJA_try, region=TRUE, at=seq(-1, 1, 0.25), 
  labels=FALSE, row.values=lon_sst, column.values=lat_sst,
  xlim=c(100, 160), ylim=c(-80, -50), xlab='longitude', ylab='latitude')

Here, the at argument controls the position at values at which contour lines will be calculated and plotted (and hence the number of breaks in the colour ramp). In my example, contour lines are provided at -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75 and 1 (with -1 being the background). Changing to at=seq(-1, 1, 0.5), for example, would produce contour lines at -0.5, 0, 0.5, and 1.

example using contourplot with dummy data

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