[R] How to plot with different colours
Bernardo Rangel Tura
tura at centroin.com.br
Sun Nov 2 10:51:22 CET 2008
On Sun, 2008-11-02 at 07:58 +0000, 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?.
>
> Thanks so much
> Carlos Morales Diego
Hi Carlos
I think you need use a nested ifelse, something similar this
x<-runif(6000,-1,1)
color<-ifelse(x>.35,"green",ifelse(x< -.35,"red","yellow"))
table(col)
plot(1:6000,x,col=color)
--
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil
More information about the R-help
mailing list