This file contains 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
################################################################################ | |
# | |
# ikashnitsky.github.io 2017-06-30 | |
# Produce an RGB coded map of pop structures at NUTS-3 level | |
# Ilya Kashnitsky, [email protected] | |
# | |
################################################################################ | |
# load required packages | |
library(tidyverse) # data manipulation and viz |
This file contains 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
#' A pipable if statement | |
#' | |
#' This function allows to create an if statement that can be used within a pipable workflow | |
#' | |
#' @importFrom magrittr %>% | |
#' @importFrom rlang parse_expr | |
#' @param .data tibble | |
#' @param condition logical test | |
#' @param call a formula descibing a pipe to be evaluated if condition is \code{code} | |
#' @examples |
This file contains 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(dplyr) | |
do_if <- function(.data, condition, call){ | |
if(condition){ | |
.x <- .data | |
call_str <- call %>% | |
as.character %>% | |
.[2] |
This file contains 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/Load Packages --#### | |
#install.packages("pacman") | |
pacman::p_load(tidyverse, tabulizer, lubridate) | |
####-- Get Intel Report and extract Tables --#### | |
# Location of Intel Report pdf file | |
location <- 'https://intelligence.house.gov/uploadedfiles/20191203_-_full_report___hpsci_impeachment_inquiry_-_20191203.pdf' |
This file contains 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 these packages if you don't have them yet | |
# if (!require("pacman")) install.packages("pacman") | |
pacman::p_load(tidyverse, egg, gridExtra, grid, patchwork) | |
## Function to fix panel width and add "buffers" for right-alignment | |
## based on: https://gist.github.com/baptiste/eadeecd7d3756a7f294eb3cade8b0b17 | |
facet_cleaner <- function(p, panel_size = 5, panel_height = 1) { | |
p %>% | |
egg::set_panel_size( |
This file contains 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(tidyverse) | |
library(lavaan) | |
measurement_invariance <- function(model, data, group, fit_measures) { | |
## Configural Model | |
model1 <- cfa(model = model, data = data, group = group) | |
## Weak/metric invariance | |
model2 <- cfa(model = model, data = data, group = group, group.equal=c("loadings")) | |
## Strong/scalar invariance |
This file contains 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(tidyverse) | |
library(ggbeeswarm) | |
library(ggthemes) | |
library(glue) | |
elex <- read_csv("https://raw.githubusercontent.com/favstats/USElection2020-NYT-Results/master/data/latest/presidential.csv") | |
elex %>% | |
mutate(votes_perc = votes/sum(votes)) %>% | |
mutate(abs_margin2020 = abs(margin2020)) %>% |
This file contains 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
paadc_ids_2021_01_22 <- old_data%>% | |
# distinct(paadc) %>% | |
mutate(impressionTime = lubridate::ymd_hms(impressionTime)) %>% | |
group_by(paadc) %>% | |
filter(impressionTime == min(impressionTime)) %>% | |
ungroup() %>% | |
distinct(paadc, .keep_all = T) %>% | |
arrange(impressionTime) %>% | |
mutate(firstImpressionTime = as.character(impressionTime)) %>% | |
select(paadc, firstImpressionTime) %>% |
This file contains 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
mutate(type = case_when( | |
type == "Regio" ~ "Local Politics", | |
type == "Rest" ~ "Party Youth Organization/Dutch Politicians (Other)", | |
type == "Kandidaat" ~ "Dutch Politician", | |
type == "Landelijk" ~ "Dutch National Party" | |
)) |
OlderNewer