Skip to content

Instantly share code, notes, and snippets.

View Ryo-N7's full-sized avatar

Ryo Nakagawara Ryo-N7

View GitHub Profile
@BenjaminWolfe
BenjaminWolfe / curl.R
Last active April 3, 2022 21:31
Create Pages in Notion with R
# See `curl.md`. Here is the R equivalent.
library(httr)
library(jsonlite)
make_page <- function(url, headers, data) {
response <- POST(
url = url,
body = toJSON(data, auto_unbox = TRUE),
config = add_headers(.headers = headers)
# Levante UD Rolling xG Plot
# Owen Thompson
# 2022-01-18
# -- Load libraries
library(tidyverse)
library(ggtext)
# -- Resources ----------------------------------.
# Adjust Transparency (alpha) of stat_smooth lines, not just transparency of Confidence Interval
#' Helper functions for styling with ggtext
#'
#' @param text The text which should be styled
#' @param ... Style options. For example `color="red"`
#' @param tag HTML tag to apply to the text. Defaults to `span`
#'
#' @export
tagged_text <- function(text, ..., tag = "span") {
glue::glue("<{tag} style='{parse_style_options(...)}'>{text}</{tag}>")
}
library(tidyverse)
library(gt)
# create data
df <- data.frame(
stringsAsFactors = FALSE,
player = c("Evan Mobley",
"Sandro Mamukelashvili","Charles Bassey","Luka Garza",
"Moses Wright","Neeimisa Queta",
"Isaiah Jackson","Day'Ron Sharpe"),
@juliasilge
juliasilge / internet_access.md
Created May 12, 2021 03:34
#TidyTuesday internet access in the US
library(tidyverse)
library(tidycensus)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
library(viridis)
#> Loading required package: viridisLite
library(patchwork)
theme_set(silgelib::theme_plex())
@uribo
uribo / jma_normal_phenology.R
Created March 31, 2021 14:47
生物季節観測 さくらの開花日・満開日の期間
####################################
# 月*100+日
# 9月5日 --> 905
####################################
library(readr)
library(dplyr)
library(ggplot2)
library(ggalt)
d <-
read_csv("~/Downloads/normal_phenology/nml_phenology.csv",
``` r
library(ggplot2)
library(dplyr)
library(magick)
library(patchwork)
library(gt)
library(ggtext)
mtcars %>%
head() %>%
@elliottmorris
elliottmorris / election_night_live_model.R
Last active January 29, 2024 18:56
A live election-night prediction model using The Economist's pre-election forecast
#' Description
#' This file runs a live election-night forecast based on The Economist's pre-election forecasting model
#' available at projects.economist.com/us-2020-forecast/president.
#' It is resampling model based on https://pkremp.github.io/update_prob.html.
#' This script does not input any real election results! You will have to enter your picks/constraints manually (scroll to the bottom of the script).
#'
#' Licence
#' This software is published by *[The Economist](https://www.economist.com)* under the [MIT licence](https://opensource.org/licenses/MIT). The data generated by *The Economist* are available under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).
#' The licences include only the data and the software authored by *The Economist*, and do not cover any *Economist* content or third-party data or content made available using the software. More information about licensing, syndication and the copyright of *Economist* content can be fou

Introduction

"Footedness" is a concept you're probably familiar with. Players almost always naturally prefer to dribble / shoot / pass with a certain foot. Total ambidexterity (being as comfortable using one foot as the other) is rarer, but is common enough at the top level.

One of the ways in which we can quantify footedness for a player is looking at how many shots or goals the player scores using one foot vs. the other. However, this isn't that meaningful for us because the majority of the time, we can see with our own eyes which foot a player prefers.

On the other hand, footedness of teams is more interesting to me. Here I've looked at which teams prefer one foot over the other or are ambidextrous, using a new metric I've called the "Ambidexterity Index" (AI). The source for all data described here is Understat; full credit to them.


@emitanaka
emitanaka / collapseoutput.js
Created July 20, 2019 04:43
Collapsible Code Output for `xaringan`
<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>Output</summary>" + outputNode.outerHTML + "</details>";
})
})();
(function() {