[R] Continuous legend colors

Jim Lemon jim at bitwrit.com.au
Mon Nov 30 07:13:27 CET 2009


On 11/30/2009 03:22 PM, Tim Clark wrote:
> 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.
>
>    
Hi Tim,
Have a look at the "color.legend" function in the plotrix package.

Jim




More information about the R-help mailing list