There are some nice packages to wrap with ggplot2 to label specific points on a plot (ggrepel
). However, I am having difficulty if I want to label geom_line.
library(tidyverse)
library(ggrepel)
data("Theoph")
Theoph2 <- Theoph %>%
filter(Subject %in% c(2, 9, 10)) %>%
mutate_at(vars(Dose), as.character)
ggplot(data = Theoph2, aes(Time, conc, color = Dose, group = Dose)) +
geom_line(size = 1.2) +
geom_label_repel(aes(label = Dose), nudge_x = 0.35, size = 4)
I would like to label the line with variable = Dose to happen with one time to emphasize in the plot what the line corresponds to. In this example, however, it shows it all every x point in the data.