ha-pu/globaltrends

Add change_score

Closed this issue · 1 comments

ha-pu commented
library(lubridate)
library(tidyverse)

data <- globaltrends::data_doi %>%
  filter(keyword == "amazon" & type == "score_obs" & locations == "countries") %>%
  mutate(date = as_date(date)) %>%
  mutate(doi_change = gini - lag(gini)) %>%
  select(date, doi_change)

q1 <- quantile(data$doi_change, probs = 0.05, na.rm = TRUE)
q2 <- quantile(data$doi_change, probs = 0.95, na.rm = TRUE)


ggplot(data, aes(x = date, y = doi_change)) +
  geom_hline(yintercept = 0) +
  geom_hline(yintercept = q1, colour = "blue4", linetype = "dotted") +
  geom_hline(yintercept = q2, colour = "blue4", linetype = "dotted") +
  geom_line() +
  geom_point(data = filter(data, doi_change < q1 | doi_change > q2), colour = "firebrick") +
  theme_bw()

Originally posted by @ha-pu in #114 (comment)

ha-pu commented

Change in data_score for single location