Looking to manually add a legend (I dont want to make the dataframe long in this case) but the legend shape doesnt match the graph:
library(ggplot2)
mtcars$time <- 1:nrow(mtcars)
ggplot(mtcars) +
#wt
geom_line(aes(x = time, y = wt, color = "wt name"), size = 1.5) +
geom_point(aes(x = time, y = wt, color = "wt name"), shape = 19, size = 4) +
#drat
geom_line(aes(x = time, y = drat , color = "drat name"), size = 1.5) +
geom_point(aes(x = time, y = drat , color = "drat name"), shape = 8, size = 4) +
scale_colour_manual(name = "legend", values = c("wt name" = "#F8766D",
"drat name" = "#B79F00"))
results in:
Other questions suggest using scale_shape_manual
but I cant get it to work:
ggplot(mtcars) +
#wt
geom_line(aes(x = time, y = wt, color = "wt name"), size = 1.5) +
geom_point(aes(x = time, y = wt, color = "wt name"), size = 4) +
#drat
geom_line(aes(x = time, y = drat , color = "drat name"), size = 1.5) +
geom_point(aes(x = time, y = drat , color = "drat name"), size = 4) +
scale_colour_manual(name = "legend", values = c("wt name" = "#F8766D",
"drat name" = "#B79F00")) +
scale_shape_manual(values = c("wt name" = 19,
"drat name" = 8 ))
gives this which ignores the shapes:
does anyone know what to change for this simple problem please? Thanks