Skip to content

Instantly share code, notes, and snippets.

View danielreispereira's full-sized avatar
💭
I may be slow to respond.

Daniel danielreispereira

💭
I may be slow to respond.
View GitHub Profile
@tomhopper
tomhopper / align_common_baseline.R
Last active November 5, 2016 17:47
Examples of aligning against a common baseline, using Cleveland-style dot plots
# Response to a post at Storytelling with Data:
# \url{http://www.storytellingwithdata.com/blog/orytellingwithdata.com/2015/07/align-against-common-baseline.html}
# Demonstrates
# * Cleveland-style dot plots (improvement over pie and bar charts)
# * Sorting categorical data by a numerical variable with more than one grouping variable
# * Highlighting differences between groups graphically
library(ggplot2)
library(scales)
@gavinsimpson
gavinsimpson / genURLS.R
Last active November 6, 2018 16:13
Functions to automate downloading data from the Government of Canada's Climate/Weather website
genURLS <- function(id, start, end, timeframe = c("hourly", "daily", "monthly")) {
years <- seq(start, end, by = 1)
nyears <- length(years)
timeframe <- match.arg(timeframe)
if (isTRUE(all.equal(timeframe, "hourly"))) {
years <- rep(years, each = 12)
months <- rep(1:12, times = nyears)
ids <- rep(id, nyears * 12)
} else if (isTRUE(all.equal(timeframe, "daily"))) {
months <- 1 # this is essentially arbitrary & ignored if daily
DT[
id %in% 200:300,
.(reg.val = sum(value)),
by=region
][
reg.val > 0,
range(reg.val)
]