4

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.

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
Yu Deng
  • 1,051
  • 4
  • 18
  • 35
  • (1) you can try increasing font size, or using a bold typeface with `contour()` arguments, e.g. `labcex=1, vfont=c('sans serif', 'bold')`; (2) use `levels` in `contour()`, e.g. `levels=seq(-1, 1, 0.25)` ; (3) You can use xlim and ylim in `map()`. – jbaums Feb 07 '12 at 09:53

2 Answers2

3

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.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
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.

example using contourplot with dummy data

jbaums
  • 27,115
  • 5
  • 79
  • 119
  • This function is great, but the problem i can't find the argument to set the land as colour filled, if i plot with a big range. In my original one, i can set it as "maps::map(database="world", fill=TRUE, col="light blue")", can i do the same thing here? – Yu Deng Feb 08 '12 at 01:31