I'm trying to make a plot with the legend using ggplot in R. I got the graph with the legend, but the colours associated to each line/point are wrong. For instance, I get that GDP is green rather than black and the same for others lines. This is the code I'm using:
ggplot(GDP_pred, aes(x=quarters)) +
geom_line(aes(y=GDP, color = "GDP")) +
geom_point(aes(y=lasso, color = "lasso")) +
geom_point(aes(y=ridge, color = "ridge")) +
geom_point(aes(y=elnet, color = "elnet")) +
geom_point(aes(y=rf, color = "rf")) +
geom_point(aes(y=gbm, color = "gbm")) +
scale_color_manual(name = "Method",
values = c("GDP" = "black", "lasso" = "blue", "ridge" = "red", "elnet" = "green", "rf" = "orange", "gbm" = "pink"),
labels = c("GDP", "Lasso", "Ridge", "Elastic Net", "Random Forest", "GBM")) +
xlab("Quarters")+
ylab("GDP (billions of chained 2012 dollars)") +
labs(title = "Prediction of the GDP in the US",
subtitle = "Q1/2014-Q4/2021")
What could be the problem? How can I solve it?
Thank you in advance.