#FILLS
#' Discrete Fill
#'
#' Fills discrete values with the main NU palette by default.
#' @param secondary takes values between 1 and 10 to pick which official secondary palette you want
#' @param reverse will change the direction of the colors
#' @return A scale_fill_manual gg primitive
#'
#' @export
scale_fill_nu_disc <- function(secondary=0,reverse=F,...){
if(secondary){
if(reverse) pal = c('#4E2A84',rev(get_sec_pal(secondary)),'#BBB8B8','#342F2E','#716C6B')
else pal = c('#4E2A84',get_sec_pal(secondary),'#BBB8B8','#342F2E','#716C6B')
return(ggplot2::scale_fill_manual(values=pal,...))
}
else {pal = c('#4E2A84','#716C6B','#B6ACD1','#342F2E','#836EAA','#BBB8B8','#E4E0EE','#401F68','#D8D6D6')}
if(reverse) return(ggplot2::scale_fill_manual(values=rev(pal),...))
return(ggplot2::scale_fill_manual(values=pal,...))
}
#' Continuous Fill Gradient
#'
#' Fills continuous values with an NU Purple to Gray gradient.
#' @param reverse will change the direction of the colors
#' @return A scale_fill_gradient gg primitive
#'
#' @export
scale_fill_nu_grd <- function(reverse=F,...){
if(reverse) return(ggplot2::scale_fill_gradient(low='#4E2A84',high='#BBB8B8'))
return(ggplot2::scale_fill_gradient(high='#4E2A84',low='#BBB8B8'))
}
#' Continuous Fill Gradient2
#'
#' Fills continuous values with a gradient with a midpoint.
#' @param midpoint is passed along via ellipsis, it needs to be manually set for your specific data
#' @param reverse will change the direction of the colors
#' @return A scale_fill_gradient2 gg primitive
#'
#' @export
scale_fill_nu_grd2 <- function(reverse=F,...){
if(reverse) return(ggplot2::scale_fill_gradient2(low='#4E2A84',mid='#BBB8B8',high='#342F2E',...))
return(ggplot2::scale_fill_gradient2(high='#4E2A84',mid='#BBB8B8',low='#342F2E',...))
}
#' Continous Fill Gradient N
#'
#' Fills continuous values with a gradient of n colors
#' @param secondary takes values between 1 and 10 to pick which official secondary palette you want
#' @param reverse will change the direction of the colors
#' @param n will determine how many colors you want (limited to 5)
#' @param purple will change the location of NU purple. 'high' sets it to the high end,
#' 'low' to the low end, anything else will remove it
#' @return A scale_fill_manual gg primitive
#'
#' @export
scale_fill_nu_grdn <- function(secondary=0,reverse=F,n=2,purple='high'){
if(secondary){
if(reverse) pal = rev(get_sec_pal(secondary))
else pal = get_sec_pal(secondary)
if(purple=='high') pal = c(pal[1:n-1], '#4E2A84')
else if(purple=='low') pal = c('#4E2A84', pal[1:n-1])
else pal = pal[1:n]
return(ggplot2::scale_fill_gradientn(colors=pal))
}
else pal = c('#4E2A84','#BBB8B8','#342F2E','#B6ACD1','#401F68')
if(reverse) return(ggplot2::scale_fill_gradientn(colors=rev(pal[1:n])))
return(ggplot2::scale_fill_gradientn(colors=pal[1:n]))
}
#COLORS
#' Discrete Color
#'
#' Sets discrete color values with the main NU palette by default.
#' @param secondary takes values between 1 and 10 to pick which official secondary palette you want
#' @param reverse will change the direction of the colors
#' @return A scale_fill_manual gg primitive
#'
#' @export
#' @export
scale_color_nu_disc <- function(secondary=0,reverse=F,...){
if(secondary){
if(reverse) pal = c('#4E2A84',rev(get_sec_pal(secondary)),'#BBB8B8','#342F2E','#716C6B')
else pal = c('#4E2A84',get_sec_pal(secondary),'#BBB8B8','#342F2E','#716C6B')
return(ggplot2::scale_color_manual(values=pal,...))
}
else {pal = c('#4E2A84','#716C6B','#B6ACD1','#342F2E','#836EAA','#BBB8B8','#E4E0EE','#401F68','#D8D6D6')}
if(reverse) return(ggplot2::scale_color_manual(values=rev(pal),...))
return(ggplot2::scale_color_manual(values=pal,...))
}
#' Continuous Color Gradient
#'
#' Sets continuous color values with an NU Purple to Gray gradient.
#' @param reverse will change the direction of the colors
#' @return A scale_fill_gradient gg primitive
#'
#' @export
scale_color_nu_grd <- function(reverse=F,...){
if(reverse) return(ggplot2::scale_color_gradient(low='#4E2A84',high='#BBB8B8'))
return(ggplot2::scale_color_gradient(high='#4E2A84',low='#BBB8B8'))
}
#' Continuous Color Gradient2
#'
#' Sets continuous color values with a gradient with a midpoint.
#' @param midpoint is passed along via ellipsis, it needs to be manually set for your specific data
#' @param reverse will change the direction of the colors
#' @return A scale_fill_gradient2 gg primitive
#'
#' @export
scale_color_nu_grd2 <- function(reverse=F,...){
if(reverse) return(ggplot2::scale_color_gradient2(low='#4E2A84',mid='#BBB8B8',high='#342F2E',...))
return(ggplot2::scale_color_gradient2(high='#4E2A84',mid='#BBB8B8',low='#342F2E',...))
}
#' Continous Color Gradient N
#'
#' Sets continuous color values with a gradient of n colors
#' @param secondary takes values between 1 and 10 to pick which official secondary palette you want
#' @param reverse will change the direction of the colors
#' @param n will determine how many colors you want (limited to 5)
#' @param purple will change the location of NU purple. 'high' sets it to the high end,
#' 'low' to the low end, anything else will remove it
#' @return A scale_fill_manual gg primitive
#'
#' @export
scale_color_nu_gradientn <- function(secondary=0,reverse=F,n=2,purple='high'){
if(secondary){
if(reverse) pal = rev(get_sec_pal(secondary))
else pal = get_sec_pal(secondary)
if(purple=='high') pal = c(pal[1:n-1], '#4E2A84')
else if(purple=='low') pal = c('#4E2A84', pal[1:n-1])
else pal = pal[1:n]
return(ggplot2::scale_color_gradientn(colors=pal))
}
else pal = c('#4E2A84','#BBB8B8','#342F2E','#B6ACD1','#401F68')
if(reverse) return(ggplot2::scale_fill_gradientn(colors=rev(pal[1:n])))
return(ggplot2::scale_color_gradientn(colors=pal[1:n]))
}
#HELPERS
#' Get Secondary Palette Colors
#'
#' Returns a secondary palette. Used in some of the functions, but you can use
#' it yourself if you want to for some reason!
#' @param selection takes values 1-10 to select a secondary palette
#' @return a list of colors, each palette has 4.
#'
#' @export
get_sec_pal <- function(selection){
secondary_palettes <-list(c('#7FCECD', '#58B947', '#EDE93B', '#FFC520'),
c('#5091CD', '#7FCECD', '#EDE93B', '#EF553F'),
c('#007FA4', '#008656', '#D9C826', '#CA7C1B'),
c('#0D2D6C', '#007FA4', '#CA7C1B', '#D85820'),
c('#0D2D6C', '#5091CD', '#FFC520', '#EF553F'),
c('#007FA4', '#7FCECD', '#D9C826', '#CA7C1B'),
c('#007FA4', '#5091CD', '#EF553F', '#CA7C1B'),
c('#D85820', '#EF553F', '#CA7C1B', '#FFC520'),
c('#0D2D6C', '#007FA4', '#5091CD', '#7FCECD'),
c('#0D2D6C', '#58B947', '#5091CD', '#D85820'))
return(secondary_palettes[[selection]])
}
nupurple <- function(selection){
nupurples = c("#1D3502", #160,
"#264108", #150
"#304E10", #140
"#385A17", #130
"#401F68", #120
"#487625", #110
"#4E842A", #100
"#5B3B8C", #90
"#684C96", #80
"#76A05D", #70
"#83AA6E", #60
"#93B680", #50
"#A4C395", #40
"#B6D1Ac", #30
"#CCDFC4", #20
"#E4EEE0", #10
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.