0
votes

I have downloaded a timeline from a twitter user and try to visualise the number of tweets over time. I'm doing it with rtweets ts_plot. Now I'm trying to add a vertical line in my graph. As far as I know ts_plot allows you to work with it as if it was a normal ggplot. Therefore, I tried ggplot2's geom_vline:

This is my code:

zanetti <- get_timeline("@zac1967", n=3200)

ts_plot(zanetti, "days") +
  theme_bw() +
  xlab("") +
  ylab("# of tweets/day") +
  geom_vline( aes(xintercept = "2019-03-21 00:00:00 UTC"))

However, I receive this error message:

  no applicable method for 'rescale' applied to an object of class "character" 

So i tried the same code but added as.numeric in the last line:

ts_plot(zanetti, "days") +
  theme_bw() +
  xlab("") +
  ylab("# of tweets/day") +
  geom_vline( aes(xintercept = as.numeric("2019-03-21 00:00:00 UTC")))

Which leads to following error message:

Warning messages:
1: In FUN(X[[i]], ...) : NAs introduced by coercion
2: Removed 53 rows containing missing values (geom_vline). 
1
Instead of as.numeric try as.DateG5W

1 Answers

0
votes

First, you don't need to use aes() as you are not mapping to a column name.

The x-axis scale for ts_plot is a date-time scale, so you need to convert the value accordingly. Something like this should work:

+ geom_vline(xintercept = as.POSIXct("2019-03-21 00:00:00", tz = "UTC"))