Skip to content

Commit

Permalink
Merge pull request #40 from MatthewBJane/snes
Browse files Browse the repository at this point in the history
Add a Super Nintendo theme
  • Loading branch information
MatthewBJane authored Mar 20, 2024
2 parents 63e711f + 17ad7c5 commit 3c370a1
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 0 deletions.
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export(scale_color_oppenheimer_flame)
export(scale_color_oppenheimer_smoke)
export(scale_color_ravenclaw)
export(scale_color_slytherin)
export(scale_color_snes_b)
export(scale_color_snes_c)
export(scale_color_snes_d)
export(scale_color_spiderman)
export(scale_color_starwars)
export(scale_color_terminator)
Expand All @@ -63,6 +66,9 @@ export(scale_colour_friends_d)
export(scale_colour_nemo_b)
export(scale_colour_nemo_c)
export(scale_colour_nemo_d)
export(scale_colour_snes_b)
export(scale_colour_snes_c)
export(scale_colour_snes_d)
export(scale_fill_alien)
export(scale_fill_asteroid_city)
export(scale_fill_avatar)
Expand Down Expand Up @@ -90,12 +96,17 @@ export(scale_fill_oppenheimer_flame)
export(scale_fill_oppenheimer_smoke)
export(scale_fill_ravenclaw)
export(scale_fill_slytherin)
export(scale_fill_snes_b)
export(scale_fill_snes_c)
export(scale_fill_snes_d)
export(scale_fill_spiderman)
export(scale_fill_starwars)
export(scale_fill_terminator)
export(scale_fill_zelda)
export(simpsons_theme_colors)
export(slytherin_theme_colors)
export(snes_palette)
export(snes_theme_colors)
export(spiderman_theme_colors)
export(starwars_theme_colors)
export(terminator_theme_colors)
Expand All @@ -120,6 +131,7 @@ export(theme_oppenheimer)
export(theme_ravenclaw)
export(theme_simpsons)
export(theme_slytherin)
export(theme_snes)
export(theme_spiderman)
export(theme_starwars)
export(theme_terminator)
Expand Down
187 changes: 187 additions & 0 deletions R/theme_snes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
## Christopher T. Kenny
## theme_snes
## 2024-03-18

#' Super Nintendo Inspired Theme Color Palette
#'
#' @format character vector of hex code strings
#' @export
#' @concept snes
#'
#' @examples
#' snes_theme_colors
#'
snes_theme_colors <- c(
background = '#B7B7B7',
text = '#515051',
panel = '#E5E5E5',
border = '#000000',
strip_text = '#000000',
lighter = '#FFFFFF',
light = '#CCCCEB',
medium = '#7F7F7F',
dark = '#8C78C7'
)

# DISCRETE PALETTE COLORS: Please update to some colors that work with your theme
#' Super Nintendo Inspired Color Palette
#'
#' @format character vector of hex code strings
#' @export
#' @concept snes
#'
#' @examples
#' snes_palette
#'
snes_palette <- c(
'#806BBA', # original buttons 1
'#00926C', '#0150A5', '#DC3A4A', '#FFBC56', # PAL region buttons
'#C7C7E6', # original buttons 2
'#444872' # Japanese dpad (other colors too close)
)

#' Super Nintendo Inspired Theme
#'
#' @param snes_font should `theme_snes` use custom font? Default is `TRUE`.
#' @param ... additional parameters to pass to `ggplot2::theme()`
#'
#' @return a `ggplot2` `theme` element
#' @export
#' @concept snes
#'
#' @examples
#' library(ggplot2)
#'
#' ggplot(data = data.frame(x = rnorm(50, 0, 1), y = rnorm(50,0,1)), aes(x = x, y = y)) +
#' geom_smooth(method = 'lm') +
#' geom_point() +
#' labs(title = 'snes Scatter Plot') +
#' theme_snes()
#'
#' ggplot(mpg, aes(cty)) +
#' geom_density(aes(fill=factor(cyl)), alpha=0.8) +
#' labs(title="Density plot",
#' subtitle="City Mileage Grouped by Number of cylinders",
#' caption="Source: mpg",
#' x="City Mileage",
#' fill="# Cylinders") +
#' theme_snes() +
#' scale_fill_snes_d()
#'
#'
theme_snes <- function(snes_font = TRUE, ...) {

# CUSTOM FONT: add a custom font from google fonts
font_family <- ifelse(snes_font, 'snes', 'sans') # use this line if you have a custom font - change snes to match the font name used
if (snes_font) {
initialize_font(name = "League Gothic", family = "snes")
}

# CUSTOM THEME:
ggplot2::theme(
plot.background = element_rect(fill = snes_theme_colors["background"]),
text = element_text(color = snes_theme_colors["text"], family = font_family),
title = element_text(size = 20),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_rect(fill = snes_theme_colors["panel"], color = snes_theme_colors["medium"]),
panel.border = element_rect(fill = NA, color = snes_theme_colors["border"], linewidth = 1.2),
axis.title = element_text(size = 22),
axis.text = element_text(size = 18, color = snes_theme_colors["text"]),
axis.ticks = element_line(color = snes_theme_colors["border"], linewidth = 1),
legend.background = element_rect(fill = snes_theme_colors["panel"], color = NA),
legend.text = element_text(size = 16, color = snes_theme_colors["text"]),
strip.background = element_rect(fill = snes_theme_colors["lighter"], colour = snes_theme_colors["border"]),
strip.text = element_text(colour = snes_theme_colors["strip_text"], size = 14)
)
}

# COLOR SCALES: Make pretty color scales

#' Super Nintendo Inspired Color Scales
#'
#' @param ... Additional arguments to pass to `ggplot2::binned_scale` for `_b`,
#' `ggplot2::scale_[fill/color]_gradient` for `_c`, or `ggplot2::discrete_scale`
#' for `_d`
#'
#' @return a `ggplot` scale object
#'
#' @rdname scale_snes
#' @export
#'
#' @examples
#' library(ggplot2)
#'
#' ggplot(mpg, aes(cty)) +
#' geom_density(aes(fill=factor(cyl)), alpha=0.8) +
#' labs(title="Density plot",
#' subtitle="City Mileage Grouped by Number of cylinders",
#' caption="Source: mpg",
#' x="City Mileage",
#' fill="# Cylinders") +
#' facet_wrap(~(hwy > 29)) +
#' theme_snes() +
#' scale_fill_snes_d()
#'
#' ggplot(mpg) +
#' geom_point(aes(x = cty, y = hwy, color = year)) +
#' labs(title = 'Mileage comparisons',
#' x = 'City Mileage', y = 'Highway Mileage', color = 'Year') +
#' theme_snes() +
#' scale_color_snes_c()
#'
scale_color_snes_c <- function(...) {
ggplot2::scale_color_gradient(..., low = snes_theme_colors["light"], high = snes_theme_colors["dark"])
}

#' @rdname scale_snes
#' @export
scale_fill_snes_c <- function(...) {
ggplot2::scale_fill_gradient(..., low = snes_theme_colors["light"], high = snes_theme_colors["dark"])
}

#' @rdname scale_snes
#' @export
scale_color_snes_b <- function(...) {
if (!requireNamespace('scales', quietly = TRUE)) {
stop('This function requires the `scales` R package.')
}
ramp <- scales::colour_ramp(c(snes_theme_colors["light"], snes_theme_colors["dark"]))
ggplot2::binned_scale('color', 'snes', palette = ramp, ...)
}

#' @rdname scale_snes
#' @export
scale_fill_snes_b <- function(...) {
if (!requireNamespace('scales', quietly = TRUE)) {
stop('This function requires the `scales` R package.')
}
ramp <- scales::colour_ramp(c(snes_theme_colors["light"], snes_theme_colors["dark"]))
ggplot2::binned_scale('fill', 'snes', palette = ramp, ...)
}

#' @rdname scale_snes
#' @export
scale_color_snes_d <- function(...) {
ggplot2::discrete_scale(aesthetics = 'color',
palette = rot_pal(snes_palette), ...)
}

#' @rdname scale_snes
#' @export
scale_fill_snes_d <- function(...) {
ggplot2::discrete_scale(aesthetics = 'fill', ...,
palette = rot_pal(snes_palette))
}

#' @rdname scale_snes
#' @export
scale_colour_snes_d <- scale_color_snes_d

#' @rdname scale_snes
#' @export
scale_colour_snes_c <- scale_color_snes_c

#' @rdname scale_snes
#' @export
scale_colour_snes_b <- scale_color_snes_b
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ reference:
desc: "Themes inspired by the Star Wars movies"
- contents:
- has_concept("starwars")
- title: "Super Nintendo"
desc: "Themes inspired by the Super Nintendo Entertainment System"
- contents:
- has_concept("snes")
- title: "Terminator"
desc: "Themes inspired by the Terminator movies"
- contents:
Expand Down
65 changes: 65 additions & 0 deletions man/scale_snes.Rd

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

21 changes: 21 additions & 0 deletions man/snes_palette.Rd

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

21 changes: 21 additions & 0 deletions man/snes_theme_colors.Rd

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

41 changes: 41 additions & 0 deletions man/theme_snes.Rd

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

Loading

0 comments on commit 3c370a1

Please sign in to comment.