[R] Complex plotting problem
Greg Snow
Greg.Snow at intermountainmail.org
Tue Nov 7 18:01:29 CET 2006
Others have given some fairly basic solutions, but if you want the lines
to change color along their length instead of each segment being a
constant color, then there are a couple of other options.
One is to create the plot using a solid color, then use image
manipulation software like imagemagick or gimp to replace the solid
color with a gradient.
Another option is to use the clipplot function in the most recent
version of the TeachingDemos Package (just updated on CRAN).
An example would be:
> library(TeachingDemos)
> x <- sort(runif(100))
> y <- rnorm(100)
> plot(x,y,type='b')
>
> tmp <- seq(par('usr')[3],par('usr')[4], length=11)
> tmp2 <- topo.colors(10) # replace with your color gradient
> for(i in 1:10) {
+ clipplot( points(x,y,type='b', col=tmp2[i]), ylim= tmp[ c(i,i+1)
] )
+ }
>
Hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Wee-Jin Goh
Sent: Thursday, November 02, 2006 1:55 AM
To: r-help at stat.math.ethz.ch
Subject: [R] Complex plotting problem
Hello,
I would like to make a plot (preferably lines, but points will do too),
where the line segment changes color depending on the value of the
y-axis. For example, let's suppose the y-axis range is from -1 to 1.
Points close to -1 would be colored blue, while points close to 1 will
be colored red. Points in between will be varying degrees of blue/red
depending on how close they are to -1 or +1.
If the above is not possible, would it be possible to set a decision
boundary on the plot, where any point above this boundary will be a
particular color, and any point below will be a different color?
Any suggestions as to how I might accomplish this would be much
appreciated.
Regards,
Wee-Jin
p.s. The data set I'm talking about has about 20,000 points.
______________________________________________
R-help at 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.
More information about the R-help
mailing list