Created
May 5, 2017 21:14
-
-
Save rabutler/f6cc887a1dc37a35e2032d6f1b451d32 to your computer and use it in GitHub Desktop.
Returns a generic boxplot legend, using the stat-boxplot-custom code
This file contains 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
library(devtools) | |
library(ggplot2) | |
source_gist("38e70de658b48e166f90", filename = "theme-blank.R") | |
source_gist("bd97a6f49db87860f987156842fd4ee5", filename = "stat-boxplot-custom.R") | |
getBoxplotLegend <- function(qs = c(.05, .25, .5, .75, .95)) { | |
df <- data.frame(x = "a", y = c(-3:1,5:95,99:103)) | |
dfQs <- quantile(df$y, probs = qs) | |
os <- c(mean(c(max(df$y), dfQs[5])), mean(c(min(df$y), dfQs[1]))) | |
gg <- ggplot(df, aes(x, y)) + | |
stat_boxplot_custom(width = .9, qs = qs) + | |
theme_blank() + | |
annotate("text", x = 1.01, y = dfQs[c(1,5)], label = c("5th percentile", "95th percentile"), hjust = 0) + | |
annotate("text", x = 1, y = dfQs[3], label = "Median", vjust = 1) + | |
annotate("text", x = 1.01, y = dfQs[c(2,4)], label = c("25th percentile", "75th percentile"), hjust = 0, vjust = 1) + | |
annotate("text", x = 1.01, y = os, label = "Outliers", hjust = 0) | |
gg | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
theme_blank
from https://gist.github.com/dgrtwo/38e70de658b48e166f90stat_boxplot_custom
from https://gist.github.com/rabutler/bd97a6f49db87860f987156842fd4ee5