The first question you should ask is "why do you want to do this?".
Adding gradients and other things like that can make a graph look neat,
but can also distort the information in the graph. You should carefully
consider whether doing things like this really help the graph, or
distract from it.
I
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
You could use a loop and fill small polygons with colors.
x<-seq(-3, 3, .01)
y<-eval(expression(x^3-3*x))
plot(x,y, type="n", las=1)
n<-length(x)
# vertical bars
for(i in 1:n)
{
polygon(c(x[i], x[i], x[i+1], x[i+1]), c(min(y), y[i], y[i+1], min(y)),
border=0, col = rainbow(n)[i])
}
## or sp
Maybe this information (from the R's father) can be of some help.
http://www.stat.auckland.ac.nz/~ihaka/Graphics/index.html
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
>
> Thank
4 matches
Mail list logo