‘Rain’ visualizations are useful aids to observe the relationship between a ranked, numeric variable (e.g. percentile, rank, etc.) and any factored, categorical variable.
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
armed_levels <- c('No', 'Knife', 'Non-lethal firearm', 'Firearm')
pk <- fivethirtyeight::police_killings %>%
filter(armed %in% armed_levels,
!is.na(age)) %>%
mutate(armed = factor(armed, levels = armed_levels))
pk %>%
d3rain(age, armed, toolTip = raceethnicity, title = "2015 Police Killings by Age, Armed Status") %>%
drip_settings(dripSequence = 'iterate',
ease = 'bounce',
jitterWidth = 20,
dripSpeed = 1000,
dripFill = 'firebrick') %>%
chart_settings(fontFamily = 'times',
yAxisTickLocation = 'left')
pk %>%
arrange(age) %>%
d3rain(age, armed, toolTip = raceethnicity, title = "2015 Police Killings by Age, Armed Status") %>%
drip_settings(dripSequence = 'iterate',
ease = 'linear',
jitterWidth = 25,
dripSpeed = 500,
dripFill = 'steelblue') %>%
chart_settings(fontFamily = 'times',
yAxisTickLocation = 'left')
d <- readr::read_csv("https://raw.githubusercontent.com/babeheim/citation-gates/master/citation-data-simulated.csv") %>%
rename(Downloaded = downloaded,
Contacted = contacted,
Replied = reply_received,
Received = data_received) %>%
mutate(Total = TRUE,
`Downloaded and Received` = case_when(
Downloaded ~ TRUE,
Received ~ TRUE,
TRUE ~ FALSE)
)
## Parsed with column specification:
## cols(
## year = col_double(),
## downloaded = col_logical(),
## contacted = col_logical(),
## reply_received = col_logical(),
## data_received = col_logical()
## )
d %>%
d3rain_hist(x = year,
levels = c("Total", "Contacted", "Replied", "Downloaded and Received"),
title = "Citation Statuses, 1960-2019") %>%
hist_chart_settings(annotations = c("Total Sample: 560", "475 (95%)", "309 (65%)", "147 (26%)"),
levelLabelLocation = "right") %>%
hist_drip_settings(colors = c("black", "forestgreen", "orange", "firebrick"),
transitionIntervals = 2500,
dripSpeed = 300)