[R] Help with coloring segments on a plot
Jim Lemon
jim at bitwrit.com.au
Tue May 3 11:02:27 CEST 2011
On 05/03/2011 04:26 AM, Paul Davison wrote:
> Hi. I need a very short piece of help regarding colouring segments plotted
> on a graph.
>
> When I am plotting segments for the graph, I am using "red" and "darkgreen
> for the values "1" and "2" respectively. Heres the relevant line of code in
> R:
>
Hi Paul,
Try this simple bit of code and see if it contains the elements you need
to solve the problem.
# grab a bunch of easily distinguishable colors
linecolors<-col2rgb(c(1:6,"#8888dd","brown","orange","pink"))
# make an empty plot
plot(0:10,type="n")
# plot segments with the colors
segments(1:10,0:9,2:11,1:10,col=linecolors)
# stick some points on to better see the colors
points(1:10,0:9,pch=19,col=linecolors)
Jim
More information about the R-help
mailing list