This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' geom_ghazi. Annotate any ggplot2 plot with Benghazi, because it's | |
| #' always about Benghazi | |
| library("ggplot2") | |
| geom_ghazi <- function(gp = grid::gpar(fontsize = 75, fontface = "bold"), | |
| ...) { | |
| annotation_custom(grid::textGrob("BENGHAZI", gp = gp, ...), | |
| xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) | |
| } | |
| ggplot(mtcars, aes(x = disp, y = mpg)) + geom_point() + geom_ghazi() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library("purrr") | |
| library("lazyeval") | |
| library("stringr") | |
| library("dplyr") | |
| expand_call <- function(x, envir = parent.frame()) { | |
| if (is.atomic(x)) { | |
| if (is.character(x)) { | |
| .m(x, envir = envir) | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| qss_data_url <- function(chapter, file) { | |
| chapter_name <- toupper(chapter) | |
| paste0("https://raw.githubusercontent.com/kosukeimai/qss/master/", | |
| chapter_name, "/", file) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library("readr") | |
| # see http://r4ds.had.co.nz/strings.html for functions to manipulate strings | |
| library("stringr") | |
| # Read individual lines into a character vector | |
| lines <- read_lines("data/county_data.csv") | |
| # delete the first and last character of each line | |
| lines <- str_sub(lines, 2, -2) | |
| # check that it worked by looking at the first line | |
| lines[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| install.packages("ggstance") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(stringr) | |
| library(dplyr) | |
| drop_leading0 <- function(x) { | |
| str_replace(x, "\\b0+\\.(?=[0-9])", ".") | |
| } | |
| format_pval <- function(x, eps = 0.001, digits = 2, drop = TRUE) { | |
| ret <- if_else( | |
| x < eps, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| d3 = function() { | |
| var d3 = { | |
| version: "3.2.7" | |
| }; | |
| if (!Date.now) Date.now = function() { | |
| return +new Date(); | |
| }; | |
| var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window; | |
| try { | |
| d3_document.createElement("div").style.setProperty("opacity", 0, ""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| d3 = function() { | |
| var d3 = { | |
| version: "3.2.7" | |
| }; | |
| if (!Date.now) Date.now = function() { | |
| return +new Date(); | |
| }; | |
| var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window; | |
| try { | |
| d3_document.createElement("div").style.setProperty("opacity", 0, ""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| d3 = function() { | |
| var d3 = { | |
| version: "3.2.7" | |
| }; | |
| if (!Date.now) Date.now = function() { | |
| return +new Date(); | |
| }; | |
| var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window; | |
| try { | |
| d3_document.createElement("div").style.setProperty("opacity", 0, ""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| d3 = function() { | |
| var d3 = { | |
| version: "3.2.7" | |
| }; | |
| if (!Date.now) Date.now = function() { | |
| return +new Date(); | |
| }; | |
| var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window; | |
| try { | |
| d3_document.createElement("div").style.setProperty("opacity", 0, ""); |