且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何说服ggplot2 geom_text在时间序列图中标记指定的日期?

更新时间:2023-09-23 17:21:04

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)

相关阅读

推荐文章