Skip to content

Instantly share code, notes, and snippets.

View DaveParr's full-sized avatar

Dave Parr DaveParr

View GitHub Profile
@DaveParr
DaveParr / miniCRAN.R
Created January 19, 2017 09:19 — forked from stephlocke/miniCRAN.R
Getting a local CRAN that combines internal and external packages
## ------------------------------------------------------------------------
# Set the repo for use throughout
cran <- "https://cran.rstudio.org"
# Install
if(!require(miniCRAN)){
install.packages("miniCRAN", repos = cran)
}
## ------------------------------------------------------------------------
@DaveParr
DaveParr / pokePlot.R
Created March 3, 2016 16:20 — forked from dsparks/pokePlot.R
Ridiculous Pokemon plot
# Truly the most ridiculous thing I could think of.
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("XML", "png", "devtools", "RCurl")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Some helper functions, lineFinder and makeTable
source_gist("818983")
source_gist("818986")
#' When plotting multiple data series that share a common x axis but different y axes,
#' we can just plot each graph separately. This suffers from the drawback that the shared axis will typically
#' not align across graphs due to different plot margins.
#' One easy solution is to reshape2::melt() the data and use ggplot2's facet_grid() mapping. However, there is
#' no way to label individual y axes.
#' facet_grid() and facet_wrap() were designed to plot small multiples, where both x- and y-axis ranges are
#' shared acros all plots in the facetting. While the facet_ calls allow us to use different scales with
#' the \code{scales = "free"} argument, they should not be used this way.
#' A more robust approach is to the grid package grid.draw(), rbind() and ggplotGrob() to create a grid of
#' individual plots where the plot axes are properly aligned within the grid.