0

I have this plot of my data shown here I have this plot of my data shown here:

What I want to happen is to have a legends of each point or what these corresponds about which should be written in the right side of the chart. I have tried everything but it doesn't showed up.

Here's the Code I have for this:

ggplot(df, aes(x = USER_ALLIAS, y = AVERAGE_HEART_RATE)) +
geom_point(color = "blue", show.legend = TRUE) +
geom_line(linetype = "dotted", color = "black", group = "USER_ALLIAS") +
geom_line(aes(y = MAXIMUM_HEART_RATE), linetype = "dotted", color = "black", group = "USER_ALLIAS") +
geom_point(aes(y = MAXIMUM_HEART_RATE), color = "red", show.legend = TRUE) +
labs(title = "Average and Maximum Heart Rate per User", x = "User ID", y = "Heart Rate") +
theme(legend.position = "right") +
guides(color = guide_legend(title = "Color", override.aes = list(shape = c(16, 17)),
labels = c("Average Heart Rate", "Maximum Heart Rate")))

Thank you so much!

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • If you want a legend, you need to map color inside an `aes()`. See the duplicates for examples of doing this. – MrFlick Aug 17 '23 at 15:00

0 Answers0