Skip to content

Instantly share code, notes, and snippets.

View ikashnitsky's full-sized avatar

Ilya Kashnitsky ikashnitsky

View GitHub Profile
@ikashnitsky
ikashnitsky / euro2020-predictions.R
Last active June 12, 2021 11:38
Win predictions of #EURO2020 pooled together from 18 sources -- https://twitter.com/ikashnitsky/status/1403470245407477764
#===============================================================================
# 2021-06-11 -- twitter
# UEFA European Cup predictions
# Ilya Kashnitsky, [email protected], @ikashnitsky
#===============================================================================
library(tidyverse)
library(magrittr)
library(ggdark)
library(paletteer)
#===============================================================================
# 2021-04-19 -- critique
# Re-analysis of Royal family members longevity
# https://theconversation.com/amp/long-live-the-monarchy-british-royals-tend-to-survive-a-full-three-decades-longer-than-their-subjects-158766
# Ilya Kashnitsky, [email protected], @ikashnitsky
#===============================================================================
library(tidyverse)
library(magrittr)
library(lubridate)
@ikashnitsky
ikashnitsky / rotater-the-damn-plot
Last active April 5, 2021 21:13
A minimal example #RotateTheDamnPlot, supplement for https://twitter.com/ikashnitsky/status/1378688932968333312
library(tidyverse)
mtcars %>%
group_by(cyl = cyl %>% as_factor) %>%
summarise(avg_mpg = mpg %>% mean) %>%
ggplot(aes(avg_mpg, cyl))+
geom_col()
@ikashnitsky
ikashnitsky / dark-tern-theme.r
Last active April 1, 2021 13:19
a nice dark theme for {ggtern} and {tricolore}
library(ggtern)
library(ggdark)
library(hrbrthemes)
# own options for ternary theme
own_tern_theme <- dark_theme_minimal(base_family = font_rc) +
theme(
legend.position = "none",
axis.title = element_blank(),
tern.axis.arrow.show = FALSE,
@ikashnitsky
ikashnitsky / fun-localize-path.R
Last active March 3, 2021 18:12
a small function to localize paths in R
lp <- function(path) {
require(here)
require(magrittr)
require(glue)
wd <- here::here()
glue(paste0("{wd}/", path))
}
@ikashnitsky
ikashnitsky / fun-fread-local-hmd.R
Last active April 11, 2025 09:51
Handy functions to quickly load locally stored HMD files -- get the zip from https://www.mortality.org/cgi-bin/hmd/hmd_download.php
#===============================================================================
# 2021-02-23 -- local hmd UPD 2025-04-11
# Function to read in a whole local HMD folder
# Ilya Kashnitsky, [email protected]
#===============================================================================
# a function to read ONE file
fread_hmd <- function(x) x %>%
data.table::fread(skip = 2, na.strings = ".") %>%
mutate(Age = Age %>% str_remove("\\+") %>% as.integer()) %>%
@ikashnitsky
ikashnitsky / check-ranking.R
Last active February 18, 2021 11:21
Check the ranking of Japan prefectures by raw cumulative c19 cases and weighted by population
#===============================================================================
# 2021-02-16 -- review
# BMJ Open Japan prefectures R2
# Ilya Kashnitsky, [email protected]
#===============================================================================
library(tidyverse)
library(magrittr)
library(janitor)
@ikashnitsky
ikashnitsky / publons-country.R
Last active November 3, 2023 15:29
Map the country data of Publons (data from https://publons.com/country, manual export on 2021-01-07) – https://twitter.com/ikashnitsky/status/1347325289496502272
#===============================================================================
# 2021-01-07 -- twitter
# Visualize Publons country data
# https://publons.com/country
# Ilya Kashnitsky, [email protected]
#===============================================================================
library(tidyverse)
library(magrittr)
library(sf)
@ikashnitsky
ikashnitsky / sim-cum-diff-poisson.R
Created December 20, 2020 00:07
Simulated random Poisson data to match the structure of the data for the figure in https://doi.org/10.1001/jamapsychiatry.2020.3938
#===============================================================================
# 2020-11-19 -- pppr
# Testing figure from JAMA Psych 10.1001/jamapsychiatry.2020.3938
# Use Poisson distribution; plot as facets with common scale
# Ilya Kashnitsky, [email protected]
#===============================================================================
library(tidyverse)
library(hrbrthemes)
library(ggeasy)
@ikashnitsky
ikashnitsky / gist:561b5a30f2fb9e0e5666cc01787cc550
Created December 18, 2020 19:02
JAMA Psych pppr – Additional check on the order of data manipulations – https://twitter.com/ikashnitsky/status/1339747476211970048
#===============================================================================
# 2020-11-18 -- JAMA Psych pppr
# Testing figure from 10.1001/jamapsychiatry.2020.3938
# Additional check on the order of data manipulations
# Ilya Kashnitsky, [email protected]
#===============================================================================
library(tidyverse)
library(hrbrthemes)
library(ggeasy)