I am working with a generic plot fxn that does not know how many lines it will plot until it's completed plotting. The data is plotting just fine, though when I try to create the legend, I'm not getting the colors.
Since the number of lines is unknown I am generating colors for the lines at random; BUT, I am storing the color in a array/vector.
From my code: I understand this is not easily reproduced, but it is not easily dumbed down, as I've gotten to the point of dumbed down and not able to find the problem...
# plot blank plot
plot(1, type="n", xlab="time elapsed [sec]", ylab="Memory Used [MB]", ylim=c(ymin,ymax),   
  xlim=c(xmin,xmax))
 # LOOOOP over column 2 (node)
for(i in 1: length(col2))
{
  if(col2[i] == compareNode)
  {
    #print(paste0("count: ", count))
    # x = time value, y = memory used value for node: compareNode
    x[count] = col1[i]
    y[count] = (col87[i] - col85[i])/1024
    count = count + 1
  }
  else
  {
    # Plot 
    colTest <- sample(colors(), 1)
    mycols <- c(mycols,colTest)
    lines(x, y, col=colTest )
    NODES[nodeCount] = col2[i]
    nodeCount = nodeCount + 1
    # Resets
    compareNode = col2[i]
    x = c()
    y = c()
    count = 1
  }
}
# Plot final line
colTest <- sample(colors(),1)
mycols <- c(mycols,colTest)
lines(x, y, col=colTest)
#print(colors)
legend("topleft", title="LDMS: Memory Used", legend = NODES, col=mycols )
garbage <- dev.off()
Trying for a better example here:
loop x times:
  color <- sample(colors(),1)
  mycols <- c(mycosl,color)
  lines(x,y,col=color)
done
lines(x,y,col=color)   # plots last set of data
legend("topright", title="title", legend=NODES, col=mycols)
 
    