Skip to content

Instantly share code, notes, and snippets.

View raphifix's full-sized avatar

Raphael Fix raphifix

View GitHub Profile
rm(list=ls())
library(ggplot2)
library(rvest)
library(zoo)
url <- "https://www.justice.gov/pardon/obama-commutations"
clemency_info <-
url %>%
read_html() %>%
html_nodes(xpath = "/html/body/div[1]/div[2]/div/div/div[2]/article/div[1]/div/div/div/table[1]") %>%
line_dat <-
dat %>%
filter(dat$signal != '--')
p <- layout(p, list(type = "line",
fillcolor = "blue", line = list(color = "blue"),
opacity = 0.3, x0 = "1997-02-11", x1 = "1997-02-11",
xref = "x", y0 = 0, y1 = 10.22, yref = "y"))
line_list <- list()
for(i in 1:nrow(line_dat)){
line_color <- ifelse(line_dat$signal[i] == 'buy', 'green', 'red')
line_list[[i]] <- list(type = "line",
fillcolor = line_color, line = list(color = line_color), opacity = 0.3,
x0 = line_dat[[1]][i], x1 = line_dat[[1]][i], xref = "x",
y0 = 0, y1 = line_dat[[2]][i], yref = "y")
}