[R] greyPalette() in legend plot

Rosario Garcia Gil M.Rosario.Garcia at slu.se
Wed Sep 7 10:33:27 CEST 2011


I have a barplot where I get a grey gradient colors for each bar, I want to append a legend with the names of each bar and next to each name I need a box with the corresponding grey color.

I managed to get the legend without boxes, but never got the wanted grey gradient in the legend:

> y <- matrix(c(46.5102,42.7561,45.7857,45.6047,45.7027,81.4565,69.8824,69.1333,67.56,57.8929,43.3019,42.9184,51.7143,40.2727,51.7692,22.3871,24.2222,24.3226,23.6342,21.5833), ncol=4)

se <- matrix(c(13.0707,12.0287,15.3949,16.5344,10.2520,28.6169,31.2398,24.5816,25.9745,22.9981,13.8433,17.3071,21.7355,18.2007,26.2546,6.8199,7.2977,7.1245,7.2345,8.2616), ncol=4)

> plot<-barplot(y, beside=TRUE, ylim=c(0,90), axis.lty=0.5,xlab="Light treatment", ylab="root length (mm)", main="Root", names.arg=c("White","Blue","Red","Far-red"))

> segments(plot,y-se,plot,y+se)

> legend("topleft", c("Sedingehult", "Mobranna", "Aunasvare", "Fallan", "Ylinen"), col=(greyPalette(n=5)))

Kind regards

More information about the R-help mailing list