[R] continuous coloring of a polygon
h.wickham at gmail.com
Fri Aug 15 21:13:52 CEST 2008
It rather sounds like you might be designing a gauge display for a
dashboard. If that's the case, I'd recommend checking out:
Information Dashboard Design: The Effective Visual Communication of Data
as well as some of his online writings:
On Fri, Aug 15, 2008 at 7:00 AM, Roger Leenders <r.t.a.j.leenders at rug.nl> wrote:
> R2.7.1, WinXP
> I have a polygon inside a circle as follows:
> radius <- 3
> x <- seq(-radius,radius,length=2000)
> y <- sqrt(radius^2-x^2)
> xx <- c(x,-x)
> yy <- c(y,-y)
> plot(xx,yy, xlim=c(-radius,radius),ylim=c(-radius,radius), type="l",
> ylab="", xlab="", axes=F)
> radius <- 2.7
> x1 <- seq(-radius,radius,length=2000)
> y1 <- sqrt(radius^2-x1^2)
> radius <- 2.0
> x2 <- seq(radius,-radius,length=2000)
> y2 <- sqrt(radius^2-x2^2)
> (the graph much resembles a speed dial inside a car).
> Now I want to fill the polygon with color, such that it starts on the left
> with red and ends on the right with green, following the coloring of the
> Preferably, the coloring should be "continuous", such that colors naturally
> fade into each other.
> I can draw the polygon as above, but I don't know how to do the coloring. It
> is easy to give the polygon only one color (e.g. through
> polygon(c(x1,x2),c(y1,y2), col="red")), but I need a way in which to color
> the polygon such that the color moves through the color spectrum from red
> (left) to green (right).
> Can anyone help me to achieve this?
> Thanks, Roger
> R-help at r-project.org mailing list
> 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