Skip to content

Instantly share code, notes, and snippets.

View Ryo-N7's full-sized avatar

Ryo Nakagawara Ryo-N7

View GitHub Profile
# load packages
pacman::p_load(tidyverse, scales, ggbeeswarm, extrafont, glue, magick)
# load fonts
loadfonts()
# load data
launches_raw <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-01-15/launches.csv")
# wrangle data
@Ryo-N7
Ryo-N7 / tokyo_monthly_1876-2018.r
Created March 2, 2019 05:57
Tokyo Monthly Temperature (1876-1886 vs. 2008-2018)
# packages
pacman::p_load(tidyverse, lubridate, geofacet, gghighlight,
sf, extrafont, glue, RColorBrewer, emo)
# font packages
loadfonts(device = "win")
# import and clean
# download from JMA website: http://www.data.jma.go.jp/gmd/risk/obsdl/index.php
# choose TokyoPrefecture/Tokyo Station, Monthly data, Jan. 1872 to Dec. 2018
@Ryo-N7
Ryo-N7 / jpop_geofacet.r
Created March 11, 2019 14:21
geofacet japanese pop. decline, focus on north-east region (Tohoku earthquake)
# packages
pacman::p_load(tidyverse, scales, lubridate, ggrepel, sf,
glue, extrafont, readxl, jpndistrict, geofacet, cowplot,
gghighlight, magick)
loadfonts(device = "win", quiet = TRUE)
# data from eStat.go.jp: https://www.e-stat.go.jp/stat-search/files?page=1&layout=datalist&toukei=00200524&tstat=000000090001&cycle=0&tclass1=000000090004&tclass2=000001051180
# specifically data file: 05k5-5.xls
jpn_pop_raw <- read_xls(glue("{here::here()}/data/05k5-5.xls"), skip = 9,
col_types = c("skip", "text", "skip", "text",
@Ryo-N7
Ryo-N7 / shimizu-s-pulse-age-utility-matrix.r
Last active March 24, 2019 10:52
age-utility matrix (Shimizu S-Pulse)
## packages
pacman::p_load(tidyverse, polite, scales, ggimage, rvest,
glue, extrafont, ggrepel, magick, ggforce)
loadfonts()
## add logo function
add_logo <- function(plot_path, logo_path, logo_position, logo_scale = 10){
# Requires magick R Package https://github.com/ropensci/magick
@Ryo-N7
Ryo-N7 / goal_contribution_matrix_jleague_2018.r
Last active April 2, 2019 14:28
Goal Contribution Matrix (J.League: 2018 Season)
pacman::p_load(tidyverse, polite, scales, ggimage,
rvest, glue, extrafont, ggrepel, magick)
loadfonts()
url <- "https://www.transfermarkt.com/j1-league/startseite/wettbewerb/JAP1/plus/?saison_id=2017"
session <- bow(url)
team_links <- scrape(session) %>%
html_nodes("#yw1 > table > tbody > tr > td.zentriert.no-border-rechts > a") %>%
@Ryo-N7
Ryo-N7 / gundam_gt.r
Last active April 26, 2019 16:50
Gundam gt (tidy tuesday)
## Packages
pacman::p_load(tidyverse, scales, janitor, gt, rvest, polite, glue, webshot)
## Data
tidy_anime <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-04-23/tidy_anime.csv")
## get Gundam data
gundam_raw <- tidy_anime %>%
select(-related, -background, -premiered, -related, -members, -airing, -favorites,
-title_synonyms, -title_japanese, -producers, -status, -broadcast, -genre, -source, -rank, -popularity) %>%
@Ryo-N7
Ryo-N7 / epl_goal_contribution_matrix_18-19.r
Last active April 1, 2021 14:19
Goal contribution matrix for Premier League 2018-2019
# pkgs
pacman::p_load(tidyverse, polite, scales, ggimage, ggforce,
rvest, glue, extrafont, ggrepel, magick)
loadfonts()
## add_logo function from Thomas Mock
add_logo <- function(plot_path, logo_path, logo_position, logo_scale = 10){
# Requires magick R Package https://github.com/ropensci/magick
@Ryo-N7
Ryo-N7 / laliga_goal_contribution_matrix.r
Last active May 30, 2019 10:45
Goal contribution matrix for La Liga (2018-2019 Season)
## pkgs
pacman::p_load(tidyverse, polite, scales, ggimage, ggforce,
rvest, glue, extrafont, ggrepel, magick)
loadfonts()
## add_logo function from Thomas Mock
add_logo <- function(plot_path, logo_path, logo_position, logo_scale = 10){
# Requires magick R Package https://github.com/ropensci/magick
@Ryo-N7
Ryo-N7 / goleadoresdecopamerica.r
Last active June 7, 2019 12:51
Top scorers of the Copa America
# pkgs
library(dplyr)
library(tidyr)
library(purrr)
library(stringr)
library(rvest)
library(polite)
library(ggplot2)
library(scales)
library(cowplot)
@Ryo-N7
Ryo-N7 / GanadoresDeCopaAmerica.r
Last active June 14, 2019 17:02
Most successful teams of the Copa America!
## packages
library(dplyr)
library(tidyr)
library(purrr)
library(stringr)
library(rvest)
library(polite) ## github only
library(ggplot2)
library(scales)
library(glue)