[R] graphs with gradients of colors

Jim Lemon jim at bitwrit.com.au
Tue Sep 18 11:26:11 CEST 2007


Van Dongen Stefan wrote:
> Hi All,
>  
> I would like to fill the area under a curve with a gradient of colors. Are there any packages or trick I could use
>  
> 
Hi Stefan,

Chris has answered the question of how to define the polygons, so I'll 
have a shot at the gradient. The plotrix package has three functions 
that produce color gradients, smoothColors, color.gradient and color.scale.

smoothColors allows you to specify the extreme, and optionally 
intervening, colors and interpolates colors between the ones you have 
specified.

color.gradient is quite similar, except that the user can specify the 
red, green and blue components separately.

color.scale turns numeric values into colors using the same method of 
color specification as color.gradient. It will also work with just the 
extreme colors.

The RColorBrewer package also has the capability to produce color 
gradients. There may be other packages that will do what you want as well.

Jim



More information about the R-help mailing list