[R] Continuous legend colors

Tim Clark mudiver1200 at yahoo.com
Mon Nov 30 05:22:57 CET 2009


Dear List,

I am trying to get a basic plot to show a continuous range of fill colors.  It is probably easiest to demonstrate.  I would like a legend like in the following example:

Satellite.Palette <-colorRampPalette(c("blue3","cyan","aquamarine","yellow","orange","red"))
require(fields)
image.plot(volcano, col = Satellite.Palette (500), legend.lab="Scale")
contour(volcano, levels = seq(90, 200, by = 5), add = TRUE)


However, I am using the basic plot function.  So far I have figured out how to remove any space between the colors using the y.intersp call in legend().  Now I need to somehow plot the legend so that it 1) fits on the plotting region, 2) has fewer labels, and 3) doesn't have black lines between each color.  The example I am trying to get to work is:

Sat.Pal<-Satellite.Palette (101)
x<-rnorm(100, mean = 50, sd = 50)
y<-rnorm(100, mean = 50, sd = 50)
z<-seq(1,100, by=1)
plot(x,y,pch=16,col=Sat.Pal[z])

legend("topleft",
legend=seq(0,100, by=1),
fill=Sat.Pal[seq(1,101, by=1)],
bty="n",
y.intersp=.5)


I would appreciate any help or suggestions on how to get this to produce a legend with "continuous" colors.

Thanks,

Tim





Tim Clark
Department of Zoology 
University of Hawaii




More information about the R-help mailing list