This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "ggplot tutorial" | |
subtitle: "with kunoichi + ninjutsu theme" | |
author: "<br><br> Emi Tanaka" | |
date: "<br>2018/09/16" | |
output: | |
xaringan::moon_reader: | |
lib_dir: libs | |
css: ["kunoichi", "ninjutsu"] | |
nature: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the party logos are required to be in the form of `plogo-XXX.png` where XXX is the party abbreviation that matches | |
# in PartyAb | |
# inspired by https://coolbutuseless.github.io/2020/04/12/racing-barplots-with-ggpattern-flagon-gganimate/ | |
library(tidyverse) | |
library(gganimate) | |
library(ggpattern) | |
dat <- read_csv("https://results.aec.gov.au/24310/Website/Downloads/HouseDopByDivisionDownload-24310.csv", skip = 1) %>% | |
mutate(PartyAb = case_when( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
income_df <- tibble(income_range = c("0-74", "75-145", "150-325", "325+"), | |
count = c(125, 170, 215, 250)) %>% | |
separate(income_range, | |
into = c("income_min", "income_max"), | |
convert = TRUE) | |
calc_median_income <- function(df) { | |
df %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
as_tidymatrix <- function(x){ | |
structure(list(.value = as.vector(x), | |
.row = as.vector(row(x)), | |
.col = as.vector(col(x))), | |
row.names = seq_len(length(as.vector(x))), | |
nrow = nrow(x), # need these attribute if storing it as sparse later | |
ncol = ncol(x), | |
class = c("tidymatrix", "data.frame")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- structure(list(x = 1), "attr" = 2) | |
y <- structure(list(y = 3), "attr" = 1) | |
l <- list(x, y) | |
out <- do.call(c, l) | |
# doesn't quite work (notice the name) | |
out2 <- lapply(seq_along(out), function(i) { | |
attributes(out[[i]]) <- attributes(l[[i]]) | |
out[[i]] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(tidyverse) # ggplot2, tidyr, dplyr, purrr, stringr ... | |
library(scales) | |
library(grid) | |
library(RColorBrewer) | |
############################################################### | |
## MOST COMMON ACTIONS DURING FIRST TWO WEEKS | |
############################################################### | |
## IMPORT AND TIDY DATA |
OlderNewer