[R] Help with plotting a line that is multicoloured based on levels of a factor

Peter Ehlers ehlers at ucalgary.ca
Tue Mar 29 03:57:28 CEST 2011


On 2011-03-28 09:33, Pam Allen wrote:
> Thank you Jim and David for your help.
>
> The 'levels' call is not a misdirection, in my actual dataset it is
> necessary because the flows aren't symmetrical.   So while your solution is
> quite elegant David, it doesn't apply to my actual data, just the example.
> Too bad, it's quite nice!
>
> I do think that "color.scale.lines" can work, now I just need to figure out
> how!  Unfortunately when I tried your example Jim:
>
> date=c(1:300)
> flow=sin(2*pi/53*c(1:300))
> levels=c(rep(c("high","med","low"),100))
> data=cbind.data.frame(date, flow, levels)
> plot(data$date,data$flow,type="n")
> library(plotrix)
> color.scale.lines(data$date,data$flow,
>    col=color.scale(data$flow,extremes=c("blue","red")))
>
> I got this error:
> "Error in length(redrange) : 'redrange' is missing"

The code works just fine for me with plotrix_3.0-7.
It would help if you provided your sessionInfo().

Peter Ehlers

>
> But I do think the function is the way to go for my dataset.
>
> Thank you!
>
> -Pam
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Help-with-plotting-a-line-that-is-multicoloured-based-on-levels-of-a-factor-tp3385857p3412310.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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