Skip to content

Commit

Permalink
Merge pull request #15 from noradno/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
einartornes authored Mar 27, 2023
2 parents 5165dd3 + f7a4aba commit 23e702a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Imports:
ggplot2,
grDevices,
jsonlite,
plotwidgets,
showtext,
sysfonts
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
27 changes: 27 additions & 0 deletions R/palette_functions.R
Original file line number Diff line number Diff line change
@@ -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
#'
Expand Down
3 changes: 2 additions & 1 deletion R/style_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
14 changes: 14 additions & 0 deletions man/norad_gradient.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23e702a

Please sign in to comment.