[R] Legend with fill = gray ?

Greg Snow Greg.Snow at imail.org
Wed Sep 1 22:35:26 CEST 2010


The phrase "does not work" can mean many things, it would help us to help you if you spelled out what you expected and how what you saw differs from what was expected.

I suspect part of your problem may be in using 0.1:0.3, did you try typing just that at the command line to see the result?  The ':' operator increments by 1 up until the largest values less than or equal to the right side, in this case it returns the single value 0.1.

Barplot uses the gray.colors function when you don't specify the colors, perhaps using that will work for you.  Or you could always pass specific shades of grey like you pass specific colors, then you don't need to guess or search.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Jens Oldeland
> Sent: Wednesday, September 01, 2010 2:17 PM
> To: r-help at r-project.org
> Subject: [R] Legend with fill = gray ?
> 
> Hi,
> 
> I am facing a problem with the legend, I don´t know how to use the fill
> option in the legend in order to achieve the same standard gray levels
> that are plotted.
> 
> Sorry for this easy one, but I really did not find anything so far.
> 
> It works fine with color:
> 
> ###### C O L O R
> mat <- matrix(2,3,rep(2,6))
> rownames(mat)<-c("A","B","C")
> par(xpd=T, mar=par()$mar+c(2,0,0,0))
> barplot(mat,col=rainbow(3))
> legend(1,-2,legend=rownames(mat),fill=rainbow(3))
> 
> however
> 
> ### G R A Y  ??
> 
> par(xpd=T, mar=par()$mar+c(2,0,0,0))
> barplot(mat)  # now without color
> legend(1,-2,legend=rownames(mat),fill=gray(0.1:0.3)) # this gray does
> not work
> 
> could anyone help me out, please?
> Thank you!
> 
> Jens
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list