| Package: ggpomological | Package: ggpomological | ||||
| Version: 0.0.0.9001 | |||||
| Version: 0.1.0 | |||||
| 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")) |
| #' | #' | ||||
| #' @references https://usdawatercolors.nal.usda.gov/pom | #' @references https://usdawatercolors.nal.usda.gov/pom | ||||
| #' @seealso [ggplot2::theme] | #' @seealso [ggplot2::theme] | ||||
| #' @param base_family,base_size Base text family and size | |||||
| #' @param base_family Base text family. See **Fonts** in [theme_pomological()] | |||||
| #' for some examples from Google Fonts options, including `"Mr De Haviland"`, | |||||
| #' `"Homemade Apple"`, `"Marck Script"`, and `"Mr. Bedfort"`. For the | |||||
| #' authentic pomological look, use `"Homemade Apple"` or `"Mr De Haviland"`. | |||||
| #' Set to `NULL` or use [theme_pomological_plain()] for no change to fonts. | |||||
| #' @param base_size Base text 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.border.color Color of plot panel border | #' @param panel.border.color Color of plot panel border | ||||
| #' Visit the links below to install on your system. | #' Visit the links below to install on your system. | ||||
| #' | #' | ||||
| #' - [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/) | |||||
| #' - [Mr. De Haviland](https://fonts.google.com/specimen/Mr+De+Haviland) | |||||
| #' - [Marck Script](https://fonts.google.com/specimen/Marck+Script/) | |||||
| #' - [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 | #' Fonts with R are notoriously tricky, so these may not work well for you. If | ||||
| #' | #' | ||||
| #' @export | #' @export | ||||
| theme_pomological <- function( | theme_pomological <- function( | ||||
| base_family = 'Homemade Apple', | |||||
| base_size = 16, | |||||
| base_family = "Homemade Apple", | |||||
| base_size = 14, | |||||
| text.color = pomological_base$dark_blue, | text.color = pomological_base$dark_blue, | ||||
| plot.background.color = pomological_base$paper, | plot.background.color = pomological_base$paper, | ||||
| panel.border.color = pomological_base$light_line, | panel.border.color = pomological_base$light_line, | ||||
| panel.grid.color = pomological_base$light_line, | panel.grid.color = pomological_base$light_line, | ||||
| panel.grid.linetype = "dashed", | panel.grid.linetype = "dashed", | ||||
| axis.text.color = pomological_base$medium_line, | axis.text.color = pomological_base$medium_line, | ||||
| axis.text.size = base_size * 14/16, | |||||
| axis.text.size = base_size * 3/4, | |||||
| 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) | ||||
| } | } | ||||
| font_urls <- data.frame( | font_urls <- data.frame( | ||||
| name = c("Homemade Apple", "Amatic SC", "Mr. Bedfort"), | |||||
| name = c("Mr De Haviland", "Homemade Apple", "Marck Script", "Mr. Bedfort"), | |||||
| url = c( | url = c( | ||||
| "https://fonts.google.com/specimen/Mr+De+Haviland", | |||||
| "https://fonts.google.com/specimen/Homemade+Apple/", | "https://fonts.google.com/specimen/Homemade+Apple/", | ||||
| "https://fonts.google.com/specimen/Amatic+SC/", | |||||
| "https://fonts.google.com/specimen/Marck+Script/", | |||||
| "https://fonts.google.com/specimen/Mr+Bedfort/" | "https://fonts.google.com/specimen/Mr+Bedfort/" | ||||
| ) | ) | ||||
| ) | ) | ||||
| 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.", | |||||
| call. = FALSE) | |||||
| } else { | } else { | ||||
| if (!font_name %in% extrafont::fonts()) { | if (!font_name %in% extrafont::fonts()) { | ||||
| if (font_name %in% font_urls$name) { | if (font_name %in% font_urls$name) { | ||||
| warning("Unable to find font '", font_name, "'. ", | |||||
| "If recently installed, please run `extrafonts::font_import()`. ", | |||||
| "To install, visit: ", font_urls[font_urls$name == font_name, "url"]) | |||||
| warning("Font '", font_name, "' isn't in the extrafonts font list (but it may still work). ", | |||||
| "If recently installed, you can try running `extrafonts::font_import()`. ", | |||||
| "To install, visit: ", font_urls[font_urls$name == font_name, "url"], | |||||
| call. = FALSE) | |||||
| } else { | } else { | ||||
| warning("Unable to find font '", font_name, "'. ", | |||||
| "If recently installed, please run `extrafonts::font_import()`. ") | |||||
| warning("Font '", font_name, "' isn't in the extrafonts font list (but it may still work). ", | |||||
| "If recently installed, you can try running `extrafonts::font_import()`. ", | |||||
| call. = FALSE) | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| 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. | ||||
| - [Mr. De Haviland](https://fonts.google.com/specimen/Mr+De+Haviland) | |||||
| - [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/) | |||||
| - [Marck Script](https://fonts.google.com/specimen/Marck+Script/) | |||||
| - [Mr. Bedfort](https://fonts.google.com/specimen/Mr+Bedfort/) | - [Mr. Bedfort](https://fonts.google.com/specimen/Mr+Bedfort/) | ||||
| Alternatively, use something like [calligrapher.com](https://www.calligraphr.com/) to create your own handwriting font! | Alternatively, use something like [calligrapher.com](https://www.calligraphr.com/) to create your own handwriting font! | ||||
| # Just your standard Iris plot | # Just your standard Iris plot | ||||
| basic_iris_plot | basic_iris_plot | ||||
| # With pomological theme | |||||
| basic_iris_plot + | |||||
| theme_pomological() + | |||||
| # With pomological colors | |||||
| basic_iris_plot <- basic_iris_plot + | |||||
| scale_color_pomological() | scale_color_pomological() | ||||
| basic_iris_plot | |||||
| # With pomological theme | |||||
| pomological_iris <- basic_iris_plot + theme_pomological() | |||||
| # With transparent background | # With transparent background | ||||
| pomological_iris <- basic_iris_plot + | |||||
| theme_pomological_nobg() + | |||||
| scale_color_pomological() | |||||
| pomological_iris | |||||
| basic_iris_plot + | |||||
| theme_pomological_nobg() | |||||
| # Without fonts | |||||
| pomological_iris + theme_pomological_plain() | |||||
| # Or with "plain" pomological | |||||
| basic_iris_plot + | |||||
| theme_pomological_plain() | |||||
| # Painted! | # Painted! | ||||
| paint_pomological(pomological_iris, res = 110) %>% | paint_pomological(pomological_iris, res = 110) %>% | ||||
| geom_histogram(binwidth = 850) + | geom_histogram(binwidth = 850) + | ||||
| xlab('Price (USD)') + | xlab('Price (USD)') + | ||||
| ylab('Count') + | ylab('Count') + | ||||
| ggtitle("ggpomological") + | |||||
| scale_x_continuous(label = scales::dollar_format()) + | scale_x_continuous(label = scales::dollar_format()) + | ||||
| scale_fill_pomological() | scale_fill_pomological() | ||||
| 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. | ||||
| - [Mr. De Haviland](https://fonts.google.com/specimen/Mr+De+Haviland) | |||||
| - [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/) | |||||
| - [Marck Script](https://fonts.google.com/specimen/Marck+Script/) | |||||
| - [Mr. Bedfort](https://fonts.google.com/specimen/Mr+Bedfort/) | - [Mr. Bedfort](https://fonts.google.com/specimen/Mr+Bedfort/) | ||||
| Alternatively, use something like | Alternatively, use something like | ||||
| <!-- --> | <!-- --> | ||||
| ``` r | ``` r | ||||
| # With pomological theme | |||||
| basic_iris_plot + | |||||
| theme_pomological() + | |||||
| # With pomological colors | |||||
| basic_iris_plot <- basic_iris_plot + | |||||
| scale_color_pomological() | scale_color_pomological() | ||||
| basic_iris_plot | |||||
| ``` | ``` | ||||
| <!-- --> | <!-- --> | ||||
| ``` r | ``` r | ||||
| # With pomological theme | |||||
| pomological_iris <- basic_iris_plot + theme_pomological() | |||||
| # With transparent background | # With transparent background | ||||
| pomological_iris <- basic_iris_plot + | |||||
| theme_pomological_nobg() + | |||||
| scale_color_pomological() | |||||
| pomological_iris | |||||
| basic_iris_plot + | |||||
| theme_pomological_nobg() | |||||
| ``` | ``` | ||||
| <!-- --> | <!-- --> | ||||
| ``` r | ``` r | ||||
| # Without fonts | |||||
| pomological_iris + theme_pomological_plain() | |||||
| # Or with "plain" pomological | |||||
| basic_iris_plot + | |||||
| theme_pomological_plain() | |||||
| ``` | ``` | ||||
| <!-- --> | <!-- --> | ||||
| geom_histogram(binwidth = 850) + | geom_histogram(binwidth = 850) + | ||||
| xlab('Price (USD)') + | xlab('Price (USD)') + | ||||
| ylab('Count') + | ylab('Count') + | ||||
| ggtitle("ggpomological") + | |||||
| scale_x_continuous(label = scales::dollar_format()) + | scale_x_continuous(label = scales::dollar_format()) + | ||||
| scale_fill_pomological() | scale_fill_pomological() | ||||
| \alias{theme_pomological_plain} | \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 = 18, | |||||
| text.color = pomological_base$dark_blue, | text.color = pomological_base$dark_blue, | ||||
| plot.background.color = pomological_base$paper, | plot.background.color = pomological_base$paper, | ||||
| panel.border.color = pomological_base$light_line, with.panel.grid = FALSE, | panel.border.color = pomological_base$light_line, with.panel.grid = FALSE, | ||||
| panel.grid.color = pomological_base$light_line, | panel.grid.color = pomological_base$light_line, | ||||
| panel.grid.linetype = "dashed", | panel.grid.linetype = "dashed", | ||||
| axis.text.color = pomological_base$medium_line, axis.text.size = base_size | axis.text.color = pomological_base$medium_line, axis.text.size = base_size | ||||
| * 14/16, base_theme = ggplot2::theme_minimal()) | |||||
| * 3/4, base_theme = ggplot2::theme_minimal()) | |||||
| theme_pomological_nobg(...) | theme_pomological_nobg(...) | ||||
| theme_pomological_plain(...) | theme_pomological_plain(...) | ||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{base_family, base_size}{Base text family and size} | |||||
| \item{base_family}{Base text family. See \strong{Fonts} in \code{\link[=theme_pomological]{theme_pomological()}} | |||||
| for some examples from Google Fonts options, including \code{"Mr De Haviland"}, | |||||
| \code{"Homemade Apple"}, \code{"Marck Script"}, and \code{"Mr. Bedfort"}. For the | |||||
| authentic pomological look, use \code{"Homemade Apple"} or \code{"Mr De Haviland"}. | |||||
| Set to \code{NULL} or use \code{\link[=theme_pomological_plain]{theme_pomological_plain()}} for no change to fonts.} | |||||
| \item{base_size}{Base text 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})} | ||||
| Visit the links below to install on your system. | Visit the links below to install on your system. | ||||
| \itemize{ | \itemize{ | ||||
| \item \href{https://fonts.google.com/specimen/Homemade+Apple/}{Homemade Apple} | \item \href{https://fonts.google.com/specimen/Homemade+Apple/}{Homemade Apple} | ||||
| \item \href{https://fonts.google.com/specimen/Amatic+SC/}{Amatic SC} | |||||
| \item \href{https://fonts.google.com/specimen/Mr+De+Haviland}{Mr. De Haviland} | |||||
| \item \href{https://fonts.google.com/specimen/Marck+Script/}{Marck Script} | |||||
| \item \href{https://fonts.google.com/specimen/Mr+Bedfort/}{Mr. Bedfort} | \item \href{https://fonts.google.com/specimen/Mr+Bedfort/}{Mr. Bedfort} | ||||
| } | } | ||||