Skip to content

Instantly share code, notes, and snippets.

Avatar

Philip Parker pdparker

View GitHub Profile
View theme_MandB.R
library(tidyverse)
library(extrafont)
font_import()
theme_MandB <- function (base_size = 11, base_family = "Times New Roman", horizontal = TRUE, dkpanel = FALSE)
{
bgcolors <- c("#24292D", "#323E4E", "#BED5E0")
ret <- theme_foundation(base_size = base_size, base_family = base_family) +
View texture_image_background.R
library(tidyverse)
library(magick)
width = 800
height = 500
img <- image_read("https://i.dlpng.com/static/png/6920336_preview.png")
pomo_bg <- magick::image_resize(img, paste0(width, "x", height, "!"))
pomo_bg <- magick::image_crop(pomo_bg, paste0(width, "x", height))
View 2020-06-21_TidyTuesday_plot2.R
library(ggmap)
library(maps)
library(mapdata)
library(glue)
library(here)
library(progress)
library(extrafont)
font_import()
tuesdata <- tidytuesdayR::tt_load(2020, week = 25)
View 2020-06-21_TidyTuesday.R
#devtools::install_github("thebioengineer/tidytuesdayR")
library(tidyverse)
library(ggpomological)
tuesdata <- tidytuesdayR::tt_load(2020, week = 25)
extrafont::ttf_import(paths = "~/Downloads/bayard-desktop")
extrafont::fonts()
#tuesdata$census%>%View
#tuesdata$slave_routes %>% View
@pdparker
pdparker / apa_style_gt.R
Last active Jun 13, 2020
APA Style Table for GT Package
View apa_style_gt.R
# Provides APA 7th Styling to a table ####
# Only works using the global-font-options branch of the gt package
#Requires
library(gt)
library(tidyverse)
# APA style ####
apa_style <- function(data) {
data %>%
opt_table_lines(extent = "none") %>%
View simmons_replication.R
library(tidyverse)
# Replication of Simmons ####
set.seed(42)
reps <- 1500
n <- 40
sim <- matrix(NA, nrow = reps, ncol = 4)
colnames(sim) <- c("vanilla_est", "vanilla_p", "covariate_est", "covariate_p")
for (i in 1:reps){
d = data_frame(
@pdparker
pdparker / image_input.gs
Last active May 26, 2020
Inserts an image from url and attaches the url to the image
View image_input.gs
// Set Globals
var ui = DocumentApp.getUi();
/** Demonstrates a simple way to prompt the user for a date. */
function img_workflow() {
// Set UI prompt + reminder to use unsecured image
var url = ui.prompt('Enter URL of image', 'use http not https', ui.ButtonSet.OK_CANCEL);
var line = url.getResponseText();
// If user clicks OK
if (url.getSelectedButton() == ui.Button.OK) {
// fetch image url
@pdparker
pdparker / UpdateImage.gs
Last active May 26, 2020
Update Images by URL
View UpdateImage.gs
/**
* Updates images by there URL. Run when image changes
* This only works for images that have a link to themselves in a google doc
* To link an image right mouse click and select link. Put a link to the image URL there
* URLs for images in Drive take the form http://drive.google.com/uc?export=view&id=##IMAGE ID HERE##
* Will replace image with same dimensions. Will not match rotation angle.
* I think the URLs need to be http rather than https to work consistently.
*/
function replace_images_url() {
// Open the document by id
View Rmd
---
title: "R Notebook"
output: html_notebook
---
# Overview
##
![Overview](fig/PISA-Workshop.png)
@pdparker
pdparker / loadingSimuation
Last active May 28, 2016
Get loadings and residuals to give a particular Omega reliability
View loadingSimuation
findValues <- function(reliability, n=6, n.total=100){
require(MASS)
f = function(L,reliability, n){-reliability+(L*n)^2/((L*n)^2 + (1- L^2)*n)}
#Base loadings residuals on that
L <- uniroot(f,interval = c(0,1), reliability=reliability, n = n)$root
R <- 1-L^2
out<- sprintf("The sum of the loadings must equal: %f and the residual: %f\n
For a Tau equaivilent model - \nEach loading should be: %f and each residual: %f",
L*n, R*n, L, R)