Giter Club home page Giter Club logo

layoffbot_timeseries's Introduction

Visualizing unemployment trends collected by @layoffbot.

Required Packages

library(tidyverse)
library(rtweet)
library(lubridate)
library(ggiraph)
library(extrafont)
library(ggtext)

Get tweets by the bot

layoff_timeline <- get_timeline("layoffbot", n = 3200, include_rts = FALSE)

Clean to get the lay off count in each tweet

layoff_df <- layoff_timeline %>%
  filter(str_detect(text, "In the last hour,")) %>%
  select(created_at, text) %>%
  mutate(created_at = ymd_hms(created_at),
         laid_off_count = as.numeric(str_extract(text, "[0-9]+")))

Base Chart

p2 <- layoff_df %>%
  ggplot(aes(x = created_at, y = laid_off_count)) +
  geom_line(colour = "purple") +
  scale_x_datetime(breaks = scales::date_breaks("1 day"),
                   labels = scales::date_format("%a. \n %b \n %d"), position = "top") +
  scale_y_log10(position = "right") +
  labs(title = "Tracking Self-Declared Layoffs During COVID-19",
       subtitle = 'Estimating recently unemployed workers by counting tweets with the words <br><i><b>"I was just laid off" </i></b> / <i><b> "I just got laid off"</i></b>',
       x = "",
       y = "Tweets Per Hour",
       caption = "SOURCE: @layoffbot; VIZ: @datajake") +
  theme_minimal() +
  theme(text = element_text(family = "Roboto Condensed"),
        panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        axis.text.x.bottom = element_text(),
        plot.margin = unit(c(0.5,0.5,0.5,0.7), units = "cm"),
        plot.title = element_text(hjust = 0.5, family = "Merriweather ExtraBold", colour = "purple"),
        plot.subtitle = element_markdown(hjust = 0.7, halign = 0.5, lineheight = 1.5),
        plot.caption = element_text(colour = "grey50", hjust = 0),
        axis.title.y.right = element_text(size = 8),
        axis.ticks.x = element_line(color = "grey50"))

SVG

girafe(ggobj = p2, width_svg = 7.2, height_svg = 4, 
       opts_toolbar(saveaspng = FALSE))

layoffbot_timeseries's People

Contributors

imjakedaniels avatar

Stargazers

Serdar Balcı avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.