[R] Plotting colors on a world map
Jim Lemon
jim at bitwrit.com.au
Tue May 12 12:22:11 CEST 2009
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)
>
>
> Thanks in advance,
> dxc13
>
Howdy dxc13,
Try this:
library(plotrix)
tempcolor<-color.scale(mat,c(0.5,1),c(0.5,0),c(1,0))
Jim
More information about the R-help
mailing list