I'm newbie in R and I'm trying to make a graphic with ggplot2 where you can 5 different stats. So, I would like to have on the right side a legend with the color and the name of the stadistic but I don't know how to do it.
My code to make the graphic are:
ggplot(object@data, aes(x=data[,1])) +
geom_point(aes(y=data[,2]), color="blue") +
geom_point(aes(y=data[,3]), color = "red") +
geom_point(aes(y=data[,4]), color = "olivedrab4") +
geom_point(aes(y=data[,5]), color = "hotpink4") +
geom_point(aes(y=data[,6]), color = "limegreen") +
labs(title = "Liga DIA: Comparativas (Liga Regular) - www.basketmetrics.com",
x = "Equipos", y = "Total") +
#Pone las etiquetas del eje de las X en vertical
theme(axis.text.x = element_text(angle = 90, hjust = 1, color = "white"),
axis.text.y = element_text(color = "white"),
legend.position = "top", legend.title = element_blank()) +
#Modificamos el fondo del panel
theme(panel.background = element_rect(fill = 'peachpuff', colour = 'white')) +
theme(plot.background = element_rect(fill = 'navyblue', colour = 'white'),
plot.title = element_text(size = 20, face = "bold", color = "white"),
axis.title.x = element_text(face = "bold", color = "white"),
axis.title.y = element_text(face = "bold", color = "white")) +
scale_color_manual(name="Estadísticas", labels = c("ORTG", "DRTG", "Pace", "eFG%", "3P%"),
values = c("blue", "red", "olivedrab4", "hotpink4", "limegreen"))
I supposed that with this code I could have the legend but it doesn't work to me :(
scale_color_manual(name="Estadísticas", labels = c("ORTG", "DRTG", "Pace", "eFG%", "3P%"),
values = c("blue", "red", "olivedrab4", "hotpink4", "limegreen"))
Right now, what I get is this graphic:
How can I set a legend on the right side with each color and the name of the statistic?