I'm using a data frame in R with 3 variables. I want to plot (ggplot) 2 variables (CMod4X and CMod5X) as two distinct lines, in function of the 3th variable (AmtX). In the end I succeed in creating some kind of graph that suits me, but I fail to include a legend. I have already consulted some other treads here, but the answers don't seem not to work for me.
The (artificial) data set looks like this
AmtX <- seq(from = 1, to = 10001, by = 50)
CMod4X <- rnorm(201, mean = 0.87, sd = 0.01)
CMod5X <- rnorm(201, mean = 0.84, sd = 0.01)
EvalAmtX <- as.data.frame(cbind(AmtX,CMod4X,CMod5X))
I have made the plot like this
pltX <- ggplot(data = EvalAmtX, aes (x = AmtX)) +
geom_line(aes(y = CMod4X), color = "red", show.legend = TRUE) +
geom_line(aes(y = CMod5X), color = "blue", show.legend = TRUE) +
geom_smooth(aes(y = CMod4X), color = "red", se = FALSE, show.legend = TRUE) +
geom_smooth(aes(y = CMod5X), color = "blue", se = FALSE, show.legend = TRUE) +
labs(y = "C-index", x = "Amount (Tau)", title = "model 4 and model 5") +
scale_colour_manual(name = "Models", values = c("CMod4" = "red", "CMod5" = "blue"))
pltX
But this plot won't include a label. I've included my plot below:
What am I doing wrong and what must I do to obtain a plot telling me the red line is CMod4 and the blue line is CMod5?
Thx for your help!! Leonard