Skip to content

Instantly share code, notes, and snippets.

Henrik Lindberg halhen

Block or report user

Report or block halhen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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 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 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 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')
@halhen
halhen / joyplot-atus.R
Last active Jul 17, 2018
The daily grind - viz
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 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 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`))
View ABM-robots.Rmd
---
title: "R Notebook"
output: html_notebook
---
```{r}
library(tidyverse)
library(animation)
@halhen
halhen / codes.csv
Last active May 15, 2019
The people who keep us company - dataviz
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. in line 7.
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
You can’t perform that action at this time.