I am using ggplot2 to plot simple line charts of time series data. One difficulty I have run into is labelling specific points corresponding to x-axis values i.e. dates.
To add text to ggplot
, use geom_text
:
Method 1: Add a column of labels to your data.frame
:
tmp$note <- LETTERS[1:7]
ggplot(tmp,aes(date, price, label=note)) +
geom_line() +
geom_text(vjust=0, colour="red")
Method 2: Add a specific label:
ggplot(tmp,aes(date, price, label=date)) +
geom_line() +
geom_text(data=tmp[3, ], label="Something of note", vjust=1)