[R] Plotting colors on a world map

Duncan Murdoch murdoch at stats.uwo.ca
Mon May 11 18:46:47 CEST 2009


On 5/11/2009 10:32 AM, dxc13 wrote:
> Hi useR's
> 
> I have created a simple map of the world using the following code:
> m <- map(xlim=c(-180,180), ylim=c(-90,90))
> map.axes()
> 
> I then create a grid of dimension 36x72 using the code:
> map.grid(m, nx=72, ny=36, labels=FALSE, col="black")
> 
> This gives 2592 grid cells.  In a separate data set of dimension 36x72, I
> have 2592 temperature values (some missing values are present) ranging from
> -20 degrees F to 90 degrees F.  
> 
> My question is, how can I create a reasonable color scheme (low temperatures
> in light blue to higher temperatures in dark red) and plot the temperature
> colors in their respective grid cells on the map?
> 
> Take this data matrix as some example data:
> T <- sample(-10:90, 2592, replace=TRUE)
> mat <- matrix(T, nrow=36, ncol=72)


The colorspace package can make nice color sequences for this sort of 
thing, and image() can add them to a plot.  In colorspace, look at the 
examples for diverge_hcl.

Duncan Murdoch




More information about the R-help mailing list