It's my first question on SO. Hopefully it will be enough detail:
I've made a Kaplan-Meier plot and would like to add a legend, however I am not having much luck with it. I know how to make a legend when you know which line is representative of it's respective category. Unfortunately since I'm using a large data set I don't know which line is which, and therefore am having a hard time creating the legend manually. Is there any way R can infer which category is which colour on the following graph? (The current selections aren't right in the legend, I was just guessing)
kmsurv1 <- survfit(Surv(as.numeric(time),hydraulic)~type)
# Specify axis options within plot()
plot(kmsurv1, col=c(1:12), main="Hydraulic Breakdown of Vehicles", sub="subtitle", xlab="Time", ylab="Probability of Being Operational", xlim=c(15400, 16500),ylim=c(.6,1.0))
legend("bottomleft", inset = 0, title = "Vehicle Type",legend= c("Hitachi Backhoe","Transport Trucks", "Water Trucks","Cat D8 Dozers", "D10 Dozers")
,fill = c(1:12), horiz=TRUE)