Re: [R] is it possible to fill with a color or transparency gradient?

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Sun 08 Oct 2006 - 23:51:18 GMT

Eric Harley wrote:
> Hi all,
>
> Is there a way to fill a rectangle or polygon with a color and/or
> transparency gradient? This would be extremely useful for me in terms
> of adding some additional information to some plots I'm making,
> especially if I could define the gradient on my own by putting
> functions into rgb something like rgb( r=f(x,y), g=f(x,y), b=f(x,y),
> alpha=f(x,y) ). Not so important whether the coordinates are in terms
> of the plot axes or normalized to the polygon itself somehow. Ideally
> it would work not only for a fill color but also for shading lines.
>
> I haven't been using R very long, so it's possible that I'm just
> missing something, but I haven't found anything like this in the help
> files. I've tried to poke around in graphics, grid, and ggplot,
> without any luck so far. I really like some of the functionality in
> ggplot, and it does some nice things with continuous gradients for the
> color of scatter plot points, for example, but it each individual
> point (or grob) is always one solid color as far as I can tell.
>
Hi Eric,

You can fill a rectangle with a "gradient" (slices of colors) using gradient.rect in the plotrix package. Filling an arbitrary polygon would be a lot harder to program. You may also be interested in the color.scale function that assigns colors to numerical values.

Jim



R-help@stat.math.ethz.ch 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. Received on Sun Oct 08 19:55:55 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 08 Oct 2006 - 10:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.