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

2011-03-28 Thread Peter Ehlers
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.

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

2011-03-28 Thread Pam Allen
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

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

2011-03-25 Thread Jim Lemon
On 03/26/2011 07:19 AM, Pam Allen wrote: Hello again, I wrote an example that better represents my data, since the coloured points are actually consecutive, but with variable lengths: date=as.Date(c(1:300)) flow=sin(2*pi/53*c(1:300)) levels=c(rep(c("high","med","low"),100)) data=cbind.data.fram

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

2011-03-25 Thread Pam Allen
Hello again, I wrote an example that better represents my data, since the coloured points are actually consecutive, but with variable lengths: date=as.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) library(zoo) z <- z

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

2011-03-25 Thread David Winsemius
On Mar 25, 2011, at 3:23 PM, Pam Allen wrote: Hello Baptiste and others, I tried your example with my dataset, and for a few days I thought it worked for me. But I realized yesterday that the result wasn't quite what I hoped for. In my actual data the flows aren't perfectly sinusoidal, a

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

2011-03-25 Thread Pam Allen
Hello Baptiste and others, I tried your example with my dataset, and for a few days I thought it worked for me. But I realized yesterday that the result wasn't quite what I hoped for. In my actual data the flows aren't perfectly sinusoidal, and I used a series of ifelse queries to code the flow

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

2011-03-17 Thread David Winsemius
On Mar 17, 2011, at 6:33 PM, Pamela Allen wrote: Hi All, I'm trying to plot data that is a time series of flows that are associated with a specific level, and I would like each level to represent a colour in a line plot. Here is some data that approximates what I'm using: date=c(1:300)

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

2011-03-17 Thread Tóth Dénes
Indeed, I forgot about the segments function. with(d,plot(date,flow,type="n")) with(d,segments(start,start.y,end,end.y,col=colour)) > Hi, > > because each colour is defined on non-consecutive points, you'll > probably need to cut the intervals to define segments around each > point. One approa

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

2011-03-17 Thread baptiste auguie
Hi, because each colour is defined on non-consecutive points, you'll probably need to cut the intervals to define segments around each point. One approach might be the following, d = transform(data, start = date - c(0, diff(date)/2), end = date + c(0, diff(date)/2) ) d$start.y = approx(d$date, d

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

2011-03-17 Thread Tóth Dénes
Hi! Not an elegant solution, but seems to work: date <- c(1:300) flow <- sin(2*pi/53*c(1:300)) levels <- factor(rep(c("high","med","low"),100)) data <- cbind.data.frame(date, flow, levels) colours <- as.numeric(levels)+1 # interpolate resolution <- 0.001 appres <- approx(date,flow,seq(min(date

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

2011-03-17 Thread Pamela Allen
Hi All, I'm trying to plot data that is a time series of flows that are associated with a specific level, and I would like each level to represent a colour in a line plot. Here is some data that approximates what I'm using: date=c(1:300) flow=sin(2*pi/53*c(1:300)) levels=c(rep(c("