Skip to content

Instantly share code, notes, and snippets.

@erictleung
Last active May 4, 2022 19:55
Show Gist options
  • Save erictleung/37074579844334ca5f254b5d89657859 to your computer and use it in GitHub Desktop.
Save erictleung/37074579844334ca5f254b5d89657859 to your computer and use it in GitHub Desktop.
Plot number of smartphone users over time, data from a tweet
library(dplyr)
library(stringr)
library(ggplot2)
d <- rtweet::search_tweets("from:stats_feed", n = 30) %>%
filter(status_id == "1521871339908263937") %>%
pull(text) %>%
str_split("\n") %>%
as_tibble(.name_repair = "universal") %>%
rename("data" = "...1") %>%
filter(str_detect(data, "billion")) %>%
mutate(year = as.numeric(str_extract(data, "20[0-9]{2}")),
billions = as.numeric(str_extract(data, "[0-9]\\.[0-9]")))
d %>%
ggplot(aes(x = year, y = billions)) +
geom_col() +
scale_x_continuous(breaks = seq(2012, 2022, 2)) +
theme_minimal() +
labs(x = "Year", y = "Smartphone users (billions)")
ggsave("smartphone_users.png", width = 5, height = 5, scale = 0.6, bg = "white")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment