Multiple curves when plotting a random forest I performed a random forest using the randomForest package. I know that if I plot the random forest using the plot() command, I should get back a graph with number of trees on the x-axis, and estimated error rate on the y-axis, but when I actually plot it, I get multiple curves, all of them start quite high, as expected and drop as the number of trees increase.  
Well, what do they mean? I assume they are just different measurements, e.g. one is the oob error rate, another is the misclass error rate and so forth, but how can I extract that information and/or filter the undesired curves?
 A: I have come across with the same issue and I found a link where it shows the graph you get when plotting the random forest model: http://statweb.stanford.edu/~jtaylo/courses/stats202/ensemble.html
If you scroll down, there is the plot(model) graph and the graph with four curves: one for the oob error in black and three corresponding to the error rates for each class ( Setosa, Versicolor and Virginica in the example). This kind of fits with my case where I just have two classes, so I get a black curve (for the oob error) and two coloured curves for the two classes I've got. 
Now, the example matched red=Setosa, green=Versicolor and blue=Virginica. In my case, i've got a binary class: 0 and 1. To know which colour was which, I executed print(rf.model) and that gave me a confusion matrix with the class.error. There, I could sort of match that my class=0 was the red and the class=1 was the green colour. That seems a reasonable way to know which curve matches which class (if your curves are not very close together) and then you can use the command legend to improve the plot. 
Hope that helps.
A: I know this post is a little bit old, but I just came accross the same problem and solved it like this:
rndF1 <- randomForest(train.X, train.Y, test.X, test.Y)
plot(rndF1)
rndF1.legend <- if (is.null(rndF1$test$err.rate)) {colnames(rndF1$err.rate)}
                else {colnames(rndF1$test$err.rate)}

legend("top", cex =0.5, legend=rndF1.legend, lty=c(1,2,3), col=c(1,2,3), horiz=T)

You can try not providing test sets, to see how the plot and legend change.
Note that my problem had two clases, therefore "lty" and "col" are of length 3, that will need customization.
A: When there is no test result (ytest was empty for training), plot shows:


*

*for classification, black solid line for overall OOB error and a bunch of colour lines, one for each class' error (i.e. 1-this class recall).

*for regression, one black solid line for OOB MSE error.


When test is present, documentation (?plot.randomForest) claims additional lines should appear (for respective measures calculated on the test set), but they don't because there is a bug in the randomForest's code.
If you want to customize this plot, it is better to just access interesting elements ($err.rate, $test$err.rate, $mse or $test$mse) and combine them into a plot you want to have.
A: If the lines are very close, I think it is not necessary to distinct them. Otherwise, you can output the value by $err.rate. and compare with the line. Or you can use only several trees in the function randomForest(Species~., iris,importance=TRUE,ntree=24) and then plot it, then you it would be easier to tell and find the correspondence between color and classes. Then you will know the order of the color in the function plot(randomforestmodel,)
A: The plot() function can be very useful here. In fact, you can do something like this to change the labels that appear on the plot.  The plot of the RandomForest will show error rates, and are very useful for analyzing the performance of the algorithm, for the different number of trees.
I recently used this:
cat(paste0('Here is a plot of the random forest for this grade, and its error rates\n'))
plot(model1, main = paste('Grade ', g))

In this case, the variable 'g' is the grade level of the student, and this is a looping variable, believe it or not. Each time through the loop, g begins at 1 and ends at 12.
Hope that helps!
