R - 等高线图
我已经绘制了等高线图,但我需要进行一些改进。这是所使用的数据的结构:
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,1),我不知道如何手动设置间隔。
有人可以告诉我如何绘制地图的特定区域,例如从 100 到 160 的经度和从 -50 到 -80 的纬度?我尝试替换
lon_sst
和lat_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)
Because most of the correlations are close to 0, it is very hard to see the big ones.
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.
Where can i see the increment, i set my range as (-1,1), i don't know how to set the interval manually.
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
andlat_sst
, but it has a dimension error. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答看似相同的请求的 1 和 3,请尝试:
要解决 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:
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.lattice
包中的contourplot
也可以生成这些类型的等高线图,并且可以轻松绘制等高线和填充颜色。这可能适合也可能不适合您的需求,但通过填充轮廓间隔,您可以取消文本标签,如果您想要高分辨率轮廓,文本标签可能会有点拥挤。我没有您的海面温度数据,因此下图使用虚拟数据,但您应该得到类似的数据。请参阅
?contourplot
和?panel.levelplot
了解可能的参数。对于您想要的小比例图,覆盖世界地图图可能不合适,特别是考虑到感兴趣的区域位于海洋中。
此处,
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 thelattice
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.
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 toat=seq(-1, 1, 0.5)
, for example, would produce contour lines at -0.5, 0, 0.5, and 1.