Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map styles #20

Merged
merged 10 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: noradplot
Type: Package
Title: Norad colour palette and theme for ggplot2 graphics
Version: 0.4.0
Version: 0.5.0
Authors@R: c(
person("Einar", "Tornes", email = "[email protected]", role = c("aut", "cre")),
person("Eivind", "Hammersmark", "Moe", email = "[email protected]", role = "aut"),
Expand Down
15 changes: 14 additions & 1 deletion R/ggnorad.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ggnorad <- function(style = "default") {

showtext::showtext_auto()

options(scipen = 999)
fonts_dir <- system.file("fonts", package = "noradplot")
sysfonts::font_add(family = "Norad Sans",
regular = paste0(fonts_dir, "/NoradSans-Regular.otf"),
Expand All @@ -26,16 +27,28 @@ ggnorad <- function(style = "default") {
bold = paste0(fonts_dir, "/NoradDisplay-Bold.otf"),
italic = paste0(fonts_dir, "/NoradDisplay-BoldItalic.otf"))

sysfonts::font_add(family = "Arial",
regular = paste0(fonts_dir, "/arial.ttf"),
bold = paste0(fonts_dir, "/arialbd.ttf"),
italic = paste0(fonts_dir, "/ariali.ttf"),
bolditalic = paste0(fonts_dir, "/arialbi.ttf"))

ggplot2::update_geom_defaults("path", list(linewidth = 1))

if (style == "default") {
ggplot2::theme_set(theme_norad())
} else if (style == "biglight1") {
} else if (style == "light") {
ggplot2::theme_set(theme_norad_light_green())
} else if (style == "biglight1") {
ggplot2::theme_set(theme_norad_big_light_1())
} else if (style == "biglight2") {
ggplot2::theme_set(theme_norad_big_light_2())
} else if (style == "bigdark") {
warning("This style is high contrast. Use additional visual elements with care.")
ggplot2::theme_set(theme_norad_big_dark())
} else if (style == "maplight") {
ggplot2::theme_set(theme_norad_map_light())
} else if (style == "mapdark") {
ggplot2::theme_set(theme_norad_map_dark())
}
}
194 changes: 157 additions & 37 deletions R/style_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,49 @@
#'
#'@export


theme_norad <- function() {
sans <- "Norad Sans"
serif <- "Norad Serif"
arial <- "Arial"

ggplot2::theme_classic() +
ggplot2::theme(
# General text
text = ggplot2::element_text(
family = sans, # default unless otherwise stated (like in plot.title)
family = arial, # default unless otherwise stated (like in plot.title)
size = 12
),
# Plot title and subtitle
plot.title.position = "plot",
plot.title = ggplot2::element_text(
family = serif,
size = 20,
size = 16,
face = "bold",
hjust = 0),
hjust = 0
),
plot.subtitle = ggplot2::element_text(
family = sans,
size = 14,
hjust = 0,
margin = ggplot2::margin(t = 5, b = 15)),
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)),
margin = ggplot2::margin(t = 10)
),
# Legend
legend.text = ggplot2::element_text(
size = 12),
family = sans,
size = 12
),
legend.title = ggplot2::element_text(
size = 12),
family = sans,
size = 12
),
legend.position = "right",
legend.justification = "top",
legend.margin = ggplot2::margin(r = 30),
Expand All @@ -49,12 +57,35 @@ theme_norad <- function() {
color = "black"
),
axis.title = ggplot2::element_text(
family = sans,
size = 12
),
axis.title.y = ggplot2::element_text(margin = ggplot2::margin(r = 5)),
axis.title.x = ggplot2::element_text(margin = ggplot2::margin(t = 10)),
axis.text.y = ggplot2::element_text(margin = ggplot2::margin(r = 5)),
axis.text.x = ggplot2::element_text(margin = ggplot2::margin(t = 10))
axis.text.x = ggplot2::element_text(margin = ggplot2::margin(t = 10)),
plot.margin = ggplot2::margin(15, 5.5, 15, 5.5, "pt")
)
}

#' Function for using Norad's theme in ggplot2 graphics
#'
#'@export

theme_norad_light_green <- function() {
sans <- "Norad Sans"
serif <- "Norad Serif"
arial <- "Arial"

theme_norad() +
ggplot2::theme(
# Plot and panel background
panel.background = element_rect(fill = "transparent"), #transparent panel bg
plot.background = element_rect(fill = "transparent", color = NA), #transparent plot bg
panel.grid.major = element_blank(), #remove major gridlines
panel.grid.minor = element_blank(), #remove minor gridlines
legend.background = element_rect(fill = "transparent", color = NA), #transparent legend bg
legend.box.background = element_rect(fill = "transparent", color = NA) #transparent legend panel
)
}

Expand All @@ -66,24 +97,31 @@ theme_norad_big_light_1 <- function() {
sans <- "Norad Sans"
serif <- "Norad Serif"
display <- "Norad Display"
arial <- "Arial"

ggplot2::theme_classic() +
ggplot2::theme(
# General text
text = ggplot2::element_text(
family = sans, # default unless otherwise stated (like in plot.title)
family = arial, # default unless otherwise stated (like in plot.title)
size = 12,
color = norad_cols("green")
),
# Plot title and subtitle
plot.title.position = "plot",
plot.title = ggplot2::element_blank(),
plot.subtitle = ggplot2::element_blank(),
plot.title = ggplot2::element_text(
family = sans,
size = 16
),
plot.subtitle = ggplot2::element_text(
family = sans,
size = 14,
margin = ggplot2::margin(t = 5, b = 20)
),
# Plot caption
plot.caption.position = "plot",
plot.caption = ggplot2::element_text(
family = serif,
size = 20,
hjust = 0,
margin = ggplot2::margin(t = 10)),
# Legend
Expand All @@ -97,19 +135,35 @@ theme_norad_big_light_1 <- function() {
legend.text.align = 0,
legend.background = ggplot2::element_blank(),
# Axes
axis.text = ggplot2::element_text(size = 20, color = norad_cols("green")),
axis.title = ggplot2::element_text(size = 20),
axis.title.y = ggplot2::element_text(margin = ggplot2::margin(r = 5)),
axis.text = ggplot2::element_text(
size = 12,
color = norad_cols("green")
),
axis.title = ggplot2::element_text(
family = sans,
size = 14
),
axis.title.y = ggplot2::element_text(margin = ggplot2::margin(r = 10)),
axis.title.x = ggplot2::element_text(margin = ggplot2::margin(t = 10)),
axis.text.y = ggplot2::element_text(margin = ggplot2::margin(r = 15)),
axis.text.x = ggplot2::element_text(margin = ggplot2::margin(t = 20)),
axis.text.y = ggplot2::element_text(margin = ggplot2::margin(r = 5)),
axis.text.x = ggplot2::element_text(margin = ggplot2::margin(t = 10)),
axis.line = ggplot2::element_line(color = norad_cols("green")),
axis.ticks = ggplot2::element_blank(),
# Facet labels
strip.text = ggplot2::element_text(size = 20, color = norad_cols("lightgreen")),
strip.background = ggplot2::element_rect(fill = norad_cols("green"), color = NA),
strip.text = ggplot2::element_text(
family = sans,
size = 14,
color = norad_cols("lightgreen")
),
strip.background = ggplot2::element_rect(
fill = norad_cols("green"),
color = NA
),
# Plot and panel background
plot.background = ggplot2::element_rect(fill = "#eff6ea", color = NA),
plot.background = ggplot2::element_rect(
fill = "#eff6ea",
color = NA
),
panel.background = ggplot2::element_blank(),
# Plot margin
plot.margin = ggplot2::margin(1, 0, 1, 1, "cm")
Expand All @@ -127,15 +181,25 @@ theme_norad_big_dark <- function() {

theme_norad_big_light_1() +
ggplot2::theme(
text = ggplot2::element_text(color = norad_cols("lightgreen")),
plot.background = ggplot2::element_rect(fill = "#1b3a1c"),
text = ggplot2::element_text(
color = norad_cols("lightgreen")
),
plot.background = ggplot2::element_rect(
fill = "#1b3a1c"
),
panel.background = ggplot2::element_blank(),
plot.title = ggplot2::element_blank(),
plot.subtitle = ggplot2::element_blank(),
axis.text = ggplot2::element_text(size = 20, color = norad_cols("lightgreen")),
axis.line = ggplot2::element_line(color = norad_cols("lightgreen")),
strip.text = ggplot2::element_text(size = 20, color = norad_cols("green")),
strip.background = ggplot2::element_rect(fill = norad_cols("lightgreen"), color = NA)
axis.text = ggplot2::element_text(
color = norad_cols("lightgreen")
),
axis.line = ggplot2::element_line(
color = norad_cols("lightgreen")
),
strip.text = ggplot2::element_text(
color = norad_cols("green")
),
strip.background = ggplot2::element_rect(
fill = norad_cols("lightgreen")
)
)
}

Expand All @@ -150,15 +214,71 @@ theme_norad_big_light_2 <- function() {

theme_norad_big_light_1() +
ggplot2::theme(
text = ggplot2::element_text(color = norad_cols("blue")),
plot.background = ggplot2::element_rect(fill = "#eee8e7"),
text = ggplot2::element_text(
color = norad_cols("blue")
),
plot.background = ggplot2::element_rect(
fill = "#eee8e7"
),
panel.background = ggplot2::element_blank(),
plot.title = ggplot2::element_blank(),
plot.subtitle = ggplot2::element_blank(),
axis.text = ggplot2::element_text(size = 20, color = norad_cols("blue")),
axis.line = ggplot2::element_line(color = norad_cols("blue")),
strip.text = ggplot2::element_text(size = 20, color = norad_cols("blue")),
strip.background = ggplot2::element_rect(fill = norad_cols("darkred"), color = NA)
axis.text = ggplot2::element_text(
color = norad_cols("blue")
),
axis.line = ggplot2::element_line(
color = norad_cols("blue")
),
strip.text = ggplot2::element_text(
color = norad_cols("blue")
),
strip.background = ggplot2::element_rect(
fill = norad_cols("darkred"),
)
)
}

#' Function for using Norad's theme in ggplot2 graphics
#'
#'@export

theme_norad_map_light <- function() {
sans <- "Norad Sans"
serif <- "Norad Serif"
display <- "Norad Display"

ggplot2::theme_void() +
ggplot2::theme(
plot.background = ggplot2::element_rect(fill = "#eff6ea", color = NA),
plot.margin = ggplot2::margin(3, 3, 3, 3, "mm"),
legend.margin = ggplot2::margin(1, 1, 1, 1, "cm"),
plot.caption = ggplot2::element_text(hjust = 0),
text = ggplot2::element_text(
color = norad_cols("green"),
family = sans,
size = 12),
panel.border = element_blank()
)
}

#' Function for using Norad's theme in ggplot2 graphics
#'
#'@export

theme_norad_map_dark <- function() {
sans <- "Norad Sans"
serif <- "Norad Serif"
display <- "Norad Display"

ggplot2::theme_void() +
ggplot2::theme(
plot.background = ggplot2::element_rect(fill = "#1b3a1c", color = NA),
plot.margin = ggplot2::margin(3, 3, 3, 3, "mm"),
legend.margin = ggplot2::margin(1, 1, 1, 1, "cm"),
plot.caption = ggplot2::element_text(hjust = 0),
text = ggplot2::element_text(
color = norad_cols("lightgreen"),
family = sans,
size = 12),
panel.border = element_blank()
)
}

Expand Down
Loading