[R] adding color bar to a graph

Jim Lemon jim at bitwrit.com.au
Fri Aug 7 13:11:46 CEST 2009

Monica Pisica wrote:
> Hi everybody,
> I am wondering how i can add a "stretch" color bar / legend to a graph that uses colorBrewer to define the colors in it. I will try to explain my graph, but i also uploaded it at: ftp://ftpext.usgs.gov/pub/er/fl/st.petersburg/Monica_pal/
> The file is: robcor_training_pca.pdf - i will also attach this file in case some people accept attachments.
> So i took apart the cor.plot function from mvoutlier and i used instead of the scatter plot function the smooth scatter density plot from geneplotter, generating my own function called cordens.plot. Now i would like to add a colorbar on the right side of the graph with red as my highest density and purple as the lowest density and right next to the colors labels "min" for purple and "max" for red (i don't want actual numbers, although i suppose i can deal with that as well if need be). 
> I've tried image.plot function but i cannot set correctly the colors in the bar since i am not using an "orthodox" rainbow set. Originally my colors in the graph are set with colorRampPalette(c("darkviolet", "deepskyblue4", "green", "yellow", "red")).
Hi Monica,
I think color.legend in the plotrix package will do what you want.


and you will have to add some space on the right side



More information about the R-help mailing list