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
## Create NYT Spiral Animations | |
## Most Code comes from here: https://bydata.github.io/nyt-corona-spiral-chart/ | |
library(tidyverse) | |
library(lubridate) | |
library(gganimate) | |
library(viridis) | |
owid_url <- "https://github.com/owid/covid-19-data/blob/master/public/data/owid-covid-data.csv?raw=true" |
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
### Code mostly inspired by https://github.com/HudsonJamie/tidy_tuesday/blob/main/2021/week_46/afrilearndata.R | |
library(pdftools) | |
library(tidygeocoder) | |
library(tidyverse) | |
library(janitor) | |
library(rgdal) | |
library(osmdata) | |
library(sf) | |
library(ggfx) |
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(sf) | |
library(cowplot) | |
library(showtext) | |
library(sysfonts) | |
library(ggplot2) | |
showtext_auto() | |
font_add_google("Quicksand") | |
font_add_google("Fira Sans") | |
font1 <- "Quicksand" |
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
### The following functions borrow heavily from this gist by @jnolis | |
### https://gist.github.com/jnolis/a41c196a5e22e2a2115d28e853d4780c | |
### Unfortunately, the shiny app framework didn't work for me | |
### So I created an interactive console script that guides you through authentification | |
### No shiny needed | |
# This function creates a URL for users to click to authenticate. | |
# You should use it to show a URL when users haven't authenticated yet. | |
get_authorization_url <- function(app, permission=NULL){ |
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
<script> | |
(function() { | |
var divHTML = document.querySelectorAll(".details-open"); | |
divHTML.forEach(function (el) { | |
var preNodes = el.getElementsByTagName("pre"); | |
var outputNode = preNodes[1]; | |
outputNode.outerHTML = "<details open class='output'><summary>Run</summary>" + outputNode.outerHTML + "</details>"; | |
}) | |
})(); | |
(function() { |
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
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" | |
)) |
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
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 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(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 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(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 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 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( |