knitr::opts_chunk$set(echo = TRUE) library(nucolors) library(dplyr) library(ggplot2) library(scales)
This is a package to use NU colors in ggplot graphs.
#Discrete w/ default palette diamonds %>% ggplot(aes(x=color, y=price, fill=color)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_disc() #Discrete w/ default palette reversed diamonds %>% ggplot(aes(x=color, y=price, fill=color)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_disc(reverse=T) #Discrete w/ default palette and reversed outlines diamonds %>% ggplot(aes(x=color, y=price, fill=color, color=color)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_disc() + scale_color_nu_disc(reverse=T) #Discrete w/ secondary palette diamonds %>% ggplot(aes(x=color, y=price, fill=color)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_disc(secondary=6) #Discrete w/ reversed secondary palette (nu primary colors remain the same) diamonds %>% ggplot(aes(x=color, y=price, fill=color)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_disc(secondary=6, reverse=T) #Continuous w/ purple-gray gradient mtcars %>% ggplot(aes(x=carb, y=mpg, fill=carb)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_grd(reverse=F) #Continuous w/ midpoint gradient at value 4 mtcars %>% ggplot(aes(x=carb, y=mpg, fill=carb)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_grd2(midpoint=4) #Continuous w/ n numbered gradient mtcars %>% ggplot(aes(x=carb, y=mpg, fill=carb)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_grdn(secondary=2, reverse=T, purple='high', n=4) #Continuous w/ n numbered gradient with purple as the low end mtcars %>% ggplot(aes(x=carb, y=mpg, fill=carb)) + stat_summary(fun.y='mean',geom='bar')+ scale_fill_nu_grdn(secondary=2, reverse=T, purple='low', n=4)
c('#4E2A84','#836EAA','#716C6B','#342F2E','#B6ACD1','#BBB8B8','#E4E0EE','#401F68','#D8D6D6') %>% show_col()
for(i in 1:10){ show_col(get_sec_pal(i)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.