This file contains hidden or 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
| # 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) |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| DT[ | |
| id %in% 200:300, | |
| .(reg.val = sum(value)), | |
| by=region | |
| ][ | |
| reg.val > 0, | |
| range(reg.val) | |
| ] |