[R] fill circles

Jim Lemon jim at bitwrit.com.au
Sun Aug 26 13:31:58 CEST 2007

Cristian cristian wrote:
> Hi all,
> I'm an R newbie,
> I did this script to create a scatterplot using the "tree" matrix from
> "datasets" package:
> library('datasets')
> with(trees,
> {
> plot(Height, Volume, pch=3, xlab="Height", ylab="Volume")
> symbols(Height, Volume, circles=Girth/12, fg="grey", inches=FALSE,
> add=FALSE)
> }
> )
> I'd like to use the column Named "Height" to fill the circles with colors
> (ex.: the small numbers in green then yellow and the high numbers in red).
> I'd like to have a legend for the size and the colors too.
> I did it manually using a script like that:
> color[(x>=0.001)&(x<0.002)]<-"#41FF41"
> color[(x>=0.002)&(x<0.003)]<-"#2BFF2B"
> color[(x>=0.003)&(x<0.004)]<-"#09FF09"
> color[(x>=0.004)&(x<0.005)]<-"#00FE00"
> color[(x>=0.005)&(x<0.006)]<-"#00F700"
> color[(x>=0.006)&(x<0.007)]<-"#00E400"
> color[(x>=0.007)&(x<0.008)]<-"#00D600"
> color[(x>=0.008)&(x<0.009)]<-"#00C300" and so on but I don't like to do it
> manually... do know a solution...
> Thank you very much
> chris
Hi Chris,
You can transform the numeric values in "Height" into colors using the 
color.scale function in the plotrix package. The color.legend function 
will allow you to get your legend.


More information about the R-help mailing list