[R] Giving vector of colors to line in plots

Peter Ehlers ehlers at ucalgary.ca
Mon Feb 7 09:39:46 CET 2011


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.



More information about the R-help mailing list