| Package: ggpomological | Package: ggpomological | ||||
| Version: 0.0.0.9000 | |||||
| Version: 0.0.0.9001 | |||||
| Title: Pomological plot themes for ggplot2 | Title: Pomological plot themes for ggplot2 | ||||
| Description: Pomological plot themes and scales for ggplot2 (in progress) | Description: Pomological plot themes and scales for ggplot2 (in progress) | ||||
| Authors@R: person("Garrick", "Aden-Buie", , "g.adenbuie@gmail.com", c("aut", "cre")) | Authors@R: person("Garrick", "Aden-Buie", , "g.adenbuie@gmail.com", c("aut", "cre")) |
| export(scale_fill_pomological) | export(scale_fill_pomological) | ||||
| export(theme_pomological) | export(theme_pomological) | ||||
| export(theme_pomological_nobg) | export(theme_pomological_nobg) | ||||
| export(theme_pomological_plain) |
| #' | #' | ||||
| #' @references https://usdawatercolors.nal.usda.gov/pom | #' @references https://usdawatercolors.nal.usda.gov/pom | ||||
| #' @seealso [ggplot2::theme] | #' @seealso [ggplot2::theme] | ||||
| #' @param base_family Base text family | |||||
| #' @param base_size Base text size | |||||
| #' @param base_family,base_size Base text family and size | |||||
| #' @param text.color Color of all text (except axis text, see `axis.text.color`) | #' @param text.color Color of all text (except axis text, see `axis.text.color`) | ||||
| #' @param plot.background.color Color of plot background, passed to `plot.background` | #' @param plot.background.color Color of plot background, passed to `plot.background` | ||||
| #' @param panel.grid.color Color of panel grid, passed to `panel.grid` | |||||
| #' @param panel.grid.linetype Linetype of panel grid, passed to `panel.grid` | |||||
| #' @param axis.text.color Color of axis text | |||||
| #' @param axis.text.size Size of axis text | |||||
| #' @param panel.border.color Color of plot panel border | |||||
| #' @param with.panel.grid If `FALSE` gridlines in plot are removed | |||||
| #' @param panel.grid.color,panel.grid.linetype Color and linetype of panel grid, passed to `panel.grid` | |||||
| #' @param axis.text.color,axis.text.size Color and size of axis text | |||||
| #' @param base_theme Starting theme of plot, default is | #' @param base_theme Starting theme of plot, default is | ||||
| #' [ggplot2::theme_minimal()]. Any elements set by `theme_pomological()` will | #' [ggplot2::theme_minimal()]. Any elements set by `theme_pomological()` will | ||||
| #' overwrite the `base_theme` unless the specific parameter is explicitly set | #' overwrite the `base_theme` unless the specific parameter is explicitly set | ||||
| #' - [Homemade Apple](https://fonts.google.com/specimen/Homemade+Apple/) | #' - [Homemade Apple](https://fonts.google.com/specimen/Homemade+Apple/) | ||||
| #' - [Amatic SC](https://fonts.google.com/specimen/Amatic+SC/) | #' - [Amatic SC](https://fonts.google.com/specimen/Amatic+SC/) | ||||
| #' - [Mr. Bedfort](https://fonts.google.com/specimen/Mr+Bedfort/) | #' - [Mr. Bedfort](https://fonts.google.com/specimen/Mr+Bedfort/) | ||||
| #' | |||||
| #' Fonts with R are notoriously tricky, so these may not work well for you. If | |||||
| #' you have installed the fonts but they aren't showing up or working, you can | |||||
| #' always try running `extrafont::font_import()` or `extrafont::load_fonts()` in | |||||
| #' the session or RMarkdown document. Or you can use [theme_pomological_plain()]. | |||||
| #' | #' | ||||
| #' @examples | #' @examples | ||||
| #' library(ggplot2) | #' library(ggplot2) | ||||
| #' basic_iris_plot <- ggplot(iris) + | #' basic_iris_plot <- ggplot(iris) + | ||||
| #' aes(x = Sepal.Length, y = Sepal.Width, color = Species) + | #' aes(x = Sepal.Length, y = Sepal.Width, color = Species) + | ||||
| #' geom_point(size = 2) | |||||
| #' geom_point(size = 2) + | |||||
| #' # with pomological color scale | |||||
| #' scale_color_pomological() | |||||
| #' | #' | ||||
| #' # Pomological Theme | #' # Pomological Theme | ||||
| #' basic_iris_plot + theme_pomological() | |||||
| #' basic_iris_plot + | |||||
| #' theme_pomological() | |||||
| #' | #' | ||||
| #' # Don't change panel grid color | #' # Don't change panel grid color | ||||
| #' basic_iris_plot + | #' basic_iris_plot + | ||||
| #' # White background | #' # White background | ||||
| #' basic_iris_plot + | #' basic_iris_plot + | ||||
| #' theme_pomological_nobg() | #' theme_pomological_nobg() | ||||
| #' | |||||
| #' # Plain plot without font or background | |||||
| #' basic_iris_plot + | |||||
| #' theme_pomological_plain() | |||||
| #' | #' | ||||
| #' @export | #' @export | ||||
| theme_pomological <- function( | theme_pomological <- function( | ||||
| base_family = 'Homemade Apple', | base_family = 'Homemade Apple', | ||||
| base_size = 16, | base_size = 16, | ||||
| text.color = NULL, | |||||
| plot.background.color = NULL, | |||||
| panel.grid.color = NULL, | |||||
| panel.grid.linetype = 'dashed', | |||||
| axis.text.color = NULL, | |||||
| text.color = pomological_base$dark_blue, | |||||
| plot.background.color = pomological_base$paper, | |||||
| panel.border.color = pomological_base$light_line, | |||||
| with.panel.grid = FALSE, | |||||
| panel.grid.color = pomological_base$light_line, | |||||
| panel.grid.linetype = "dashed", | |||||
| axis.text.color = pomological_base$medium_line, | |||||
| axis.text.size = base_size * 14/16, | axis.text.size = base_size * 14/16, | ||||
| base_theme = ggplot2::theme_minimal() | base_theme = ggplot2::theme_minimal() | ||||
| ) { | ) { | ||||
| if (!is.null(base_family)) check_font(base_family) | if (!is.null(base_family)) check_font(base_family) | ||||
| base_theme + | |||||
| base_theme + | |||||
| ggplot2::theme( | ggplot2::theme( | ||||
| text = ggplot2::element_text( | text = ggplot2::element_text( | ||||
| family = base_family, | family = base_family, | ||||
| size = base_size, | size = base_size, | ||||
| colour = ifelse(hasArg(text.color), text.color, pomological_base$dark_blue) | |||||
| colour = text.color | |||||
| ), | ), | ||||
| plot.background = ggplot2::element_rect( | plot.background = ggplot2::element_rect( | ||||
| fill = ifelse(hasArg(plot.background.color), plot.background.color, pomological_base$paper), | |||||
| fill = plot.background.color, | |||||
| colour = NA | colour = NA | ||||
| ), | ), | ||||
| panel.grid = ggplot2::element_line( | panel.grid = ggplot2::element_line( | ||||
| colour = ifelse(hasArg(panel.grid.color), panel.grid.color, pomological_base$light_line), | |||||
| linetype = panel.grid.linetype), | |||||
| panel.grid.major = ggplot2::element_line( | |||||
| colour = ifelse(hasArg(panel.grid.color), panel.grid.color, pomological_base$light_line), | |||||
| colour = panel.grid.color, | |||||
| linetype = panel.grid.linetype), | linetype = panel.grid.linetype), | ||||
| panel.border = ggplot2::element_rect( | |||||
| color = panel.border.color, | |||||
| fill = NA, | |||||
| linetype = "solid", | |||||
| size = 0.75 | |||||
| ), | |||||
| panel.grid.major = if (!with.panel.grid) ggplot2::element_blank(), | |||||
| panel.grid.minor = ggplot2::element_blank(), | panel.grid.minor = ggplot2::element_blank(), | ||||
| axis.text = ggplot2::element_text( | axis.text = ggplot2::element_text( | ||||
| colour = ifelse(hasArg(axis.text.color), axis.text.color, pomological_base$medium_line), | |||||
| colour = axis.text.color, | |||||
| size = axis.text.size) | size = axis.text.size) | ||||
| ) | ) | ||||
| } | } | ||||
| #' @export | #' @export | ||||
| theme_pomological_nobg <- function(...) { | theme_pomological_nobg <- function(...) { | ||||
| dots <- list(...) | dots <- list(...) | ||||
| dots$plot.background.color <- 'transparent' | |||||
| do.call('theme_pomological', args = dots) | |||||
| dots$plot.background.color <- "transparent" | |||||
| do.call("theme_pomological", args = dots) | |||||
| } | |||||
| #' @describeIn theme_pomological A "plain" pomological theme with white | |||||
| #' background and normal fonts. | |||||
| #' @export | |||||
| theme_pomological_plain <- function(...) { | |||||
| dots <- list(...) | |||||
| dots$plot.background.color <- "transparent" | |||||
| if (!"base_family" %in% names(dots)) dots["base_family"] <- "" | |||||
| if (!"base_size" %in% names(dots)) dots["base_size"] <- 11 | |||||
| do.call("theme_pomological", args = dots) | |||||
| } | } | ||||
| font_urls <- data.frame( | font_urls <- data.frame( | ||||
| ) | ) | ||||
| check_font <- function(font_name) { | check_font <- function(font_name) { | ||||
| if (!requireNamespace('extrafont', quietly = TRUE)) { | |||||
| if (!requireNamespace("extrafont", quietly = TRUE)) { | |||||
| warning("The font \"", font_name, "\" may or may not be installed on your system.", | warning("The font \"", font_name, "\" may or may not be installed on your system.", | ||||
| "Please install the package `extrafont` if you'd like me to be able to check for you.") | "Please install the package `extrafont` if you'd like me to be able to check for you.") | ||||
| } else { | } else { | ||||
| if (font_name %in% font_urls$name) { | if (font_name %in% font_urls$name) { | ||||
| warning("Unable to find font '", font_name, "'. ", | warning("Unable to find font '", font_name, "'. ", | ||||
| "If recently installed, please run `extrafonts::font_import()`. ", | "If recently installed, please run `extrafonts::font_import()`. ", | ||||
| "To install, visit: ", font_urls[font_urls$name == font_name, 'url']) | |||||
| "To install, visit: ", font_urls[font_urls$name == font_name, "url"]) | |||||
| } else { | } else { | ||||
| warning("Unable to find font '", font_name, "'. ", | warning("Unable to find font '", font_name, "'. ", | ||||
| "If recently installed, please run `extrafonts::font_import()`. ") | "If recently installed, please run `extrafonts::font_import()`. ") | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| } |
| This package provides a ggplot2 theme inspired by the [USDA Pomological Watercolors collection][usda-pom] and by Aron Atkins's ([\@aronatkins][t-aronatkins]) [talk on parameterized RMarkdown][rsconf-video] at [rstudio::conf 2018][rstudioconf]. | This package provides a ggplot2 theme inspired by the [USDA Pomological Watercolors collection][usda-pom] and by Aron Atkins's ([\@aronatkins][t-aronatkins]) [talk on parameterized RMarkdown][rsconf-video] at [rstudio::conf 2018][rstudioconf]. | ||||
|  | |||||
|  |  | ||||
| ## Installation | ## Installation | ||||
| ## Setup theme and scales | ## Setup theme and scales | ||||
| There are two theme-generating functions: | |||||
| There are three theme-generating functions: | |||||
| - `theme_pomological()` sets the plot theme to be representative of the paper and styling of the watercolors and includes a paper-colored background, | - `theme_pomological()` sets the plot theme to be representative of the paper and styling of the watercolors and includes a paper-colored background, | ||||
| - and `theme_pomological_nobg()` has the same styling, just with a transparent (or white) background. | |||||
| - `theme_pomological_nobg()` has the same styling, just with a transparent (or white) background, | |||||
| - `theme_pomological_plain()` has a white background and doesn't change the font unless requested. | |||||
| A handwriting font is needed for the fully authentic pomological look, and I found a few from Google Fonts that fit the bill. | A handwriting font is needed for the fully authentic pomological look, and I found a few from Google Fonts that fit the bill. | ||||
| theme_pomological() + | theme_pomological() + | ||||
| scale_color_pomological() | scale_color_pomological() | ||||
| # With transparent background | # With transparent background | ||||
| pomological_iris <- basic_iris_plot + | pomological_iris <- basic_iris_plot + | ||||
| theme_pomological_nobg() + | theme_pomological_nobg() + | ||||
| scale_color_pomological() | scale_color_pomological() | ||||
| pomological_iris | pomological_iris | ||||
| # Without fonts | |||||
| pomological_iris + theme_pomological_plain() | |||||
| # Painted! | # Painted! | ||||
| paint_pomological(pomological_iris, res = 110) %>% | paint_pomological(pomological_iris, res = 110) %>% | ||||
| magick::image_write("Readme_files/figure-gfm/plot-demo-painted.png") | magick::image_write("Readme_files/figure-gfm/plot-demo-painted.png") |
| parameterized RMarkdown](https://youtu.be/Ol1FjFR2IMU?t=5h21m15s) at | parameterized RMarkdown](https://youtu.be/Ol1FjFR2IMU?t=5h21m15s) at | ||||
| [rstudio::conf 2018](https://www.rstudio.com/conference/). | [rstudio::conf 2018](https://www.rstudio.com/conference/). | ||||
|  | |||||
|  |  | ||||
| ## Installation | ## Installation | ||||
| ## Setup theme and scales | ## Setup theme and scales | ||||
| There are two theme-generating functions: | |||||
| There are three theme-generating functions: | |||||
| - `theme_pomological()` sets the plot theme to be representative of | - `theme_pomological()` sets the plot theme to be representative of | ||||
| the paper and styling of the watercolors and includes a | the paper and styling of the watercolors and includes a | ||||
| paper-colored background, | paper-colored background, | ||||
| - and `theme_pomological_nobg()` has the same styling, just with a | |||||
| transparent (or white) background. | |||||
| - `theme_pomological_nobg()` has the same styling, just with a | |||||
| transparent (or white) background, | |||||
| - `theme_pomological_plain()` has a white background and doesn’t | |||||
| change the font unless requested. | |||||
| A handwriting font is needed for the fully authentic pomological look, | A handwriting font is needed for the fully authentic pomological look, | ||||
| and I found a few from Google Fonts that fit the bill. | and I found a few from Google Fonts that fit the bill. | ||||
| <!-- --> | <!-- --> | ||||
| ``` r | |||||
| # Without fonts | |||||
| pomological_iris + theme_pomological_plain() | |||||
| ``` | |||||
| <!-- --> | |||||
| ``` r | ``` r | ||||
| # Painted! | # Painted! | ||||
| paint_pomological(pomological_iris, res = 110) %>% | paint_pomological(pomological_iris, res = 110) %>% |
| \name{theme_pomological} | \name{theme_pomological} | ||||
| \alias{theme_pomological} | \alias{theme_pomological} | ||||
| \alias{theme_pomological_nobg} | \alias{theme_pomological_nobg} | ||||
| \alias{theme_pomological_plain} | |||||
| \title{Pomological Theme} | \title{Pomological Theme} | ||||
| \usage{ | \usage{ | ||||
| theme_pomological(base_family = "Homemade Apple", base_size = 16, | theme_pomological(base_family = "Homemade Apple", base_size = 16, | ||||
| text.color = NULL, plot.background.color = NULL, | |||||
| panel.grid.color = NULL, panel.grid.linetype = "dashed", | |||||
| axis.text.color = NULL, axis.text.size = base_size * 14/16, | |||||
| base_theme = ggplot2::theme_minimal()) | |||||
| text.color = pomological_base$dark_blue, | |||||
| plot.background.color = pomological_base$paper, | |||||
| panel.border.color = pomological_base$light_line, with.panel.grid = FALSE, | |||||
| panel.grid.color = pomological_base$light_line, | |||||
| panel.grid.linetype = "dashed", | |||||
| axis.text.color = pomological_base$medium_line, axis.text.size = base_size | |||||
| * 14/16, base_theme = ggplot2::theme_minimal()) | |||||
| theme_pomological_nobg(...) | theme_pomological_nobg(...) | ||||
| theme_pomological_plain(...) | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{base_family}{Base text family} | |||||
| \item{base_size}{Base text size} | |||||
| \item{base_family, base_size}{Base text family and size} | |||||
| \item{text.color}{Color of all text (except axis text, see \code{axis.text.color})} | \item{text.color}{Color of all text (except axis text, see \code{axis.text.color})} | ||||
| \item{plot.background.color}{Color of plot background, passed to \code{plot.background}} | \item{plot.background.color}{Color of plot background, passed to \code{plot.background}} | ||||
| \item{panel.grid.color}{Color of panel grid, passed to \code{panel.grid}} | |||||
| \item{panel.border.color}{Color of plot panel border} | |||||
| \item{panel.grid.linetype}{Linetype of panel grid, passed to \code{panel.grid}} | |||||
| \item{with.panel.grid}{If \code{FALSE} gridlines in plot are removed} | |||||
| \item{axis.text.color}{Color of axis text} | |||||
| \item{panel.grid.color, panel.grid.linetype}{Color and linetype of panel grid, passed to \code{panel.grid}} | |||||
| \item{axis.text.size}{Size of axis text} | |||||
| \item{axis.text.color, axis.text.size}{Color and size of axis text} | |||||
| \item{base_theme}{Starting theme of plot, default is | \item{base_theme}{Starting theme of plot, default is | ||||
| \code{\link[ggplot2:theme_minimal]{ggplot2::theme_minimal()}}. Any elements set by \code{theme_pomological()} will | \code{\link[ggplot2:theme_minimal]{ggplot2::theme_minimal()}}. Any elements set by \code{theme_pomological()} will | ||||
| \section{Functions}{ | \section{Functions}{ | ||||
| \itemize{ | \itemize{ | ||||
| \item \code{theme_pomological_nobg}: Pomological theme with white (transparent) background | \item \code{theme_pomological_nobg}: Pomological theme with white (transparent) background | ||||
| \item \code{theme_pomological_plain}: A "plain" pomological theme with white | |||||
| background and normal fonts. | |||||
| }} | }} | ||||
| \section{Fonts}{ | \section{Fonts}{ | ||||
| \item \href{https://fonts.google.com/specimen/Amatic+SC/}{Amatic SC} | \item \href{https://fonts.google.com/specimen/Amatic+SC/}{Amatic SC} | ||||
| \item \href{https://fonts.google.com/specimen/Mr+Bedfort/}{Mr. Bedfort} | \item \href{https://fonts.google.com/specimen/Mr+Bedfort/}{Mr. Bedfort} | ||||
| } | } | ||||
| Fonts with R are notoriously tricky, so these may not work well for you. If | |||||
| you have installed the fonts but they aren't showing up or working, you can | |||||
| always try running \code{extrafont::font_import()} or \code{extrafont::load_fonts()} in | |||||
| the session or RMarkdown document. Or you can use \code{\link[=theme_pomological_plain]{theme_pomological_plain()}}. | |||||
| } | } | ||||
| \examples{ | \examples{ | ||||
| library(ggplot2) | library(ggplot2) | ||||
| basic_iris_plot <- ggplot(iris) + | basic_iris_plot <- ggplot(iris) + | ||||
| aes(x = Sepal.Length, y = Sepal.Width, color = Species) + | aes(x = Sepal.Length, y = Sepal.Width, color = Species) + | ||||
| geom_point(size = 2) | |||||
| geom_point(size = 2) + | |||||
| # with pomological color scale | |||||
| scale_color_pomological() | |||||
| # Pomological Theme | # Pomological Theme | ||||
| basic_iris_plot + theme_pomological() | |||||
| basic_iris_plot + | |||||
| theme_pomological() | |||||
| # Don't change panel grid color | # Don't change panel grid color | ||||
| basic_iris_plot + | basic_iris_plot + | ||||
| # White background | # White background | ||||
| basic_iris_plot + | basic_iris_plot + | ||||
| theme_pomological_nobg() | theme_pomological_nobg() | ||||
| # Plain plot without font or background | |||||
| basic_iris_plot + | |||||
| theme_pomological_plain() | |||||
| } | } | ||||
| \references{ | \references{ |