R - Contour map

牧云@^-^@ 提交于 2019-12-19 09:07:19

问题


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.

  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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9172247/r-contour-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!