View chart.R
HEIGHT <- 50 # points per column
closing_df[rep(1:nrow(closing_df), closing_df$total), ] %>%
group_by(store) %>%
mutate(rank = row_number() - 1) %>%
mutate(x = rank %/% HEIGHT,
y = rank %% HEIGHT + 0.5) %>%
arrange(y, x) %>%
mutate(rank = row_number() - 1,
View europe.R
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)
View elevation.R
# Download elevation tif from eg http://www.eea.europa.eu/data-and-maps/data/digital-elevation-model-of-europe
# First, convert elevation tif to a space delimited xyz (lng lat elevation) file
# $ gdal_translate -of XYZ elevation3x3.tif /tmp/file.xyz
df <- read_delim('/tmp/file.xyz', delim=' ', col_names=FALSE)
df %>%
mutate(X3 = na_if(X3, 0)) %>%
ggplot(aes(X1, -X2 + 20 * X3/max(X3, na.rm=TRUE), group=X2)) +
geom_line(size=0.05) +
View joyplot-atus.R
library(tidyverse)
# data from https://www.kaggle.com/bls/american-time-use-survey
df.resp <- read_csv('../data/atus/atusresp.csv')
df.act <- read_csv('../data/atus/atusact.csv', col_types=cols(tustarttim = col_character(), tustoptime = col_character()))
df.sum <- read_csv('../data/atus/atussum.csv')
df.tmp <- df.act %>%
mutate(activity = case_when(trtier2p == 1301 ~ 'Exercise',
View atus-tidytext.R
# Data from https://www.kaggle.com/bls/american-time-use-survey
library(tidyverse)
library(tidytext)
# Contains both 1st and 2nd level codes; collisions won't appear though since 1-99 is tier 1 and 100+ is two
df.names <- read_csv2('../data/atus/codes.csv') %>%
mutate(code = as.integer(code))
df.resp <- read_csv('../data/atus/atusresp.csv')
View GTI.r
library(htmltab)
library(tidyverse)
library(stringr)
URL <- 'https://en.wikipedia.org/w/index.php?title=Global_Terrorism_Index&oldid=779504863'
df <- htmltab(URL, 5) %>%
transmute(Country = str_trim(Country),
score = as.numeric(Score))
View codes.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 1 column, instead of 2.
code;name
01;Personal Care Activities
0101;Sleeping
0102;Grooming
0103;Health-related self care
0104;Personal Activities
0105;Personal Care Emergencies
0199;Personal care, n.e.c.*
02;Household Activities
0201;Housework
View weather.R
# Pasted from various sources and published quickly as part of a twitter discussion; not tested if this copy/paste actually runs.
# Result as https://twitter.com/hnrklndbrg/status/859888911337873409
library(tidyverse)
library(lubridate)
df.recent <- read_csv2('/home/henrik/private/vizyns/data/väder/göteborg-a-20170502.csv', skip=15) %>%
transmute(date=`Representativt dygn`,
min=as.numeric(`Lufttemperatur`),
max=as.numeric(`Lufttemperatur_1`))