Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
Last active October 28, 2020 21:37
Show Gist options
  • Save thoughtfulbloke/44583144b5ea0890f0dafde9db07a1fa to your computer and use it in GitHub Desktop.
Save thoughtfulbloke/44583144b5ea0890f0dafde9db07a1fa to your computer and use it in GitHub Desktop.
Checks twitter accounts daylight savings movements.
# modify this line
questionable_screennames <- c("put","screennames","here")
###
library(rtweet)
library(dplyr)
library(lubridate)
library(ggplot2)
library(scales)
library(ggthemes)
## gather tweets- this number of tweets per account
## if everyone has tweeted 3000+ times this is going to be
## 15 mins * number of acocunts checked
testacs <- get_timelines(questionable_screennames, n=3000)
nzdst <- ISOdatetime(2020,9,27,1,59,59,tz = "Pacific/Auckland")
audst <- ISOdatetime(2020,10,4,1,59,59,tz = "Australia/Sydney")
prenz7am <- with_tz(ISOdatetime(2020,9,20,7,0,0,tz = "Pacific/Auckland"), "UTC")
nzdst7am <- with_tz(ISOdatetime(2020,10,27,7,0,0,tz = "Pacific/Auckland"), "UTC")
annotatepre7 <- ISOdatetime(2018,7,1,hour(prenz7am), minute(prenz7am),
second(prenz7am), tz="UTC")
annotatedst7 <- ISOdatetime(2018,7,1,hour(nzdst7am), minute(nzdst7am),
second(nzdst7am), tz="UTC")
graphlimits = c(ISOdatetime(2018,7,1,0,0,0,tz = "UTC"),
ISOdatetime(2018,7,2,0,0,0,tz = "UTC"))
testacs %>%
filter(created_at > (nzdst - days(14))) %>%
mutate(inday = ISOdatetime(2018,7,1,hour(created_at), minute(created_at),
second(created_at), tz="UTC"),
byday = floor_date(created_at, unit="day"),
when = case_when(created_at < nzdst ~ "Pre NZ DST",
created_at > audst ~ "AU DST",
TRUE ~ "NZ DST"),
cloaked_screen_name = as.numeric(factor(screen_name))) %>%
ggplot(aes(x=byday, y=inday, colour=when)) + geom_point(size=0.2) +
scale_y_datetime(date_breaks = "6 hours",
labels = date_format("%H:%M",tz = "UTC"),
limits = graphlimits) + theme_tufte() +
xlab("Day (in UTC time)") + ylab("Hour of Day (UTC)") +
scale_colour_colorblind() +
facet_wrap(~ cloaked_screen_name, ncol=6) +
annotate("line", x=c(nzdst - days(15), nzdst-days(1)), y=annotatepre7, linetype="dashed") +
annotate("line", x=c(nzdst, nzdst+days(12)), y=annotatedst7, linetype="dashed") +
annotate("line", x=c(nzdst - days(15), nzdst-days(1)), y=annotatepre7 - hours(7)) +
annotate("line", x=c(nzdst, nzdst+days(12)), y=annotatedst7 - hours(7)) +
ggtitle("Tweet times (UTC) of 'fringe' accounts saying they were New Zealanders.
Solid line: midnight in NZ, Dashed line: 7am in NZ") +
theme(strip.background = element_rect(fill= "#FFFFFF", colour="#EFEFEF"),
strip.placement = "inside",
panel.background = element_rect(fill = "#FFFFFF", colour = "#FFFFFF"),
panel.spacing = unit(1.5, "lines"),
plot.background = element_rect(fill = "#FAFAFA", colour = NA),
axis.text.x = element_text(angle = 90))
@thoughtfulbloke
Copy link
Author

Example output
patterns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment