ggplot2: how to add text to multiple vertical lines (geom_vlines) on a time x-axis?
<p>Please have a look at the following example</p>

<pre><code>library(dplyr)
library(lubridate)
library(ggplot2)
data &lt;- data_frame(time = c(ymd(20160201),
                            ymd(20160202),
                            ymd(20160203),
                            ymd(20160201),
                            ymd(20160202)),
                            value = c(1,1,1,2,2), 
                            group = c('A','A','B','B','B'))

events &lt;- data_frame(time = c(ymd(20160201), 
                              ymd(20160202)),
                     text = c('who let the dogs out?',
                              'who? who? who?'))

ggplot(data, aes(x = time, y = value, group = group, color = group)) + 
  geom_line(size = 2 ) +
  geom_vline(data = events, aes(xintercept = as.numeric(time)))  

&gt; data
# A tibble: 5 × 3
        time value group
      &lt;date&gt; &lt;dbl&gt; &lt;chr&gt;
1 2016-02-01     1     A
2 2016-02-02     1     A
3 2016-02-03     1     B
4 2016-02-01     2     B
5 2016-02-02     2     B

&gt; events
# A tibble: 2 × 2
        time                  text
      &lt;date&gt;                 &lt;chr&gt;
1 2016-02-01 who let the dogs out?
2 2016-02-02        who? who? who?
</code></pre>

<p>I would like to get a line chart for the variable <code>value</code> for each group (A and B) and plot vertical lines every time there is an event in the <code>events</code> dataframe.</p>

<p>Using the ideas  <a href="https://stackoverflow.com/questions/9422452/ggplot-vertical-line-with-date-axis">ggplot vertical line with date axis</a>, <a href="https://stackoverflow.com/questions/5388832/how-to-get-a-vertical-geom-vline-to-an-x-axis-of-class-date">How to get a vertical geom_vline to an x-axis of class date?</a> and <a href="https://stackoverflow.com/questions/28885769/how-to-add-legend-for-vertical-lines-in-ggplot">How to add legend for vertical lines in ggplot?</a> I can easily do that:</p>

<pre><code>ggplot(data, aes(x = time, y = value, group = group, color = group)) + 
  geom_line(size = 2 ) +
  geom_vline(data = events, aes(xintercept = as.numeric(time)))
</code></pre>

<p><a href="https://i.stack.imgur.com/iFhOg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iFhOg.png" alt="enter image description here"></a></p>

<p>The problem is that I would like to label each vertical line (each event) with the corresponding text, as in <a href="https://stackoverflow.com/questions/12876501/r-ggplot2-labelling-a-horizontal-line-on-the-y-axis-with-a-numeric-value">R ggplot2: Labelling a horizontal line on the y axis with a numeric value</a>. </p>

<p>Unfortunately, doing the following does not work</p>

<pre><code>ggplot(data, aes(x = time, y = value, group = group, color = group)) + 
  geom_line(size = 2 ) +
  geom_vline(data = events, aes(xintercept = as.numeric(time)))  +
  geom_text(data = events, aes(x = as.numeric(time), y = 0, label = text))
</code></pre>

<p>What is wrong here? any ideas?
Thanks!</p>