[R] How to plot with different colours
Carl Witthoft
carl at witthoft.com
Sun Nov 2 17:03:42 CET 2008
Carlos Morales wrote:
> Hello everyone,
>
> I'm trying to plot 3600 points and my idea is if this value is higher
than 0.35 then this point must appear in green colour, if it's smaller
than -0.35 then values must appear in red and if values are between
-0.35 and 0.35 they must be in yellow. I'm thinking and I'm trying many
things but I don't achieve it. Any idea?.
Hi Carlos,
This may be what you want:
zeep<-rnorm(20)
zeepcut<-as.numeric(cut(zeep,c(-4,-0.35,0.35,4)))
plot(zeepcut,col=c("red","yellow","green")[zeepcut])
Jim
------
At the risk of promoting my own code :-), if you want to plot lines
with this sort of value-dependent color instead of points (or in
addition), the function clplot() in the Plotrix package will do it for you.
Carl
More information about the R-help
mailing list