--- title: "Browsing palettes" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Browsing palettes} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, echo=FALSE} knitr::opts_chunk$set(fig.width = 5) library(paletteNMR) suppressPackageStartupMessages({ library(ggplot2) library(patchwork) }) ``` A full visualization of palettes in the NMR color palette. ### Categorical #### Pairs ```{r pairs} pair_plots <- as.list(1:length(names(nmrPalettes_2020$pair))) for (i in 1:length(names(nmrPalettes_2020$pair))) { pair_plots[[i]] <- draw_palette(scale = "categorical", pal = "pair", set = names(nmrPalettes_2020$pair)[i]) + labs(subtitle = paste0("Pair ", names(nmrPalettes_2020$pair)[i])) + theme(plot.subtitle = element_text(size = rel(0.667))) } wrap_plots(pair_plots, ncol = length(pair_plots)%/%2) ``` #### Quads ```{r quads} quad_plots <- as.list(1:length(names(nmrPalettes_2020$quad))) for (i in 1:length(names(nmrPalettes_2020$quad))) { quad_plots[[i]] <- draw_palette(scale = "categorical", pal = "quad", set = names(nmrPalettes_2020$quad)[i]) + labs(subtitle = paste0("Quad ", names(nmrPalettes_2020$quad)[i])) + theme(plot.subtitle = element_text(size = rel(0.667))) } wrap_plots(quad_plots, ncol = length(quad_plots)%/%2) ``` #### Lines ```{r lines} line_plots <- as.list(1:length(names(nmrPalettes_2020$lines))) for (i in 1:length(names(nmrPalettes_2020$lines))) { line_plots[[i]] <- draw_palette(scale = "categorical", pal = "lines", set = names(nmrPalettes_2020$lines)[i]) + labs(subtitle = paste0("Lines ", names(nmrPalettes_2020$lines)[i])) + theme(plot.subtitle = element_text(size = rel(0.667))) } line_plots[[1]] ``` #### Hex and Hept ```{r hex} hex_plots <- as.list(1:length(names(nmrPalettes_2020$hex))) for (i in 1:length(names(nmrPalettes_2020$hex))) { hex_plots[[i]] <- draw_palette(scale = "categorical", pal = "hex", set = names(nmrPalettes_2020$hex)[i]) + labs(subtitle = paste0("Hex ", names(nmrPalettes_2020$hex)[i])) + theme(plot.subtitle = element_text(size = rel(0.667))) } wrap_plots(hex_plots, ncol = length(hex_plots)%/%2) hept_plots <- as.list(1:length(names(nmrPalettes_2020$hept))) for (i in 1:length(names(nmrPalettes_2020$hept))) { hept_plots[[i]] <- draw_palette(scale = "categorical", pal = "hept", set = names(nmrPalettes_2020$hept)[i]) + labs(subtitle = paste0("Hept ", names(nmrPalettes_2020$hept)[i])) + theme(plot.subtitle = element_text(size = rel(0.667))) } hept_plots[[1]] ``` #### Maps ```{r map} map_plots <- as.list(1:length(names(nmrPalettes_2020$map))) for (i in 1:length(names(nmrPalettes_2020$map))) { map_plots[[i]] <- draw_palette(scale = "categorical", pal = "map", set = names(nmrPalettes_2020$map)[i]) + labs(subtitle = paste0("Map ", names(nmrPalettes_2020$map)[i])) + theme(plot.subtitle = element_text(size = rel(0.667))) } wrap_plots(map_plots, ncol = length(map_plots)%/%2) ``` ### Numerical #### Non-divergent ```{r sequential} nondiverg_plots <- as.list(1:length(names(nmrPalettes_2020$nondiverg))) for (i in 1:length(names(nmrPalettes_2020$nondiverg))) { nondiverg_plots[[i]] <- draw_palette(scale = "numerical", pal = "nondiverg", set = names(nmrPalettes_2020$nondiverg)[i]) + labs(subtitle = paste0("Nondiverg ", names(nmrPalettes_2020$nondiverg)[i])) + theme(plot.subtitle = element_text(size = rel(0.667))) } wrap_plots(nondiverg_plots, ncol = 4) ``` If you need a continuous scale, consider the "Viridis" scale, available via the `colorspace` package. ```{r nondiv_colorspace, fig.height=2} colorspace::hcl_palettes("Sequential (multi-hue)", "Viridis") |> plot() ``` #### Divergent ```{r divergent} diverg_plots <- as.list(1:length(names(nmrPalettes_2020$diverg))) for (i in 1:length(names(nmrPalettes_2020$diverg))) { diverg_plots[[i]] <- draw_palette(scale = "numerical", pal = "diverg", set = names(nmrPalettes_2020$diverg)[i]) + labs(subtitle = paste0("Diverg ", names(nmrPalettes_2020$diverg)[i])) + theme(plot.subtitle = element_text(size = rel(0.667))) } wrap_plots(diverg_plots, ncol = 4) ``` If you need a continuous scale, consider the "Green-Brown" scale from Color Brewer, available via the `colorspace` package ```{r div_colorspace, fig.height=2} colorspace::hcl_palettes("diverging", "Green-Brown") |> plot() ``` #### Orthogonal ```{r ortho} list(draw_palette(scale = "numerical", pal = "ortho", set = "All", index = 1:3), draw_palette(scale = "numerical", pal = "ortho", set = "All", index = 4:6), draw_palette(scale = "numerical", pal = "ortho", set = "All", index = 7:9)) |> wrap_plots(ncol = 3) ``` ### Extras ```{r descr_numextras} extra_colors <- nmrColors_2020$hex[nmrColors_2020$color_id %in% c("R1", "K0", "K4")] data.frame(hex = extra_colors) |> ggplot(aes(fill = hex)) + facet_wrap( ~ hex, ncol = 1) + geom_rect(aes(xmin = 1, xmax = 2, ymin = 1, ymax = 2)) + lims(x=c(1,2),y=c(1,2)) + scale_fill_manual(values = as.character(extra_colors), guide = "none") + theme(axis.text = element_blank(), axis.ticks = element_blank(), panel.grid = element_blank(), panel.spacing = unit(-0.5, "lines"), plot.margin = unit(c(0,-0.25,0,-0.25), "lines"), strip.background = element_blank(), strip.text = element_blank()) + labs(subtitle = "Extras") ``` ## Additional palettes Useful when we have to prepare reporting for other firms' reports. ```{r addl} wrap_plots(draw_palette(scale = "categorical", pal = "MainColors", set = "All", pal_df = neeaPalettes_2017) + labs(subtitle = "NEEA MRE 2017"), draw_palette(scale = "categorical", pal = "MainColors", set = "All", pal_df = nexantPalettes_2017) + labs(subtitle = "Nexant 2017"), ncol = 2) ```