-
-
Save meyera/4903913820d3e5c1f17cd3e8ff83a703 to your computer and use it in GitHub Desktop.
viridis color/fill scales for ggplot2
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
viridis_pal <- function(alpha=1) { | |
function(n) { | |
viridis(n, alpha) | |
} | |
} | |
scale_color_viridis <- function(..., alpha=1, discrete=TRUE) { | |
if (discrete) { | |
discrete_scale("colour", "viridis", viridis_pal(alpha), ...) | |
} else { | |
scale_color_gradientn(colours = viridis(256, alpha), ...) | |
} | |
} | |
scale_fill_viridis <- function (..., alpha=1, discrete=TRUE) { | |
if (discrete) { | |
discrete_scale("fill", "viridis", viridis_pal(alpha), ...) | |
} else { | |
scale_fill_gradientn(colours = viridis(256, alpha), ...) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment