Hey all, I can't for the life of me figure out what I'm missing here. I'm trying to change the color of the line in a time series type plot. I can change the point colors and symbols no problem, but for some reason the colors do not get passed to the lines, regardless of if I do type="b" or type="l". The sample code I'm using is below. Any help would be greatly appreciated. Also, please CC me, as I only get daily summaries of the mailing list. Thanks, Brian ## Changing plot attributes through the plot set.seed(33) x <- rpois(7,lambda=7) y <- rpois(7,lambda=5) cols.x <- c(rep("black",2),rep("red",3),rep("black",2)) cols.y <- c(rep("blue",3),rep("yellow",2),rep("blue",2)) points.x <- c(rep("x",2),rep("O",3),rep("x",2)) points.y <- c(rep(8,3),rep(17,2),rep(8,2)) plot(x,col=cols.x,pch=points.x,type="b",ylim=c(0,15)) points(y,col=cols.y,pch=points.y,type="b")
On 2011-02-06 22:15, statmobile wrote:> Hey all, > > I can't for the life of me figure out what I'm missing here. I'm trying > to change the color of the line in a time series type plot. I can > change the point colors and symbols no problem, but for some reason the > colors do not get passed to the lines, regardless of if I do type="b" or > type="l". The sample code I'm using is below.Because lines are not segments. For what you want to do, you'll have to use the segments() function. Perhaps there's something in the plotrix package. Peter Ehlers> > Any help would be greatly appreciated. > > Also, please CC me, as I only get daily summaries of the mailing list. > > Thanks, > Brian > > > > ## Changing plot attributes through the plot > set.seed(33) > x<- rpois(7,lambda=7) > y<- rpois(7,lambda=5) > > cols.x<- c(rep("black",2),rep("red",3),rep("black",2)) > cols.y<- c(rep("blue",3),rep("yellow",2),rep("blue",2)) > > points.x<- c(rep("x",2),rep("O",3),rep("x",2)) > points.y<- c(rep(8,3),rep(17,2),rep(8,2)) > > plot(x,col=cols.x,pch=points.x,type="b",ylim=c(0,15)) > points(y,col=cols.y,pch=points.y,type="b") > > ______________________________________________ > 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.
On 02/07/2011 05:15 PM, statmobile wrote:> Hey all, > > I can't for the life of me figure out what I'm missing here. I'm trying > to change the color of the line in a time series type plot. I can change > the point colors and symbols no problem, but for some reason the colors > do not get passed to the lines, regardless of if I do type="b" or > type="l". The sample code I'm using is below. >Hi Brian, Have a look at the color.scale.lines function (plotrix). This may allow you to do what you want. Jim
On 02/07/2011 02:15 AM, Jinsong Zhao wrote:> On 2011-2-7 14:15, statmobile wrote: >> set.seed(33) >> x <- rpois(7,lambda=7) >> y <- rpois(7,lambda=5) >> >> cols.x <- c(rep("black",2),rep("red",3),rep("black",2)) >> cols.y <- c(rep("blue",3),rep("yellow",2),rep("blue",2)) >> >> points.x <- c(rep("x",2),rep("O",3),rep("x",2)) >> points.y <- c(rep(8,3),rep(17,2),rep(8,2)) >> >> plot(x,col=cols.x,pch=points.x,type="b",ylim=c(0,15)) >> points(y,col=cols.y,pch=points.y,type="b") > > the following code may give hints... > > segments(1:6,x[-7],2:7,x[-1], col = cols.x) > segments(1:6,y[-7],2:7,y[-1], col = cols.y) > > regards, > JinsongThanks Jinsong, this works like a charm. I'll need to dive deeper into the segments function.