[R] Change the color of the line inside of the function lines

Pascal Oettli kridox at ymail.com
Mon Sep 16 09:42:57 CEST 2013


Hi,

Maybe the following might help you:

 > s <- seq(length(xx)-1)
 > plot(xx, yy, type="n")
 > segments(xx[s], yy[s], xx[s+1], yy[s], col=zz, lwd=2)
 > segments(xx[s+1], yy[s], xx[s+1], yy[s+1], col='grey')

Regards,
Pascal


On 16/09/2013 15:42, Arnaud Michel wrote:
> Hi
>
> I have the following problem :
> I have 3 vectors xx, yy, zz :
> xx <-  c(5479,  6209,  6940,  7670,  8766,  9496, 10227, 11048, 11778,
> 12509, 13239, 13970,
> 14700, 15340, 15948)
> yy <- c( 267, 275, 281, 287, 296, 306, 316, 325, 334, 351, 365, 377,
> 389, 419, 419)
> zz <- c( 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6)
> I would like a line wich join the points (xx, yy) with stair steps (as
> type = "s")
> plot(xx, yy, type="n")
> lines(xx, yy, type ="s")
> but I want to change the color according to the value of zz (exemple :
> col = 1 if zz =3 ; col =2 if zz= 4 ;  col =3 if zz= 5 ;  col =4 if zz= 6)
> Thank you for your help
>

-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan



More information about the R-help mailing list