Skip to content

Instantly share code, notes, and snippets.

View burchill's full-sized avatar
💭
I love my default GitHub picture

Zach Burchill burchill

💭
I love my default GitHub picture
View GitHub Profile
@burchill
burchill / set_scales_constant.R
Last active September 14, 2022 15:17
Set continuous scales to be identical across ggplot2 plots automatically
# Check https://www.zachburchill.ml/constant_scales/ for a walkthrough.
# Note that this code is slightly "better" than the code in the post, since it checks
# to see if the scales being supplied and used are all continuous.
# Examples included after the function definitions.
# Given a bunch of plots and a scale you want to apply to them, this returns that scale,
# but with limits that encompass the union of all the ranges of values in those plots
# Meant to be for users
get_shared_scale <- function(..., scale) {
@burchill
burchill / geom_segment_plus.R
Last active November 30, 2021 18:40
Updated geom_segment_plus
# an updated version of https://pastebin.com/0BRwUzpu by SO user mo-seph (https://stackoverflow.com/a/14692588/4560765)
# The version above no longer works
#' # The example:
#' points <- data.frame( x=runif(10), y=runif(10),class=1:10, size=runif(10,min=1000,max=100000) )
#' trans <- data.frame( from=rep(1:10,times=10), to=rep(1:10,each=10), amount=runif(100)^3 )
#' trans <- merge( trans, points, by.x="from", by.y="class" )
#' trans <- merge( trans, points, by.x="to", by.y="class", suffixes=c(".to",".from") )
#' ggplot( points, aes( x=x, y=y ) ) + geom_point(aes(size=size),color="red",shape=1) +
#' scale_size_continuous(range=c(4,20)) +