My data looks like this:
dat <- data.frame(
rate = sample(1:30),
group = sample(c("grp1", "grp2", "grp3"))
)
dat <- dat[order(dat$group),]
dat <- dat %>% group_by(group) %>% mutate(groupid = row_number())
I want to draw a line graph by groups and add text under the x-axis, I tried this:
ggplot(dat, aes(x = groupid, y = rate, group = group, colour = group)) +
geom_line() +
geom_point() +
scale_x_continuous(name = "", breaks = seq(1, 10, by = 1)) +
annotate("text", x = 3, y = -3, size = 3.5,label = "2016")
but the text was drawn inside the graph instead of under it.
I want 2016 under the number 3 not above it. Any suggestions?
Thanks!