Title: | Dark Mode for 'ggplot2' Themes |
---|---|
Description: | Activate dark mode on your favorite 'ggplot2' theme with dark_mode() or use the dark versions of 'ggplot2' themes, including dark_theme_gray(), dark_theme_minimal(), and others. When a dark theme is applied, all geom color and geom fill defaults are changed to make them visible against a dark background. To restore the defaults to their original values, use invert_geom_defaults(). |
Authors: | Neal Grantham |
Maintainer: | Neal Grantham <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2024-10-23 03:43:56 UTC |
Source: | https://github.com/nsgrantham/ggdark |
Activate dark mode on a 'ggplot2' theme
dark_mode(.theme = theme_get(), verbose = TRUE, force_geom_invert = FALSE)
dark_mode(.theme = theme_get(), verbose = TRUE, force_geom_invert = FALSE)
.theme |
ggplot2 theme object |
verbose |
print messages (default: TRUE) |
force_geom_invert |
Force the inversion of geom defaults for fill and color/colour (default: FALSE) |
dark version of theme
library(ggplot2) p1 <- ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) + geom_point() p1 # theme returned by theme_get() p1 + dark_mode() # activate dark mode on theme returned by theme_get() p2 <- ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point() + facet_wrap(~ Species) p2 + dark_mode(theme_minimal()) # activate dark mode on another theme invert_geom_defaults() # restore geom defaults to their original values
library(ggplot2) p1 <- ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) + geom_point() p1 # theme returned by theme_get() p1 + dark_mode() # activate dark mode on theme returned by theme_get() p2 <- ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point() + facet_wrap(~ Species) p2 + dark_mode(theme_minimal()) # activate dark mode on another theme invert_geom_defaults() # restore geom defaults to their original values
Use dark_mode() on your favorite 'ggplot2' theme to activate its dark mode. 'ggdark' also provides dark versions of the themes included in 'ggplot2': dark_theme_grey(), dark_theme_bw(), dark_theme_minimal(), and others. When a dark theme is applied, all geom color and geom fill defaults are inverted to make them visible against a dark background. To change them back, use invert_geom_defaults().
These are dark versions of complete themes from 'ggplot2' which control all non-data display. Use theme() if you just need to tweak the display of an existing theme.
dark_theme_bw(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_classic(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_gray(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_grey(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_minimal(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_light(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_dark(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_void(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_test(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_linedraw(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22)
dark_theme_bw(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_classic(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_gray(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_grey(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_minimal(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_light(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_dark(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_void(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_test(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) dark_theme_linedraw(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22)
base_size |
base font size |
base_family |
base font family |
base_line_size |
base size for line elements |
base_rect_size |
base size for rect elements |
Dark version of theme_gray(), the signature 'ggplot2' theme with a grey background and white gridlines, designed to put the data forward yet make comparisons easy.
Dark version of theme_bw(), the classic dark-on-light 'ggplot2' theme. May work better for presentations displayed with a projector.
Dark version of theme_linedraw(), a theme with only black lines of various widths on white backgrounds, reminiscent of a line drawings. Serves a purpose similar to theme_bw(). Note that this theme has some very thin lines (<< 1 pt) which some journals may refuse.
Dark version of theme_light(), a theme similar to theme_linedraw() but with light grey lines and axes, to direct more attention towards the data.
Dark verion of theme_dark(), the dark cousin of theme_light(), with similar line sizes but a dark background. Useful to make thin coloured lines pop out.
Dark version of theme_minimal(), a minimalistic theme with no background annotations.
Dark version of theme_classic(), a classic-looking theme, with x and y axis lines and no gridlines.
Dark version of theme_void(), a completely empty theme.
Dark version of theme_test(), a theme for visual unit tests. It should ideally never change except for new features.
library(ggplot2) 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.", tag = "Figure 1", x = "Weight (1000 lbs)", y = "Fuel economy (mpg)", colour = "Gears") p1 + dark_theme_gray() p1 + dark_theme_bw() p1 + dark_theme_linedraw() p1 + dark_theme_light() # quite dark p1 + dark_theme_dark() # quite light p1 + dark_theme_minimal() p1 + dark_theme_classic() p1 + dark_theme_void() # Theme examples with panels p2 <- p1 + facet_grid(vs ~ am) p2 + dark_theme_gray() p2 + dark_theme_bw() p2 + dark_theme_linedraw() p2 + dark_theme_light() # quite dark p2 + dark_theme_dark() # quite light p2 + dark_theme_minimal() p2 + dark_theme_classic() p2 + dark_theme_void()
library(ggplot2) 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.", tag = "Figure 1", x = "Weight (1000 lbs)", y = "Fuel economy (mpg)", colour = "Gears") p1 + dark_theme_gray() p1 + dark_theme_bw() p1 + dark_theme_linedraw() p1 + dark_theme_light() # quite dark p1 + dark_theme_dark() # quite light p1 + dark_theme_minimal() p1 + dark_theme_classic() p1 + dark_theme_void() # Theme examples with panels p2 <- p1 + facet_grid(vs ~ am) p2 + dark_theme_gray() p2 + dark_theme_bw() p2 + dark_theme_linedraw() p2 + dark_theme_light() # quite dark p2 + dark_theme_dark() # quite light p2 + dark_theme_minimal() p2 + dark_theme_classic() p2 + dark_theme_void()
Invert a vector of colors, provided the colors are valid hex codes or have valid names (i.e., they belong to base::colors()), and return a vector of inverted colors in hex code.
invert_color(color, colour = color) invert_colour(color, colour = color)
invert_color(color, colour = color) invert_colour(color, colour = color)
color |
color(s) to invert |
colour |
alias of color |
Inverted color(s) in hex code
invert_color("white") # "black" invert_color("gray20") # "gray80" invert_color("grey80") # "grey20" invert_color(c("#000000", "#333333")) # "#FFFFFF","#CCCCCC"
invert_color("white") # "black" invert_color("gray20") # "gray80" invert_color("grey80") # "grey20" invert_color(c("#000000", "#333333")) # "#FFFFFF","#CCCCCC"
Invert geom defaults for fill and color/colour
invert_geom_defaults(geoms = get_geoms())
invert_geom_defaults(geoms = get_geoms())
geoms |
List of geoms as ggproto objects |
library(ggplot2) p <- ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point() + facet_wrap(~ Species) p + dark_theme_gray() # geom defaults changed p + theme_gray() # oh no! geoms are not visible on light background invert_geom_defaults() # geom defaults changed back p + theme_gray() # back to normal
library(ggplot2) p <- ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point() + facet_wrap(~ Species) p + dark_theme_gray() # geom defaults changed p + theme_gray() # oh no! geoms are not visible on light background invert_geom_defaults() # geom defaults changed back p + theme_gray() # back to normal
Invert theme elements
invert_theme_elements(.theme)
invert_theme_elements(.theme)
.theme |
theme to invert |
Inverted theme