Skip to content
Open
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
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Generated by roxygen2: do not edit by hand

export(alucard_tibble)
export(dracula_brand)
export(dracula_tibble)
export(scale_color_alucard)
export(scale_color_dracula)
export(scale_colour_alucard)
export(scale_colour_dracula)
export(scale_fill_alucard)
export(scale_fill_dracula)
export(theme_alucard)
export(theme_dracula)
importFrom(dplyr,pull)
importFrom(ggplot2,'%+replace%')
Expand Down
65 changes: 65 additions & 0 deletions R/alucard_palette.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#' @title Alucard Tibble
#'
#' @description A Tibble of Alucard data that includes the palette specification.
#' See https://spec.draculatheme.com for details.
#'
#' @importFrom tibble tribble
#'
#' @return Alucard Tibble
#'
#' @export
alucard_tibble <- tribble(
~palette, ~hex, ~rgb, ~hsl,
"green", "#14710A", "RGB(20, 113, 10)", "HSL(114, 84, 24)",
"cyan", "#036A96", "RGB(3, 106, 150)", "HSL(198, 96, 30)",
"purple", "#644AC9", "RGB(100, 74, 201)", "HSL(252, 54, 54)",
"pink", "#A3144D", "RGB(163, 20, 77)", "HSL(336, 78, 36)",
"red", "#CB3A2A", "RGB(203, 58, 42)", "HSL(6, 66, 48)",
"orange", "#A34D14", "RGB(163, 77, 20)", "HSL(24, 78, 36)",
"yellow", "#846E15", "RGB(132, 110, 21)", "HSL(48, 73, 30)"
)


#' @title Alucard Bright Palette
#'
#' @description Used in conjunction with `alucard_discrete_bright_palette` as an
#' internal closure for interfacing with `scale_fill_alucard` and `scale_color_alucard`.
#'
#' @noRd
#'
#' @importFrom dplyr pull
alucard_bright_palette <- function() {
function(n) {
pull(alucard_tibble, "hex")[1:n]
}
}


#' @title Alucard Discrete Bright Palette
#'
#' @description Used in conjunction with `alucard_bright_palette` as an
#' internal closure for interfacing with `scale_fill_alucard` and `scale_color_alucard`
#'
#' @param n Number of colors to return.
#' If missing, defaults to the length of the entire palette
#'
#' @noRd
#'
#' @return Function for interfacing with scale functions
alucard_discrete_bright_palette <- function(n) {
if (missing(n)) {
n <- 7
}

if (n > 7) {
stop("WARNING: Cannot use n > 7")
}

alucard <- alucard_bright_palette()(n)

structure(
alucard,
name = "alucard",
class = "palette"
)
}
36 changes: 36 additions & 0 deletions R/scales.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,39 @@ scale_color_dracula <- function(..., discrete = FALSE, aesthetics = "color") {
#' @aliases scale_color_dracula
#' @export
scale_colour_dracula <- scale_color_dracula

#' @title Alucard Theme Scales for `ggplot2`
#'
#' @param ... Parameters passed on to [ggplot2::discrete_scale()] if
#' `discrete == TRUE`, or to [ggplot2::scale_fill_gradientn()] if `discrete == FALSE`.
#' @param discrete Whether the scale is discrete. Defaults to `FALSE`.
#' @param aesthetics The aesthetics for the plot.
#'
#' @rdname scale_alucard
#'
#' @importFrom ggplot2 scale_fill_gradientn scale_color_gradientn discrete_scale
#'
#' @export
scale_fill_alucard <- function(..., discrete = FALSE, aesthetics = "fill") {
if (discrete) {
discrete_scale(aesthetics, palette = alucard_discrete_bright_palette, ...)
} else {
scale_fill_gradientn(colors = pull(alucard_tibble, "hex"), aesthetics = aesthetics, ...)
}
}

#' @rdname scale_alucard
#'
#' @export
scale_color_alucard <- function(..., discrete = FALSE, aesthetics = "color") {
if (discrete) {
discrete_scale(aesthetics, palette = alucard_discrete_bright_palette, ...)
} else {
scale_color_gradientn(colors = pull(alucard_tibble, "hex"), aesthetics = aesthetics, ...)
}
}

#' @rdname scale_alucard
#' @aliases scale_color_alucard
#' @export
scale_colour_alucard <- scale_color_alucard
48 changes: 48 additions & 0 deletions R/theme_alucard.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#' @title Theme Alucard
#'
#' @description Provides a minimal `ggplot2` theme with a Alucard, light backdrop.
#'
#' @importFrom ggplot2 '%+replace%' theme element_text element_rect element_line element_blank theme_minimal
#'
#' @examples
#' # Set the current `ggplot2` theme with `ggplot2::theme_set`:
#' library(ggplot2)
#' theme_set(theme_alucard())
#'
#' # Or set it for the plot in the pipeline:
#' library(dplyr)
#' library(dRacula)
#' library(ggplot2)
#'
#' mpg %>%
#' filter(manufacturer %in% c("honda", "ford", "dodge", "audi")) %>%
#' group_by(manufacturer) %>%
#' summarize(mean_hwy = mean(hwy)) %>%
#' ggplot(aes(x = manufacturer, y = mean_hwy, fill = manufacturer)) +
#' theme(legend.position = "none") +
#' coord_flip() + geom_col() +
#' scale_fill_alucard(discrete = TRUE) +
#' theme_alucard()
#' @export
theme_alucard <- function() {
theme_minimal(base_size = 12) %+replace%
theme(
axis.text = element_text(color = "#1F1F1F"),
axis.title = element_text(face = "bold", color = "#6C664B"),

strip.text = element_text(face = "bold", colour = "#6C664B"),

legend.background = element_rect(fill = "transparent", color = NA),
legend.box.background = element_rect(fill = "transparent", color = "#1F1F1F", linewidth = 0.25),
legend.key = element_rect(fill = "transparent", color = NA),
legend.text = element_text(color = "#1F1F1F"),
legend.title = element_text(face = "bold", color = "#6C664B"),

panel.background = element_blank(),
panel.grid = element_line(color = "#CFCFDE"),

plot.background = element_rect(fill = "#FFFBEB", color = "#CFCFDE"),

title = element_text(face = "bold", color = "#1F1F1F")
)
}
20 changes: 20 additions & 0 deletions man/alucard_tibble.Rd

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

25 changes: 25 additions & 0 deletions man/scale_alucard.Rd

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

31 changes: 31 additions & 0 deletions man/theme_alucard.Rd

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

Loading