#PALETA---- library(ggplot2) barbacil_colors <- c( `red` = "#d11141", `green` = "#00b159", `light green`= "#ADFF2F", `pale green` = "#5ED893", `blue` = "#1E90FF", `bluee` ="#5C0F6F", `dark blue` = "#00008B", `orange` = "#FFA500", `yellow` = "#ffc425", `violet` = "#8A2BE2", `light grey` = "#DCDCDC", `dark grey` = "#808080", `black` = "#000000", `pale green thesis` = "#e6ffdc", `green thesis` = "#5ED893", `blue thesis` = "#1874cd", `dark blue thesis` = "#002060", `yellow thesis` = "#FFFFCC", `white thesis` = "#FFFFFF" ) barbacil_cols <- function(...) { cols <- c(...) if (is.null(cols)) return (barbacil_colors) barbacil_colors[cols] } barbacil_palettes <- list( `main` = barbacil_cols("blue", "green", "yellow"), `electric` = barbacil_cols("light green","blue", "dark blue"), `nature` = barbacil_cols("pale green","bluee"), `fire` = barbacil_cols("yellow", "orange", "red"), `citric` = barbacil_cols("green","yellow", "orange"), `trafficlight` = barbacil_cols("green","yellow", "orange","red"), `mixed` = barbacil_cols("blue", "green", "yellow", "red","violet"), `grey` = barbacil_cols("White thesis", "black"), `thesis` = barbacil_cols("blue thesis","green thesis","yellow thesis"), `thesis_2` = barbacil_cols("blue thesis", "white thesis","green thesis","yellow thesis")) barbacil_pal <- function(palette = "main", reverse = FALSE, ...) { pal <- barbacil_palettes[[palette]] if (reverse) pal <- rev(pal) colorRampPalette(pal, ...) } #' Color scale constructor for drsimonj colors #' #' @param palette Character name of palette in drsimonj_palettes #' @param discrete Boolean indicating whether color aesthetic is discrete or not #' @param reverse Boolean indicating whether the palette should be reversed #' @param ... Additional arguments passed to discrete_scale() or #' scale_color_gradientn(), used respectively when discrete is TRUE or FALSE #' scale_color_barbacil <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) { pal <- barbacil_pal(palette = palette, reverse = reverse) if (discrete) { discrete_scale("colour", paste0("barbacil_", palette), palette = pal, ...) } else { scale_color_gradientn(colours = pal(256), ...) } } #' Fill scale constructor for drsimonj colors #' #' @param palette Character name of palette in drsimonj_palettes #' @param discrete Boolean indicating whether color aesthetic is discrete or not #' @param reverse Boolean indicating whether the palette should be reversed #' @param ... Additional arguments passed to discrete_scale() or #' scale_fill_gradientn(), used respectively when discrete is TRUE or FALSE #' scale_fill_barbacil <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) { pal <- barbacil_pal(palette = palette, reverse = reverse) if (discrete) { discrete_scale("fill", paste0("barbacil_", palette), palette = pal, ...) } else { scale_fill_gradientn(colours = pal(256), ...) } } #EXAMPLES---- barbacil_cols() barbacil_cols("red") barbacil_cols("red", "blue") barbacil_pal("nature") barbacil_pal("nature")(10) ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) + geom_point(size = 4, alpha = .6) + scale_color_barbacil(discrete = FALSE, palette = "main") ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) + geom_point(size = 4, alpha = .6) + scale_color_barbacil(discrete = FALSE, palette = "nature") ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) + geom_point(size = 4, alpha = .6) + scale_color_barbacil(discrete = FALSE, palette = "electric") ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) + geom_point(size = 4, alpha = .6) + scale_color_barbacil(discrete = FALSE, palette = "fire") ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) + geom_point(size = 4, alpha = .6) + scale_color_barbacil(discrete = FALSE, palette = "citric") ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) + geom_point(size = 4, alpha = .6) + scale_color_barbacil(discrete = FALSE, palette = "trafficlight") ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) + geom_point(size = 4, alpha = .6) + scale_color_barbacil(discrete = FALSE, palette = "mixed") ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) + geom_point(size = 4, alpha = .6) + scale_color_barbacil(discrete = FALSE, palette = "grey") ggplot(mpg, aes(manufacturer, fill = manufacturer)) + geom_bar() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + scale_fill_barbacil(palette = "mixed", guide = "none")