diff --git a/DESCRIPTION b/DESCRIPTION index ddb5f66..2b2d450 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,5 +17,6 @@ Imports: ggplot2, grDevices, jsonlite, + plotwidgets, showtext, sysfonts diff --git a/NAMESPACE b/NAMESPACE index ef7d0e7..e094c9b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(ggnorad) +export(norad_gradient) export(norad_pal) export(scale_color_norad) export(scale_color_norad_c) diff --git a/R/palette_functions.R b/R/palette_functions.R index 75e07e8..0adf535 100644 --- a/R/palette_functions.R +++ b/R/palette_functions.R @@ -1,3 +1,30 @@ +#' Gradient color constructor for Norad colors +#' +#' @param n Number of colors +#' @export + + +norad_gradient <- function(n) { + stopifnot("n must be greater than zero" = n > 0) + color_high <- "#1B3A1C" + color_high_hsl <- plotwidgets::col2hsl(color_high) + color_low_hsl <- color_high_hsl + color_low_hsl[3] <- 1 - (1 - color_high_hsl[3])*0.1 # 90 % lighter + color_low <- plotwidgets::hsl2col(color_low_hsl) + + if (n > 2) { + colorramp <- vector("character", length = n) + lightness_steps <- (color_low_hsl[3] - color_high_hsl[3]) / (n - 1) + for(i in 1:n) { + color_hsl <- color_high_hsl + color_hsl[3] <- color_high_hsl[3] + lightness_steps*(i - 1) + colorramp[i] <- plotwidgets::hsl2col(color_hsl) + } + } else { + colorramp <- c(color_low, color_high) + } + return(colorramp) +} #' Function to extract Norad colors as hex codes #' diff --git a/R/style_functions.R b/R/style_functions.R index 707fc3f..e0c7dd7 100644 --- a/R/style_functions.R +++ b/R/style_functions.R @@ -25,10 +25,11 @@ theme_norad <- function() { plot.subtitle = ggplot2::element_text( size = 14, hjust = 0, - margin = ggplot2::margin(t = 5, b = 5)), + margin = ggplot2::margin(t = 5, b = 15)), # Plot caption plot.caption.position = "plot", plot.caption = ggplot2::element_text( + family = serif, size = 12, hjust = 0, margin = ggplot2::margin(t = 10)), diff --git a/man/norad_gradient.Rd b/man/norad_gradient.Rd new file mode 100644 index 0000000..1b50468 --- /dev/null +++ b/man/norad_gradient.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/palette_functions.R +\name{norad_gradient} +\alias{norad_gradient} +\title{Gradient color scale constructor for Norad colors} +\usage{ +norad_gradient(n) +} +\arguments{ +\item{n}{Number of colors} +} +\description{ +Gradient color scale constructor for Norad colors +}