#' Dark (oscuro) theme for ggplots
#'
#' This function will make an extra dark theme for ggplots. Useful for PowerPoints with black background.
#' @export
#' @examples
#' mtcars2 <- within(mtcars, {
#' vs <- factor(vs, labels = c("V-shaped", "Straight"))
#' am <- factor(am, labels = c("Automatic", "Manual"))
#' cyl <- factor(cyl)
#' gear <- factor(gear)})
#'
#' p1 <- ggplot(mtcars2) +
#' geom_point(aes(x = wt, y = mpg, colour = gear)) +
#' labs(title = "Fuel economy declines as weight increases",
#' subtitle = "(1973-74)",
#' caption = "Data from the 1974 Motor Trend US magazine.",
#' x = "Weight (1000 lbs)",
#' y = "Fuel economy (mpg)",
#' colour = "Gears")
#'
#' p1 + theme_oscuro()
theme_oscuro <- function(base_size = 12, base_family = "") {
library(ggplot2)
theme_grey(base_size = base_size, base_family = base_family) %+replace%
theme(
# Specify axis options
axis.line = element_blank(),
axis.text.x = element_text(size = base_size*0.8, color = "white"),
axis.text.y = element_text(size = base_size*0.8, color = "white"),
axis.ticks = element_line(color = "white", size = 0.2),
axis.title.x = element_text(size = base_size, color = "white"),
axis.title.y = element_text(size = base_size, color = "white", angle = 90),
axis.ticks.length = unit(0.3, "lines"),
# Specify legend options
legend.background = element_rect(color = NA, fill = "black"),
legend.key = element_rect(color = "white", fill = "black"),
legend.key.size = unit(1.2, "lines"),
legend.key.height = NULL,
legend.key.width = NULL,
legend.text = element_text(size = base_size*0.8, color = "white"),
legend.title = element_text(size = base_size*0.8, face = "bold", hjust = 0, color = "white"),
legend.position = "right",
legend.text.align = NULL,
legend.title.align = NULL,
legend.direction = "vertical",
legend.box = NULL,
# Specify panel options
panel.background = element_rect(fill = "black", color = NA),
panel.border = element_rect(fill = NA, color = "white"),
panel.grid.major = element_line(color = "grey35"),
panel.grid.minor = element_line(color = "grey20"),
panel.spacing = unit(0.5, "lines"),
# Specify facetting options
strip.background = element_rect(fill = "grey30", color = "grey10"),
strip.text.x = element_text(size = base_size*0.8, color = "white"),
strip.text.y = element_text(size = base_size*0.8, color = "white",angle = -90),
# Specify plot options
plot.background = element_rect(color = "black", fill = "black"),
plot.title = element_text(size = base_size*1.2, color = "white"),
plot.margin = unit(rep(1, 4), "lines")
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.