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 -- View this message in context: http://www.nabble.com/Plotting-colors-on-a-world-map-tp23484524p23484524.html Sent from the R help mailing list archive at Nabble.com.
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
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