I am new to R and I have the following queries:
I am trying to create a graph in R that has several rows (data series). Each of these lines is a category, and I want it to have a unique color.
My code is currently configured in this way:
First, I create an empty plot:
plot(1,type='n',xlim=c(1,10),ylim=c(0,max_y),xlab='ID', ylab='Frequency')
Then, for each of my category, I draw lines on this empty section using the "for" loop, for example:
for (category in categories){ lines(data.frame.for.this.category, type='o', col=sample(rainbow(10)), lwd=2) }
There are 8 categories, and therefore 8 lines are produced on the chart. As you can see, I am trying to select a color from the rainbows () function to generate a color for each row.
However, when the graph is generated, I find that there are several lines that have the same color. For example, 3 of these 8 lines are green.
How to make each of these 8 lines unique?
In addition, how can I reflect this uniqueness in the story legend? I tried to find the legend() function, however it is not clear which parameter should I use to reflect this unique color for each category?
Any help or suggestions would be greatly appreciated.
colors r plot unique lines
user1418321 Feb 13 '13 at 18:07 2013-02-13 18:07
source share