| @@ -1,5 +1,5 @@ | |||
| Package: ggpomological | |||
| Version: 0.0.0.9001 | |||
| Version: 0.1.0 | |||
| Title: Pomological plot themes for ggplot2 | |||
| Description: Pomological plot themes and scales for ggplot2 (in progress) | |||
| Authors@R: person("Garrick", "Aden-Buie", , "g.adenbuie@gmail.com", c("aut", "cre")) | |||
| @@ -4,7 +4,12 @@ | |||
| #' | |||
| #' @references https://usdawatercolors.nal.usda.gov/pom | |||
| #' @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 plot.background.color Color of plot background, passed to `plot.background` | |||
| #' @param panel.border.color Color of plot panel border | |||
| @@ -22,7 +27,8 @@ | |||
| #' Visit the links below to install on your system. | |||
| #' | |||
| #' - [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/) | |||
| #' | |||
| #' Fonts with R are notoriously tricky, so these may not work well for you. If | |||
| @@ -58,8 +64,8 @@ | |||
| #' | |||
| #' @export | |||
| theme_pomological <- function( | |||
| base_family = 'Homemade Apple', | |||
| base_size = 16, | |||
| base_family = "Homemade Apple", | |||
| base_size = 14, | |||
| text.color = pomological_base$dark_blue, | |||
| plot.background.color = pomological_base$paper, | |||
| panel.border.color = pomological_base$light_line, | |||
| @@ -67,7 +73,7 @@ theme_pomological <- function( | |||
| 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 * 3/4, | |||
| base_theme = ggplot2::theme_minimal() | |||
| ) { | |||
| if (!is.null(base_family)) check_font(base_family) | |||
| @@ -120,10 +126,11 @@ theme_pomological_plain <- function(...) { | |||
| } | |||
| 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( | |||
| "https://fonts.google.com/specimen/Mr+De+Haviland", | |||
| "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/" | |||
| ) | |||
| ) | |||
| @@ -131,16 +138,19 @@ font_urls <- data.frame( | |||
| check_font <- function(font_name) { | |||
| if (!requireNamespace("extrafont", quietly = TRUE)) { | |||
| 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 { | |||
| if (!font_name %in% extrafont::fonts()) { | |||
| 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 { | |||
| 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) | |||
| } | |||
| } | |||
| } | |||
| @@ -69,8 +69,9 @@ There are three theme-generating functions: | |||
| 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/) | |||
| - [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/) | |||
| Alternatively, use something like [calligrapher.com](https://www.calligraphr.com/) to create your own handwriting font! | |||
| @@ -111,19 +112,21 @@ basic_iris_plot <- ggplot(iris) + | |||
| # Just your standard 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() | |||
| basic_iris_plot | |||
| # With pomological theme | |||
| pomological_iris <- basic_iris_plot + theme_pomological() | |||
| # 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! | |||
| paint_pomological(pomological_iris, res = 110) %>% | |||
| @@ -141,6 +144,7 @@ stacked_bar_plot <- ggplot(diamonds) + | |||
| geom_histogram(binwidth = 850) + | |||
| xlab('Price (USD)') + | |||
| ylab('Count') + | |||
| ggtitle("ggpomological") + | |||
| scale_x_continuous(label = scales::dollar_format()) + | |||
| scale_fill_pomological() | |||
| @@ -67,8 +67,9 @@ There are three theme-generating functions: | |||
| 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/) | |||
| - [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/) | |||
| Alternatively, use something like | |||
| @@ -119,27 +120,29 @@ basic_iris_plot | |||
| <!-- --> | |||
| ``` r | |||
| # With pomological theme | |||
| basic_iris_plot + | |||
| theme_pomological() + | |||
| # With pomological colors | |||
| basic_iris_plot <- basic_iris_plot + | |||
| scale_color_pomological() | |||
| basic_iris_plot | |||
| ``` | |||
| <!-- --> | |||
| ``` r | |||
| # With pomological theme | |||
| pomological_iris <- basic_iris_plot + theme_pomological() | |||
| # With transparent background | |||
| pomological_iris <- basic_iris_plot + | |||
| theme_pomological_nobg() + | |||
| scale_color_pomological() | |||
| pomological_iris | |||
| basic_iris_plot + | |||
| theme_pomological_nobg() | |||
| ``` | |||
| <!-- --> | |||
| ``` r | |||
| # Without fonts | |||
| pomological_iris + theme_pomological_plain() | |||
| # Or with "plain" pomological | |||
| basic_iris_plot + | |||
| theme_pomological_plain() | |||
| ``` | |||
| <!-- --> | |||
| @@ -160,6 +163,7 @@ stacked_bar_plot <- ggplot(diamonds) + | |||
| geom_histogram(binwidth = 850) + | |||
| xlab('Price (USD)') + | |||
| ylab('Count') + | |||
| ggtitle("ggpomological") + | |||
| scale_x_continuous(label = scales::dollar_format()) + | |||
| scale_fill_pomological() | |||
| @@ -6,21 +6,27 @@ | |||
| \alias{theme_pomological_plain} | |||
| \title{Pomological Theme} | |||
| \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, | |||
| 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()) | |||
| * 3/4, base_theme = ggplot2::theme_minimal()) | |||
| theme_pomological_nobg(...) | |||
| theme_pomological_plain(...) | |||
| } | |||
| \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})} | |||
| @@ -57,7 +63,8 @@ The following fonts from \href{https://fonts.google.com}{Google Fonts} work well | |||
| Visit the links below to install on your system. | |||
| \itemize{ | |||
| \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} | |||
| } | |||