├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── data.R ├── gg_remove_background.R ├── gg_remove_grid.R ├── gg_remove_legend.R ├── gg_remove_ticks.R ├── gg_remove_titles.R ├── gg_rescale.R ├── gg_supports_theme_attribute.R ├── ggplot2bdc.R ├── ggsave_golden.R ├── span.R ├── theme_bdc_grey.R ├── theme_bdc_lattice_population.R ├── theme_bdc_microtiter.R ├── theme_bdc_paneled.R └── trim_whitespace.R ├── README.Rmd ├── README.md ├── data └── rockpaperscissors.rda ├── figure ├── gg_rescale-1.png ├── gg_rescale-2.png ├── gg_rescale_golden-1.png ├── gg_rescale_golden2-1.png ├── gg_rescale_square-1.png ├── gg_rescale_square2-1.png ├── lattice-anim.gif ├── theme_bdc_grey-1.png ├── theme_bdc_grey-facets1-1.png ├── theme_bdc_grey-facets2-1.png ├── theme_bdc_grey_grid-1.png ├── theme_bdc_lattice_population-1.png ├── theme_bdc_lattice_population-facets-1.png ├── theme_bdc_microtiter-1.png ├── theme_bdc_microtiter-switch-1.png └── theme_bdc_paneled-1.png ├── ggplot2-bdc.Rproj ├── man ├── gg_remove_background.Rd ├── gg_remove_grid.Rd ├── gg_remove_legend.Rd ├── gg_remove_ticks.Rd ├── gg_remove_titles.Rd ├── gg_rescale.Rd ├── gg_supports_theme_attribute.Rd ├── ggplot2bdc.Rd ├── ggsave_golden.Rd ├── rockpaperscissors.Rd ├── span.Rd ├── theme_bdc_grey.Rd ├── theme_bdc_lattice_population.Rd ├── theme_bdc_microtiter.Rd ├── theme_bdc_paneled.Rd └── trim_whitespace.Rd └── tests ├── testthat.R └── testthat └── test-span.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: ggplot2bdc 2 | Type: Package 3 | Title: Themes and other helper functions for working with ggplot2 plots 4 | Version: 0.3.2 5 | Date: 2017-01-05 6 | Authors@R: c(person(family="Connelly", given="Brian", email="bdc@bconnelly.net", 7 | role=c("aut", "cre"))) 8 | Maintainer: Brian Connelly 9 | Description: The ggplot2bdc package contains themes and other functions for 10 | creating plots using ggplot2. 11 | License: BSD_2_clause + file LICENSE 12 | URL: https://github.com/briandconnelly/ggplot2bdc 13 | BugReports: https://github.com/briandconnelly/ggplot2bdc/issues 14 | ByteCompile: no 15 | NeedsCompilation: no 16 | LazyData: true 17 | VignetteBuilder: knitr 18 | Depends: 19 | R (>= 3.0.0) 20 | Imports: 21 | ggplot2 (>= 2.2.0), 22 | grid, 23 | tools 24 | Suggests: 25 | cowplot, 26 | knitr, 27 | testthat 28 | Enhances: ggplot2 29 | RoxygenNote: 5.0.1 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2014-2017 2 | COPYRIGHT HOLDER: Brian Connelly 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014-2017 Brian Connelly 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 10 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(gg_remove_background) 4 | export(gg_remove_background_canvas) 5 | export(gg_remove_background_facet) 6 | export(gg_remove_background_legend) 7 | export(gg_remove_background_panel) 8 | export(gg_remove_caption) 9 | export(gg_remove_grid) 10 | export(gg_remove_grid_major) 11 | export(gg_remove_grid_minor) 12 | export(gg_remove_grid_x) 13 | export(gg_remove_grid_y) 14 | export(gg_remove_legend) 15 | export(gg_remove_legend_background) 16 | export(gg_remove_legend_key) 17 | export(gg_remove_legend_text) 18 | export(gg_remove_legend_title) 19 | export(gg_remove_subtitle) 20 | export(gg_remove_ticks) 21 | export(gg_remove_ticks_x) 22 | export(gg_remove_ticks_y) 23 | export(gg_remove_title) 24 | export(gg_remove_title.x) 25 | export(gg_remove_title.y) 26 | export(gg_remove_titles) 27 | export(gg_rescale) 28 | export(gg_rescale_golden) 29 | export(gg_rescale_square) 30 | export(gg_supports_theme_attribute) 31 | export(ggsave_golden) 32 | export(rescale_golden) 33 | export(rescale_plot) 34 | export(rescale_square) 35 | export(span) 36 | export(theme_bdc_gray) 37 | export(theme_bdc_grey) 38 | export(theme_bdc_lattice_population) 39 | export(theme_bdc_microtiter) 40 | export(theme_bdc_paneled) 41 | export(trim_whitespace) 42 | import(ggplot2) 43 | import(grid) 44 | importFrom(ggplot2,ggsave) 45 | importFrom(grid,unit) 46 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # ggplot2bdc 0.3.2 (2017-01-05) 2 | 3 | * Added `trim_whitespace` for removing whitespace around an image 4 | 5 | # ggplot2bdc 0.3.1 (2017-01-05) 6 | 7 | * Re-implemented `gg_rescale_` functions 8 | * Now uses the theme's `aspect.ratio` instead of `coord_equal` 9 | 10 | # ggplot2bdc 0.3.0 11 | 12 | * Added support for the changes in ggplot2 2.2.0 13 | * Now that `theme` uses named arguments, `gg_supports_theme_attribute` now examines `theme`'s formal arguments instead of looking in `theme_grey` 14 | * Moved `panel.margin` and `legend.margin` to `panel.spacing` and `legend.spacing` 15 | * Explicitly setting a few legend properties in `theme_bdc_grey` 16 | * Updated `gg_rescale` to work with changed format of plot objects 17 | * ggplot2 2.2.0 is now required for ease of maintenance 18 | * Removed checks for subtitle and caption support 19 | 20 | # ggplot2bdc 0.2.3 21 | 22 | * Fixed support for subtitles and captions in theme_bdc_microtiter (thanks @WadeDavis) 23 | 24 | # ggplot2bdc 0.2.2 25 | 26 | * Support for subtitles and captions only when development version is used 27 | 28 | # ggplot2bdc 0.2.1 29 | 30 | * Updated `theme_bdc_microtiter` 31 | * Now compatible with cowplot::switch_axis_position 32 | 33 | # ggplot2bdc 0.2.0 34 | 35 | * Updated `theme_bdc_grey` 36 | * Works properly with ggplot2 37 | * Added support for subtitle and caption 38 | * Merged in facet strip formatting from `theme_bdc_simplefacets` 39 | * Updated `theme_bdc_microtiter` 40 | * Works properly with ggplot2 41 | * Added support for subtitle and caption 42 | * Updated `theme_bdc_lattice_population` 43 | * Works properly with ggplot2 44 | * Added support for subtitle and caption 45 | * Added gganimate example 46 | * Now based on `ggplot2::theme_void` 47 | * Updated `theme_bdc_paneled` 48 | * Works properly with ggplot2 49 | * Added support for subtitle and caption 50 | * Added `rockpaperscissors` data set, a spatial simulation of rock, paper, scissors 51 | * Added `gg_remove_ticks` functions 52 | * Removed `remove_ticks` 53 | * Added `gg_remove_titles` functions 54 | * Removed `remove_titles` 55 | * Simplified `span` implementation 56 | * Added unit tests for span 57 | * Renamed `rescale_plot`, `rescale_golden`, and `rescale_square` as `gg_rescale`, `gg_rescale_golden`, and `gg_rescale_square`, respectively 58 | * All now share the same man page 59 | * Removed `theme_bdc_black` 60 | * Removed `theme_bdc_simple` 61 | * Removed `theme_bdc_simplefacets` 62 | * Removed `coord_golden`, `coord_square`, `ratio_golden`, and `ratio_square` 63 | 64 | # ggplot2bdc 0.1.7 65 | 66 | * Added theme_bdc_lattice_population 67 | 68 | # ggplot2bdc 0.1.6 69 | 70 | * rescale_plot now uses the axis ranges instead of the data ranges when calculating the appropriate ratio 71 | 72 | 73 | # ggplot2bdc 0.1.5 74 | 75 | * Added rescale_plot function, which re-scales a plot to a given ratio 76 | * rescale_golden and rescale_square now call rescale_plot 77 | * Created NEWS file 78 | 79 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Data set containing locations of simulated rock-paper-scissors players 2 | #' 3 | #' Simulations were run on a 50x50 lattice. Each player played one strategy. 4 | #' 5 | #' @name rockpaperscissors 6 | #' @docType data 7 | #' @format A data frame with TODO rows and TODO variables: 8 | #' \describe{ 9 | #' \item{Time}{The simulation timestep} 10 | #' \item{X}{The X coordinate of the cell on the lattice} 11 | #' \item{Y}{The Y coordinate of the cell on the lattice} 12 | #' \item{Type}{The type of player: Rock, Paper, or Scissors} 13 | #' } 14 | #' @source \url{https://github.com/briandconnelly/seeds} 15 | NULL 16 | 17 | -------------------------------------------------------------------------------- /R/gg_remove_background.R: -------------------------------------------------------------------------------- 1 | #' Remove a plot's background. 2 | #' 3 | #' \code{gg_remove_background} removes the background from the given plot. This 4 | #' is useful for creating plots with transparent backgrounds 5 | #' 6 | #' @param plot A ggplot2 plot object. By default, the last plot displayed is 7 | #' used. 8 | #' @param canvas Whether or not to remove the background from the entire image (default: \code{TRUE}) 9 | #' @param panel Whether or not to remove the background from the panel (i.e., the plotting area; default: \code{FALSE}) 10 | #' @param legend Whether or not to remove the legend's background 11 | #' (default: \code{FALSE}) 12 | #' @param facet Whether or not to remove the background from facet labels 13 | #' (default: \code{FALSE}) 14 | #' 15 | #' @return A modified ggplot2 plot 16 | #' @export 17 | #' 18 | #' @examples 19 | #' p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 20 | #' geom_point(shape = 1) 21 | #' gg_remove_background(plot = p) 22 | #' 23 | gg_remove_background <- function(plot = last_plot(), canvas = TRUE, 24 | panel = FALSE, legend = FALSE, facet = FALSE) { 25 | if (canvas) plot <- plot + theme(plot.background = element_blank()) 26 | if (panel) plot <- plot + theme(panel.background = element_blank()) 27 | if (legend) plot <- plot + theme(legend.background = element_blank()) 28 | if (facet) plot <- plot + theme(strip.background = element_blank()) 29 | 30 | plot 31 | } 32 | 33 | #' \code{gg_remove_background_canvas} Removes TODO 34 | #' @rdname gg_remove_background 35 | #' @export 36 | gg_remove_background_canvas <- function(plot = last_plot()) { 37 | gg_remove_background(plot = plot, canvas = TRUE, panel = FALSE, 38 | legend = FALSE, facet = FALSE) 39 | } 40 | 41 | 42 | #' \code{gg_remove_background_panel} Removes TODO 43 | #' @rdname gg_remove_background 44 | #' @export 45 | gg_remove_background_panel <- function(plot = last_plot()) { 46 | gg_remove_background(plot = plot, canvas = FALSE, panel = TRUE, 47 | legend = FALSE, facet = FALSE) 48 | } 49 | 50 | 51 | #' \code{gg_remove_background_legend} Removes TODO 52 | #' @rdname gg_remove_background 53 | #' @export 54 | gg_remove_background_legend <- function(plot = last_plot()) { 55 | gg_remove_background(plot = plot, canvas = FALSE, panel = FALSE, 56 | legend = TRUE, facet = FALSE) 57 | } 58 | 59 | 60 | #' \code{gg_remove_background_facet} Removes TODO 61 | #' @rdname gg_remove_background 62 | #' @export 63 | gg_remove_background_facet <- function(plot = last_plot()) { 64 | gg_remove_background(plot = plot, canvas = FALSE, panel = FALSE, 65 | legend = FALSE, facet = TRUE) 66 | } 67 | -------------------------------------------------------------------------------- /R/gg_remove_grid.R: -------------------------------------------------------------------------------- 1 | #' Remove grid lines from a plot 2 | #' 3 | #' \code{gg_remove_grid} removes either the major or minor grid lines on either 4 | #' axis. 5 | #' 6 | #' @param plot A ggplot2 plot object. By default, the last plot displayed is 7 | #' used. 8 | #' @param major.x Whether or not to remove grid lines at major breakpoints along the X axis (default: \code{TRUE}) 9 | #' @param major.y Whether or not to remove grid lines at major breakpoints along the Y axis (default: \code{TRUE}) 10 | #' @param minor.x Whether or not to remove grid lines at minor breakpoints along the X axis (default: \code{TRUE}) 11 | #' @param minor.y Whether or not to remove grid lines at minor breakpoints along the Y axis (default: \code{TRUE}) 12 | #' @return A modified ggplot2 plot 13 | #' 14 | #' @export 15 | #' @examples 16 | #' p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 17 | #' geom_point(shape = 1) 18 | #' gg_remove_grid(plot = p) 19 | #' 20 | gg_remove_grid <- function(plot = last_plot(), major.x = TRUE, major.y = TRUE, 21 | minor.x = TRUE, minor.y = TRUE) { 22 | if (major.x) plot <- plot + theme(panel.grid.major.x = element_blank()) 23 | if (major.y) plot <- plot + theme(panel.grid.major.y = element_blank()) 24 | if (minor.x) plot <- plot + theme(panel.grid.minor.x = element_blank()) 25 | if (minor.y) plot <- plot + theme(panel.grid.minor.y = element_blank()) 26 | 27 | plot 28 | } 29 | 30 | #' @description \code{gg_remove_grid_major} Removes grid lines at major breaks 31 | #' @rdname gg_remove_grid 32 | #' @export 33 | gg_remove_grid_major <- function(plot = last_plot(), major.x = TRUE, 34 | major.y = TRUE) { 35 | gg_remove_grid(plot = plot, major.x = major.x, major.y = major.y, 36 | minor.x = FALSE, minor.y = FALSE) 37 | } 38 | 39 | 40 | #' @description \code{gg_remove_grid_minor} Removes grid lines at minor breaks 41 | #' @rdname gg_remove_grid 42 | #' @export 43 | gg_remove_grid_minor <- function(plot = last_plot(), minor.x = TRUE, 44 | minor.y = TRUE) { 45 | gg_remove_grid(plot = plot, major.x = FALSE, major.y = FALSE, 46 | minor.x = minor.x, minor.y = minor.y) 47 | } 48 | 49 | 50 | #' @description \code{gg_remove_grid_x} Removes grid lines at major and minor 51 | #' breaks on the X axis 52 | #' @rdname gg_remove_grid 53 | #' @export 54 | gg_remove_grid_x <- function(plot = last_plot(), major = TRUE, minor = TRUE) { 55 | gg_remove_grid(plot = plot, major.x = major, major.y = FALSE, 56 | minor.x = minor, minor.y = FALSE) 57 | } 58 | 59 | 60 | #' @description \code{gg_remove_grid_y} Removes grid lines at major and minor 61 | #' breaks on the X axis 62 | #' @rdname gg_remove_grid 63 | #' @export 64 | gg_remove_grid_y <- function(plot = last_plot(), major = TRUE, minor = TRUE) { 65 | gg_remove_grid(plot = plot, major.x = FALSE, major.y = major, 66 | minor.x = FALSE, minor.y = minor) 67 | } 68 | -------------------------------------------------------------------------------- /R/gg_remove_legend.R: -------------------------------------------------------------------------------- 1 | #' Remove a legend or parts of a legend from a plot 2 | #' 3 | #' \code{gg_remove_legend} Removes a plot's legend or some of its components 4 | #' 5 | #' @param plot A ggplot2 plot object. By default, the last plot displayed is 6 | #' used. 7 | #' @param title Whether or not to remove the legend's title 8 | #' (default: \code{TRUE}) 9 | #' @param key Whether or not to remove the legend's key 10 | #' (default: \code{TRUE}) 11 | #' @param text Whether or not to remove the legend's key text 12 | #' (default: \code{TRUE}) 13 | #' @param background Whether or not to remove the legend's background 14 | #' (default: \code{TRUE}) 15 | #' @return A modified ggplot2 plot 16 | #' @export 17 | #' 18 | #' @examples 19 | #' p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 20 | #' geom_point(shape = 1) 21 | #' gg_remove_legend(plot = p) 22 | #' 23 | gg_remove_legend <- function(plot = last_plot(), title = TRUE, 24 | key = TRUE, text = TRUE, background = TRUE) { 25 | if (all(title, key, text, background)) { 26 | plot <- plot + theme(legend.position = "none") 27 | } 28 | else { 29 | if (title) plot <- plot + theme(legend.title = element_blank()) 30 | if (key) { 31 | plot <- plot + theme(legend.key = element_blank(), 32 | legend.key.size = unit(0, "pt"), 33 | legend.key.height = unit(0, "pt"), 34 | legend.key.width = unit(0, "pt")) 35 | } 36 | if (text) plot <- plot + theme(legend.text = element_blank()) 37 | if (background) { 38 | plot <- plot + theme(legend.background = element_blank()) 39 | } 40 | } 41 | 42 | plot 43 | } 44 | 45 | 46 | #' @description \code{gg_remove_legend_title} Removes legend's title 47 | #' @rdname gg_remove_legend 48 | #' @export 49 | gg_remove_legend_title <- function(plot = last_plot()) { 50 | gg_remove_legend(plot = plot, title = TRUE, key = FALSE, text = FALSE, 51 | background = FALSE) 52 | } 53 | 54 | 55 | #' @description \code{gg_remove_legend_key} Removes legend's key 56 | #' @rdname gg_remove_legend 57 | #' @export 58 | gg_remove_legend_key <- function(plot = last_plot()) { 59 | gg_remove_legend(plot = plot, title = FALSE, key = TRUE, text = FALSE, 60 | background = FALSE) 61 | } 62 | 63 | 64 | #' @description \code{gg_remove_legend_text} Removes legend's item labels 65 | #' @rdname gg_remove_legend 66 | #' @export 67 | gg_remove_legend_text <- function(plot = last_plot()) { 68 | gg_remove_legend(plot = plot, title = FALSE, key = FALSE, text = TRUE, 69 | background = FALSE) 70 | } 71 | 72 | 73 | #' @description \code{gg_remove_legend_background} Removes legend's background 74 | #' @rdname gg_remove_legend 75 | #' @export 76 | gg_remove_legend_background <- function(plot = last_plot()) { 77 | gg_remove_legend(plot = plot, title = FALSE, key = FALSE, text = FALSE, 78 | background = TRUE) 79 | } 80 | -------------------------------------------------------------------------------- /R/gg_remove_ticks.R: -------------------------------------------------------------------------------- 1 | #' Remove tick marks from a plot's axes 2 | #' 3 | #' \code{gg_remove_ticks} can remove ticks on either the X or Y axes. By 4 | #' default, all tick marks are removed. 5 | #' 6 | #' @param plot A ggplot2 plot object. By default, the last plot displayed is 7 | #' used. 8 | #' @param x Whether or not to remove X-axis ticks (default: \code{TRUE}) 9 | #' @param y Whether or not to remove Y-axis ticks (default: \code{TRUE}) 10 | #' @return A modified ggplot2 plot 11 | #' @export 12 | #' 13 | #' @examples 14 | #' p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 15 | #' geom_point(shape = 1) 16 | #' gg_remove_ticks(plot = p) 17 | #' 18 | gg_remove_ticks <- function(plot = last_plot(), x = TRUE, y = TRUE) { 19 | if (x) plot <- plot + theme(axis.ticks.x = element_blank()) 20 | if (y) plot <- plot + theme(axis.ticks.y = element_blank()) 21 | 22 | plot 23 | } 24 | 25 | #' @description \code{gg_remove_ticks_x} removes tick marks from the X axis 26 | #' @rdname gg_remove_ticks 27 | #' @export 28 | gg_remove_ticks_x <- function(plot = last_plot()) { 29 | gg_remove_ticks(plot = plot, x = TRUE, y = FALSE) 30 | } 31 | 32 | #' @description \code{gg_remove_ticks_y} removes tick marks from the Y axis 33 | #' @rdname gg_remove_ticks 34 | #' @export 35 | gg_remove_ticks_y <- function(plot = last_plot()) { 36 | gg_remove_ticks(plot = plot, x = FALSE, y = TRUE) 37 | } 38 | -------------------------------------------------------------------------------- /R/gg_remove_titles.R: -------------------------------------------------------------------------------- 1 | #' Remove titles from a plot 2 | #' 3 | #' \code{gg_remove_titles} removes title elements such as the main title, 4 | #' subtitle, caption, or axis titles. By default, all are removed. 5 | #' 6 | #' @param plot A ggplot2 plot object. By default, the last plot displayed is 7 | #' used. 8 | #' @param title Whether or not to remove the main title (default: \code{TRUE}) 9 | #' @param subtitle Whether or not to remove the subtitle (default: \code{TRUE}) 10 | #' @param caption Whether or not to remove the caption (default: \code{TRUE}) 11 | #' @param x Whether or not to remove the X axis title (default: \code{TRUE}) 12 | #' @param y Whether or not to remove the Y axis title (default: \code{TRUE}) 13 | #' 14 | #' @return A modified ggplot2 plot 15 | #' @export 16 | #' 17 | #' @examples 18 | #' p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 19 | #' geom_point(shape = 1) + 20 | #' labs(title = "Fuel Efficiency by Engine Type", 21 | #' subtitle = "Larger engines are less efficient", 22 | #' caption = "Source: Motor Trend", 23 | #' x = "Number of Cylinders", 24 | #' y = "Fuel Efficiency (MPG)") 25 | #' gg_remove_titles(plot = p) 26 | #' 27 | gg_remove_titles <- function(plot = last_plot(), title = TRUE, subtitle = TRUE, 28 | caption = TRUE, x = TRUE, y = TRUE) { 29 | if (title) plot <- plot + theme(plot.title = element_blank()) 30 | if (subtitle) plot <- plot + theme(plot.subtitle = element_blank()) 31 | if (caption) plot <- plot + theme(plot.caption = element_blank()) 32 | if (x) plot <- plot + theme(axis.title.x = element_blank()) 33 | if (y) plot <- plot + theme(axis.title.y = element_blank()) 34 | 35 | plot 36 | } 37 | 38 | 39 | #' @description \code{gg_remove_title} Removes the plot's main title 40 | #' @rdname gg_remove_titles 41 | #' @export 42 | gg_remove_title <- function(plot = last_plot()) { 43 | gg_remove_titles(title = TRUE, subtitle = FALSE, caption = FALSE, x = FALSE, 44 | y = FALSE) 45 | } 46 | 47 | 48 | #' @description \code{gg_remove_subtitle} Removes the plot's subtitle 49 | #' @rdname gg_remove_titles 50 | #' @export 51 | gg_remove_subtitle <- function(plot = last_plot()) { 52 | gg_remove_titles(title = FALSE, subtitle = TRUE, caption = FALSE, x = FALSE, 53 | y = FALSE) 54 | } 55 | 56 | 57 | #' @description \code{gg_remove_caption} Removes the plot caption 58 | #' @rdname gg_remove_titles 59 | #' @export 60 | gg_remove_caption <- function(plot = last_plot()) { 61 | gg_remove_titles(title = FALSE, subtitle = FALSE, caption = TRUE, x = FALSE, 62 | y = FALSE) 63 | } 64 | 65 | 66 | #' @description \code{gg_remove_title.x} Removes the X-axis title 67 | #' @rdname gg_remove_titles 68 | #' @export 69 | gg_remove_title.x <- function(plot = last_plot()) { 70 | gg_remove_titles(title = FALSE, subtitle = FALSE, caption = FALSE, x = TRUE, 71 | y = FALSE) 72 | } 73 | 74 | 75 | #' @description \code{gg_remove_title.y} Removes the Y-axis title 76 | #' @rdname gg_remove_titles 77 | #' @export 78 | gg_remove_title.y <- function(plot = last_plot()) { 79 | gg_remove_titles(title = FALSE, subtitle = FALSE, caption = FALSE, 80 | x = FALSE, y = TRUE) 81 | } 82 | -------------------------------------------------------------------------------- /R/gg_rescale.R: -------------------------------------------------------------------------------- 1 | #' Rescale a ggplot2 plot so that axes follow a given ratio 2 | #' 3 | #' \code{gg_rescale} rescales the given ggplot2 so that the axes follow the 4 | #' given ratio (horizontally). If a plot is not specified, the last plot 5 | #' displayed is used. 6 | #' 7 | #' @export 8 | #' @param plot A ggplot2 plot object. By default, the last plot displayed is 9 | #' used. 10 | #' @param ratio The aspect ratio to use for the axes. This is independent of 11 | #' units used in the plot, so the size of the X axis will be ratio times the 12 | #' total size of the Y axis. 13 | #' @return A modified ggplot2 plot 14 | #' @examples 15 | #' p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 16 | #' geom_point(shape = 1) 17 | #' gg_rescale(ratio = 1.67) 18 | #' 19 | gg_rescale <- function(plot = last_plot(), ratio) { 20 | plot + theme(aspect.ratio = 1 / ratio) 21 | } 22 | 23 | #' @export 24 | rescale_plot <- function(plot = last_plot(), ratio) { 25 | warning("rescale_plot is depricated. Use gg_rescale instead.") 26 | gg_rescale(plot = plot, ratio = ratio) 27 | } 28 | 29 | 30 | #' @description \code{gg_rescale_golden} rescales a ggplot2 plot so that axes 31 | #' follow golden ratio 32 | #' @rdname gg_rescale 33 | #' @param orient Whether the golden ratio should be horizontal 34 | #' (\code{h}; default) or vertical (\code{v}) 35 | #' @export 36 | #' 37 | gg_rescale_golden <- function(plot = last_plot(), orient = "h") { 38 | gr <- (1 + sqrt(5)) / 2 39 | 40 | if (orient == "h") { 41 | gg_rescale(plot = plot, ratio = gr) 42 | } 43 | else if (orient == "v") { 44 | gg_rescale(plot = plot, ratio = 1/gr) 45 | } 46 | else { 47 | stop("Invalid orientation. Must be either 'h' or 'v'") 48 | } 49 | } 50 | 51 | #' @export 52 | rescale_golden <- function(plot = last_plot()) { 53 | warning("rescale_golden is depricated. Use gg_rescale_golden instead.") 54 | gg_rescale_golden(plot = plot) 55 | } 56 | 57 | 58 | #' @description \code{gg_rescale_square} rescales a ggplot2 plot so that its 59 | #' axes are square 60 | #' @rdname gg_rescale 61 | #' @export 62 | #' 63 | gg_rescale_square <- function(plot = last_plot()) { 64 | gg_rescale(plot = plot, ratio = 1) 65 | } 66 | 67 | #' @export 68 | rescale_square <- function(plot = last_plot()) { 69 | warning("rescale_square is depricated. Use gg_rescale_square instead.") 70 | gg_rescale_square(plot = plot) 71 | } -------------------------------------------------------------------------------- /R/gg_supports_theme_attribute.R: -------------------------------------------------------------------------------- 1 | #' Determine whether installed ggplot2 supports a given theme attribute 2 | #' 3 | #' @param x The name of an attribute (e.g., "plot.caption") 4 | #' 5 | #' @return A logical value indicating whether the given attribute is supported 6 | #' (\code{TRUE}) or not (\code{FALSE}). 7 | #' @seealso \code{\link[ggplot2]{theme}} 8 | #' @export 9 | #' 10 | #' @examples 11 | #' gg_supports_theme_attribute("plot.caption") 12 | #' 13 | gg_supports_theme_attribute <- function(x) { 14 | x %in% names(formals(fun = ggplot2::theme)) 15 | } 16 | -------------------------------------------------------------------------------- /R/ggplot2bdc.R: -------------------------------------------------------------------------------- 1 | #' Themes and functions for creating plots with ggplot2 2 | #' 3 | #' \code{ggplot2bdc} is a package that contains themes and functions that can 4 | #' be used when creating plots with \code{\link{ggplot2}}. 5 | #' 6 | #' @docType package 7 | #' @name ggplot2bdc 8 | #' @import ggplot2 9 | #' @import grid 10 | NULL 11 | -------------------------------------------------------------------------------- /R/ggsave_golden.R: -------------------------------------------------------------------------------- 1 | #' Save a plot with proportions equal to the golden ratio 2 | #' 3 | #' \code{ggsave_golden} is a wrapper for \code{\link{ggsave}} that saves a 4 | #' ggplot to a file with proportions equal to the golden ratio (wide). 5 | #' 6 | #' @export 7 | #' @param filename The name of the file to be written to 8 | #' @param plot The plot object to save. Defaults to last plot displayed. 9 | #' @param width The width of the resulting image (default: 8) 10 | #' @param height The height of the resulting image (default: 4.94) 11 | #' @param ... Additional parameters to be passed to \code{\link{ggsave}} 12 | #' @importFrom ggplot2 ggsave 13 | 14 | ggsave_golden <- function(filename, plot=last_plot(), ...) { 15 | ggsave(filename = filename, plot = plot, width = 8, 16 | height = 8/1.61803398875, ...) 17 | } 18 | -------------------------------------------------------------------------------- /R/span.R: -------------------------------------------------------------------------------- 1 | #' Calculate the distance between the minimum and maximum values 2 | #' 3 | #' \code{span} calculates the distance between a vector's minimum and maximum 4 | #' values. Only finite and non-NA values are considered. 5 | #' 6 | #' @export 7 | #' @examples 8 | #' vals <- sample(1:100, 10) 9 | #' span(vals) 10 | #' 11 | span <- function(n) { 12 | diff(range(n, na.rm = TRUE, finite = TRUE)) 13 | } 14 | -------------------------------------------------------------------------------- /R/theme_bdc_grey.R: -------------------------------------------------------------------------------- 1 | #' Clean theme with grey box and axis ticks 2 | #' 3 | #' \code{theme_bdc_grey} is a \code{\link{ggplot2}} theme that produces a plot 4 | #' in a simple grey panel on a white background. Facet labels are displayed as 5 | #' black text on a grey background. Grid lines can be enabled using 6 | #' the \code{grid.x} and \code{grid.y} parameters. Tick marks can be disabled 7 | #' using the \code{ticks.x} and \code{ticks.y} parameters. 8 | #' 9 | #' @export 10 | #' @aliases theme_bdc_gray 11 | #' @param base_size The base size for all text (default: 12) 12 | #' @param base_family The base font family for all text 13 | #' @param base_grey The base color to use for rects, lines, etc (default: "grey70") 14 | #' @param grid.x Show grid lines along the X axis (default: FALSE) 15 | #' @param grid.y Show grid lines along the Y axis (default: FALSE) 16 | #' @param gridmin.x Show minor grid lines along the X axis (default: FALSE) 17 | #' @param gridmin.y Show minor grid lines along the Y axis (default: FALSE) 18 | #' @param ticks.x Show tick marks along the X axis (default: TRUE) 19 | #' @param ticks.y Show tick marks along th Y axis (default: TRUE) 20 | #' @param pmargin Margin around the plot (default: 1/2 line) 21 | #' @return A list of ggplot theme parameters 22 | #' @seealso \code{\link{theme}} 23 | #' @import ggplot2 24 | #' @importFrom grid unit 25 | #' @examples 26 | #' library(ggplot2) 27 | #' 28 | #' p <- ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point() + theme_bdc_grey() 29 | #' p 30 | #' 31 | #' 32 | 33 | theme_bdc_grey <- function(base_size = 12, base_family = "", 34 | base_grey = "grey70", 35 | grid.x = FALSE, grid.y = FALSE, 36 | gridmin.x = grid.x, gridmin.y = grid.y, 37 | ticks.x = TRUE, ticks.y = TRUE, 38 | pmargin = base_size / 2) { 39 | half_line <- base_size / 2 40 | quarter_line <- base_size / 4 41 | line_size <- 0.5 42 | medgrey <- "grey40" 43 | 44 | t <- theme( 45 | line = element_line(color = base_grey, size = line_size, 46 | linetype = 1, lineend = "square"), 47 | rect = element_rect(fill = "white", color = base_grey, 48 | size = line_size, linetype = 1), 49 | text = element_text(family = base_family, face = "plain", 50 | color = "black", size = base_size, 51 | lineheight = 0.9, hjust = 0.5, vjust = 0.5, 52 | angle = 0, margin = margin(), debug = FALSE), 53 | 54 | axis.line = element_blank(), 55 | axis.text = element_text(size = rel(0.8), color = medgrey), 56 | axis.text.x = element_text( 57 | margin = margin(t = 0.8 * quarter_line), 58 | vjust = 1 59 | ), 60 | axis.text.y = element_text( 61 | margin = margin(r = 0.8 * quarter_line), 62 | hjust = 1 63 | ), 64 | axis.ticks = element_line(size = line_size / 2), 65 | axis.ticks.x = element_line( 66 | size = ifelse(ticks.x, line_size / 2, 0) 67 | ), 68 | axis.ticks.y = element_line( 69 | size = ifelse(ticks.y, line_size / 2, 0) 70 | ), 71 | axis.ticks.length = unit(quarter_line, units = "pt"), 72 | axis.title.x = element_text( 73 | margin = margin(t = 0.8 * half_line, b = 0.8 * quarter_line) 74 | ), 75 | axis.title.y = element_text( 76 | angle = 90, 77 | margin = margin(r = 0.8 * half_line, l = 0.8 * quarter_line) 78 | ), 79 | 80 | legend.background = element_rect(fill = "transparent", color = NA), 81 | legend.margin = margin(0, 0, 0, 0), 82 | legend.spacing = unit(0, units = "cm"), 83 | legend.key = element_rect(fill = "transparent", color = NA), 84 | legend.key.size = unit(0.5, units = "lines"), 85 | legend.key.height = unit(0.5, units = "lines"), 86 | legend.key.width = unit(1.0, units = "lines"), 87 | legend.text = element_text(size = rel(0.6), hjust = 0, vjust = 0.5, 88 | color = medgrey), 89 | legend.text.align = NULL, 90 | legend.title = element_text(size = rel(0.6), face = "bold", 91 | vjust = 0.5), 92 | legend.title.align = 1, 93 | legend.position = "top", 94 | legend.direction = "horizontal", 95 | legend.justification = "center", 96 | legend.box = "vertical", 97 | legend.box.just = "left", 98 | legend.box.margin = margin(0, 0, 0, 0, unit = "pt"), 99 | legend.box.background = element_blank(), 100 | legend.box.spacing = unit(6, units = "pt"), 101 | 102 | panel.background = element_rect(fill = "white", color = base_grey), 103 | panel.border = element_blank(), 104 | panel.grid.major = element_line(color = NA, size = line_size / 5), 105 | panel.grid.major.x = element_line( 106 | color = ifelse(grid.x, base_grey, NA) 107 | ), 108 | panel.grid.major.y = element_line( 109 | color = ifelse(grid.y, base_grey, NA) 110 | ), 111 | panel.grid.minor = element_line(color = NA, size = line_size / 10), 112 | panel.grid.minor.x = element_line( 113 | color = ifelse(gridmin.x, base_grey, NA) 114 | ), 115 | panel.grid.minor.y = element_line( 116 | color = ifelse(gridmin.y, base_grey, NA) 117 | ), 118 | panel.spacing = unit(quarter_line, units = "pt"), 119 | panel.spacing.x = NULL, 120 | panel.spacing.y = NULL, 121 | panel.ontop = FALSE, 122 | 123 | strip.background = element_rect(fill = "transparent", color = NA), 124 | strip.text = element_text( 125 | color = "grey40", 126 | size = rel(0.8), 127 | face = "bold" 128 | ), 129 | strip.text.x = element_text( 130 | margin = margin(t = quarter_line, b = quarter_line) 131 | ), 132 | strip.text.y = element_text( 133 | angle = -90, 134 | margin = margin(l = quarter_line, r = quarter_line) 135 | ), 136 | strip.switch.pad.grid = unit(0.1, units = "cm"), 137 | strip.switch.pad.wrap = unit(0.1, units = "cm"), 138 | 139 | plot.background = element_rect(color = "transparent"), 140 | plot.title = element_text( 141 | size = rel(1.2), 142 | face = "bold", 143 | hjust = 0, 144 | margin = margin(b = half_line * 1.2) 145 | ), 146 | plot.subtitle = element_text( 147 | size = rel(0.8), 148 | color = "grey40", 149 | face = "italic", 150 | hjust = 0, 151 | margin = margin(b = (base_size / 2) * 1.2) 152 | ), 153 | plot.caption = element_text( 154 | size = rel(0.7), 155 | color = "grey40", 156 | face = "plain", 157 | hjust = 0, 158 | margin = margin(b = base_size * 0.4, t = base_size * 0.4, 159 | r = 0, l = 0) 160 | ), 161 | plot.margin = margin(pmargin, pmargin, pmargin, pmargin), 162 | complete = TRUE 163 | ) 164 | 165 | t 166 | } 167 | 168 | #' @export 169 | theme_bdc_gray <- theme_bdc_grey 170 | -------------------------------------------------------------------------------- /R/theme_bdc_lattice_population.R: -------------------------------------------------------------------------------- 1 | #' Theme for displaying populations structured on a lattice 2 | #' 3 | #' \code{theme_bdc_lattice_population} is a \code{\link{ggplot2}} theme that 4 | #' produces a plot where many graphical details such as tick marks and axis 5 | #' labels and text have been removed. This theme is intended to be used to 6 | #' display simluated populations where individuals are arranged on a lattice. 7 | #' 8 | #' @export 9 | #' @param base_size The base size for all text (default: 10) 10 | #' @param base_family The base font family for all text 11 | #' @return A list of ggplot theme parameters 12 | #' @seealso \code{\link{theme}} 13 | #' 14 | 15 | theme_bdc_lattice_population <- function(base_size = 12, base_family = "") { 16 | t <- theme_void(base_size = base_size, base_family = base_family) %+replace% 17 | theme( 18 | panel.spacing = unit(0, "pt"), 19 | plot.title = element_text( 20 | size = rel(1.2), 21 | face = "bold", 22 | hjust = 0, 23 | margin = margin(b = base_size * 0.6) 24 | ), 25 | plot.margin = margin(t = 0, r = 0, b = 0, l = 0), 26 | strip.text.x = element_text( 27 | margin = margin(t = 2, b = 2) 28 | ), 29 | strip.text.y = element_text( 30 | angle = -90, 31 | margin = margin(l = 2, r = 2) 32 | ), 33 | plot.caption = element_text( 34 | size = rel(0.7), 35 | color = "grey40", 36 | face = "plain", 37 | hjust = 0, 38 | margin = margin(b = base_size * 0.4, t = base_size * 0.4, 39 | r = 0, l = 0) 40 | ), 41 | plot.subtitle = element_text( 42 | size = rel(0.8), 43 | color = "grey40", 44 | face = "italic", 45 | hjust = 0, 46 | margin = margin(b = base_size * 0.6) 47 | ), 48 | legend.box.margin = margin(0, 0, 0, 0, unit = "pt"), 49 | legend.box.spacing = unit(6, units = "pt") 50 | ) 51 | 52 | t 53 | } 54 | -------------------------------------------------------------------------------- /R/theme_bdc_microtiter.R: -------------------------------------------------------------------------------- 1 | #' Theme for displaying Microtiter plates 2 | #' 3 | #' \code{theme_bdc_microtiter} is a \code{\link{ggplot2}} theme that produces a 4 | #' plot that resembles a 96-well microtiter plate. This is useful for displaying 5 | #' either data from the plate or information about the plate in a spatial 6 | #' context. 7 | #' 8 | #' @export 9 | #' @param base_size The base size for all text (default: 14) 10 | #' @param base_family The base font family for all text 11 | #' @return A list of ggplot theme parameters 12 | #' 13 | theme_bdc_microtiter <- function(base_size = 12, base_family = "") { 14 | t <- theme_bdc_grey(base_size = base_size, base_family = base_family, 15 | grid.x = FALSE, grid.y = FALSE, 16 | gridmin.x = FALSE, gridmin.y = FALSE, 17 | ticks.x = FALSE, ticks.y = FALSE, 18 | pmargin = base_size / 2) %+replace% 19 | theme( 20 | panel.spacing = unit(0, units = "pt"), 21 | axis.title = element_blank(), 22 | axis.text = element_text(size = rel(1.0), face = "bold"), 23 | axis.text.y = element_text( 24 | margin = margin(r = 0.4 * base_size, l = 0.4 * base_size) 25 | ), 26 | axis.text.x = element_text( 27 | margin = margin(t = 0.4 * base_size, b = 0.4 * base_size) 28 | ), 29 | axis.ticks.length = unit(0, "pt"), 30 | legend.position = "bottom", 31 | legend.direction = "horizontal", 32 | legend.box = "vertical", 33 | legend.spacing = unit(6, "pt"), 34 | plot.title = element_text( 35 | size = rel(1.2), 36 | face = "bold", 37 | hjust = 0.5, 38 | margin = margin(b = (base_size / 2) * 1.2) 39 | ), 40 | plot.subtitle = element_text( 41 | size = rel(0.8), 42 | color = "grey50", 43 | hjust = 0.5, 44 | margin = margin(b = (base_size / 2) * 1.2) 45 | ) 46 | ) 47 | 48 | t 49 | } 50 | -------------------------------------------------------------------------------- /R/theme_bdc_paneled.R: -------------------------------------------------------------------------------- 1 | #' Clean, borderless theme with grey panels and axis ticks 2 | #' 3 | #' \code{theme_bdc_paneled} is a \code{\link{ggplot2}} theme that produces a plot 4 | #' with simple grey panels on a white background. Facet labels are displayed as 5 | #' black text. Grid lines can be enabled using the \code{grid.x} and 6 | #' \code{grid.y} parameters. By default, grid lines along the Y axis are shown. 7 | #' Tick marks can be disabled using the \code{ticks.x} and \code{ticks.y} 8 | #' parameters. 9 | #' 10 | #' @export 11 | #' @param base_size The base size for all text (default: 12) 12 | #' @param base_family The base font family for all text 13 | #' @param grid.x Show grid lines along the X axis (default: FALSE) 14 | #' @param grid.y Show grid lines along the Y axis (default: TRUE) 15 | #' @param gridmin.x Show minor grid lines along the X axis (default: FALSE) 16 | #' @param gridmin.y Show minor grid lines along the Y axis (default: FALSE) 17 | #' @param ticks.x Show tick marks along the X axis (default: TRUE) 18 | #' @param ticks.y Show tick marks along th Y axis (default: TRUE) 19 | #' @param pmargin Margin around the plot (default: 1/2 line) 20 | #' @return A list of ggplot theme parameters 21 | #' @seealso \code{\link{theme}} 22 | #' @examples 23 | #' library(ggplot2) 24 | #' 25 | #' p <- ggplot(movies, aes(x=year, y=budget)) + geom_point() + theme_bdc_paneled() 26 | #' p 27 | #' 28 | theme_bdc_paneled <- function(base_size = 12, base_family = "", 29 | grid.x = FALSE, grid.y = TRUE, 30 | gridmin.x = FALSE, gridmin.y = FALSE, 31 | ticks.x = TRUE, ticks.y = TRUE, 32 | pmargin = base_size / 2) { 33 | 34 | line_size <- 0.5 35 | panel_color <- "grey95" 36 | line_color <- "grey85" 37 | 38 | theme_bdc_grey(base_size = base_size, base_family = base_family, 39 | grid.x = grid.x, grid.y = grid.y, 40 | gridmin.x = gridmin.x, gridmin.y = gridmin.y, 41 | ticks.x = ticks.x, ticks.y = ticks.y, 42 | pmargin = pmargin) %+replace% 43 | theme( 44 | line = element_line(color = line_color, size = line_size / 4, 45 | linetype = 1, lineend = "square"), 46 | rect = element_rect(fill = "white", color = line_color, 47 | size = line_size, linetype = 1), 48 | panel.background = element_rect(fill = panel_color, color = NA), 49 | axis.ticks.x = element_line( 50 | color = ifelse(ticks.x, "grey75", NA), 51 | size = ifelse(ticks.x, line_size / 4, 0) 52 | ), 53 | axis.ticks.y = element_line( 54 | color = ifelse(ticks.y, "grey75", NA), 55 | size = ifelse(ticks.y, line_size / 4, 0) 56 | ), 57 | strip.background = element_rect(fill = line_color, 58 | color = line_color) 59 | ) 60 | } 61 | -------------------------------------------------------------------------------- /R/trim_whitespace.R: -------------------------------------------------------------------------------- 1 | #' Remove whitespace from around an image 2 | #' 3 | #' \code{trim_whitespace} crops an image, removing any whitespace from around 4 | #' it. 5 | #' 6 | #' @note This function requires \href{http://pdfcrop.sourceforge.net}{PDFCrop} 7 | #' for PDFs and \href{http://www.imagemagick.org/script/index.php}{ImageMagick} 8 | #' for other formats. 9 | #' 10 | #' @param filename Image to be cropped 11 | #' @param ... Optional arguments 12 | #' @export 13 | #' 14 | #' @examples 15 | #' \dontrun{ 16 | #' trim_whitespace("my_figure.pdf") 17 | #' } 18 | trim_whitespace <- function(filename, ...) { 19 | ext <- tolower(tools::file_ext(filename)) 20 | full_path <- path.expand(filename) 21 | file_args <- sprintf("'%s' '%s'", full_path, full_path) 22 | other_args <- list(...) 23 | 24 | if (identical(ext, "pdf")) { 25 | margin_args <- NULL 26 | if ("margins" %in% names(other_args)) { 27 | if (length(other_args$margins) %in% c(1, 4)) { 28 | margin_args <- sprintf("--margins '%s'", 29 | paste0(other_args$margins, 30 | collapse = " ")) 31 | } 32 | else { 33 | stop(sprintf("margins should have 1 or 4 values. %d given.", 34 | length(margin))) 35 | } 36 | } 37 | system2( 38 | command = "pdfcrop", 39 | args = paste0(c(margin_args, file_args), collapse = " ") 40 | ) 41 | } else { 42 | # Use magick package. At the moment, it's not working correctly. 43 | system2( 44 | command = "convert", 45 | args = paste0(c("-trim", file_args), collapse = " ") 46 | ) 47 | } 48 | } -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: ggplot2bdc README 3 | author: Brian Connelly 4 | output: md_document 5 | --- 6 | 7 | ```{r global_options, echo=FALSE} 8 | knitr::opts_chunk$set(fig.path="figure/", warning=FALSE, message=FALSE, 9 | error=FALSE) 10 | ``` 11 | 12 | # ggplot2bdc 13 | 14 | ggplot2bdc is a collection of themes and other things that can be used when creating plots with [ggplot2](http://ggplot2.org/). 15 | For those using the [development version of ggplot](https://github.com/hadley/ggplot2), subtitles and captions are supported. 16 | 17 | - Themes 18 | - `theme_bdc_grey` 19 | - `theme_bdc_paneled` 20 | - `theme_bdc_microtiter` 21 | - `theme_bdc_lattice_population` 22 | - Modifying Plots 23 | - Removing Plot Elements 24 | - `gg_remove_titles`, `gg_remove_title`, `gg_remove_subtitle`, `gg_remove_caption`, `gg_remove_title.x`, `gg_remove_title.y` 25 | - `gg_remove_ticks`, `gg_remove_ticks_x`, `gg_remove_ticks_y` 26 | - `gg_remove_grid`, `gg_remove_grid_major`, `gg_remove_grid_minor`, `gg_remove_grid_x`, `gg_remove_grid_y` 27 | - `gg_remove_legend`, `gg_remove_legend_title`, `gg_remove_legend_key`, `gg_remove_legend_text`, `gg_remove_legend_background` 28 | - `gg_remove_background`, `gg_remove_background_canvas`, `gg_remove_background_legend`, `gg_remove_background_facet` 29 | - Rescaling 30 | - `gg_rescale` 31 | - `gg_rescale_golden` 32 | - `gg_rescale_square` 33 | - Modifying Files Containing Plots 34 | - `trim_whitespace` 35 | - Misc 36 | - `ggsave_golden` 37 | - `span` 38 | 39 | 40 | ## Installation 41 | 42 | `ggplot2bdc` is not on [CRAN](http://cran.r-project.org/), but you can use [devtools](http://cran.r-project.org/web/packages/devtools/index.html) to install the latest and greatest version. 43 | To do so: 44 | 45 | ```{r Installation, eval=FALSE} 46 | if(!require("devtools")) install.packages("devtools") 47 | devtools::install_github("briandconnelly/ggplot2bdc") 48 | ``` 49 | 50 | ## Examples 51 | 52 | To gain access to the following themes, etc. provided, first load the `gplot2bdc` package. 53 | We'll also load `ggplot`, `dplyr`, and `magrittr` for these examples. 54 | 55 | ```{r} 56 | library(ggplot2bdc) 57 | library(ggplot2) 58 | library(dplyr) 59 | library(magrittr) 60 | ``` 61 | 62 | ### Themes 63 | 64 | #### theme_bdc_grey 65 | 66 | `theme_bdc_grey` is a clean theme that uses thin grey panels on a white background. 67 | Legends are placed above. 68 | Facet labels are displayed as black text on a grey background. 69 | 70 | ```{r theme_bdc_grey} 71 | pUnemploy <- ggplot(data = economics, aes(x = date, y = unemploy)) + 72 | geom_line() + 73 | scale_x_date() + 74 | labs(x = "Year", y = "Thousands of Persons", 75 | title = "Monthly Unemployment", subtitle = "Seasonally Adjusted", 76 | caption = "Source: Federal Reserve Bank of St. Louis") + 77 | theme_bdc_grey() 78 | pUnemploy 79 | ``` 80 | 81 | Subtle grid lines can be added to the panels with the `grid.x` and `grid.y` parameters. 82 | These also affect minor grid lines, which can further be controlled with the `gridmin.x` and `gridmin.y` parameters. 83 | 84 | ```{r theme_bdc_grey_grid} 85 | midwest$inmetro <- factor(midwest$inmetro, levels = c(0, 1), 86 | labels = c("Rural", "Metro")) 87 | 88 | ggplot(data = midwest, 89 | aes(x = inmetro, y = percbelowpoverty, color = state, shape = state)) + 90 | stat_summary(fun.y = "mean", geom = "line", aes(group = state)) + 91 | stat_summary(fun.y = "mean", geom = "point") + 92 | scale_color_hue(name = "State") + 93 | scale_shape_discrete(name = "State") + 94 | labs(x = NULL, y = "Percent", 95 | title = "Poverty in the Midwest", 96 | subtitle = "Poverty rates in rural and metro communities") + 97 | coord_equal(ratio = 0.5) + 98 | theme_bdc_grey(ticks.x = FALSE, grid.y = TRUE) 99 | ``` 100 | 101 | Some people prefer to display categorical data without tick marks along the axis. 102 | These are included by default, but can be removed by setting either the `ticks.x` or `ticks.y` parameters to `FALSE`. 103 | 104 | We can also use facets to divide the data by state: 105 | 106 | ```{r theme_bdc_grey-facets1} 107 | ggplot(data = midwest, aes(x = inmetro, y = percbelowpoverty)) + 108 | facet_grid(. ~ state) + 109 | stat_summary(fun.y = "mean", geom = "line", aes(group = state)) + 110 | stat_summary(fun.y = "mean", geom = "point") + 111 | labs(x = NULL, y = "Percent", 112 | title = "Poverty in the Midwest", 113 | subtitle = "Poverty rates in rural and metro communities") + 114 | coord_equal(ratio = 0.5) + 115 | theme_bdc_grey(grid.y = TRUE) 116 | ``` 117 | 118 | 119 | ```{r theme_bdc_grey-facets2} 120 | txcities <- txhousing %>% 121 | filter(city %in% c("Austin", "Dallas", "El Paso", "Fort Worth", "Houston", 122 | "San Antonio")) 123 | 124 | pTX <- ggplot(data = txcities, aes(x = year, y = median / 1000)) + 125 | facet_grid(city ~ .) + 126 | stat_summary(fun.data = "mean_cl_boot", geom = "ribbon", 127 | color = NA, alpha = 0.3) + 128 | stat_summary(fun.y = "mean", geom = "line") + 129 | labs(x = "Year", y = "Thousands of Dollars", 130 | title = "Home Prices are Getting Bigger in Texas", 131 | subtitle = "Median Home Prices in Texas' Largest Cities", 132 | caption = "Source: TAMU Real Estate Center") 133 | 134 | pTX + theme_bdc_grey() 135 | ``` 136 | 137 | 138 | #### theme_bdc_paneled 139 | 140 | `theme_bdc_paneled` is a clean theme that displays plots without borders on grey panels. 141 | Legends are placed above. 142 | Facet labels are displayed as plan black text. 143 | Subtle grid lines can be added to the panels with the `grid.x` and `grid.y` parameters, and tick marks can be managed with `ticks.x` and `ticks.y`. 144 | By default, grid lines are used along the Y axis. 145 | This theme is best suited for plots with multiple facets. 146 | 147 | ```{r theme_bdc_paneled} 148 | pTX + theme_bdc_paneled() 149 | ``` 150 | 151 | 152 | #### theme_bdc_microtiter 153 | 154 | `theme_bdc_microtiter` is a specialized theme for use in creating figures that represent 96-well microtiter plates. 155 | 156 | ```{r loadplatemap,echo=FALSE} 157 | library(dplyr) 158 | platemap <- read.csv("~/Dropbox/Research/Documents/Blog/Blog Post-Analyzing Bacterial Growth/data/platemap.csv") %>% 159 | mutate(Row = as.numeric(match(toupper(substr(Well,1,1)), LETTERS)), Column = as.numeric(substr(Well,2,5))) 160 | platemap$Environment <- as.factor(platemap$Environment) 161 | ``` 162 | 163 | ```{r theme_bdc_microtiter} 164 | pPlate <- ggplot(data = platemap, aes(x = Column, y = Row)) + 165 | geom_point(data = expand.grid(Column = seq(1,12), Row = seq(1,8)), 166 | color = "grey90", fill = "white", shape = 21, size = 8) + 167 | geom_point(aes(shape = Environment, color = Strain), size = 9) + 168 | coord_fixed(ratio = (13/12)/(9/8), xlim = c(0.5, 12.5), ylim = c(0.6, 8.4)) + 169 | scale_y_reverse(breaks = seq(1, 8), labels = LETTERS[1:8]) + 170 | scale_x_continuous(breaks = seq(1, 12), position = "top") + 171 | labs(title = "Plate Layout for My Experiment", subtitle = "25 March 2016") + 172 | guides(shape = guide_legend(override.aes = list(size = 3)), 173 | color = guide_legend(override.aes = list(size = 3))) + 174 | theme_bdc_microtiter() 175 | 176 | pPlate 177 | ``` 178 | 179 | 180 | For more information, see the [Plotting Microtiter Plate Maps](http://bconnelly.net/2014/05/plotting-microtiter-plate-maps/). 181 | 182 | #### theme_bdc_lattice_population 183 | 184 | `theme_bdc_lattice_population` is a specialized theme intended to display populations of individuals structured spatially in a lattice. 185 | 186 | ```{r theme_bdc_lattice_population} 187 | ggplot(data = filter(rockpaperscissors, Time == 10), 188 | aes(x = X, y = Y, color = Type)) + 189 | geom_point(shape=15) + 190 | coord_equal(ratio=1) + 191 | scale_color_hue() + 192 | theme_bdc_lattice_population() 193 | ``` 194 | 195 | We can also show multiple population states: 196 | 197 | ```{r theme_bdc_lattice_population-facets} 198 | ggplot(data = filter(rockpaperscissors, Time %in% c(0, 200, 400, 600)), 199 | aes(x = X, y = Y, color = Type)) + 200 | facet_wrap(~Time, nrow = 1, ncol = 4) + 201 | geom_point(shape = 15) + 202 | coord_equal(ratio = 1) + 203 | scale_color_hue(guide = FALSE) + 204 | labs(title = "Rock, Paper, Scissors", 205 | subtitle = "Wait, is it ON three or AFTER three?", 206 | caption = "Data from simulation on a 50x50 lattice") + 207 | theme_bdc_lattice_population() 208 | ``` 209 | 210 | 211 | This is also a great opportunity to create an animation. 212 | We can use [gganimate](https://github.com/dgrtwo/gganimate) to create an animated GIF showing the population for the first 10 time steps. 213 | 214 | ```{r lattice-animation, eval=FALSE} 215 | library(gganimate) 216 | 217 | p <- ggplot(data = filter(rockpaperscissors, Time < 10), 218 | aes(x = X, y = Y, color = Type, frame = Time)) + 219 | geom_point(shape = 15, size = 3) + 220 | coord_equal(ratio = 1) + 221 | scale_color_hue(guide = FALSE) + 222 | labs(title = "Rock, Paper, Scissors at t=") + 223 | theme_bdc_lattice_population() 224 | 225 | gg_animate(p = p, saver = "gif", interval = 0.2) 226 | ``` 227 | 228 | ```{r lattice-animation-save, echo=FALSE} 229 | library(gganimate) 230 | 231 | p <- ggplot(data = filter(rockpaperscissors, Time < 10), 232 | aes(x = X, y = Y, color = Type, frame = Time)) + 233 | geom_point(shape = 15, size = 3) + 234 | coord_equal(ratio = 1) + 235 | scale_color_hue(guide = FALSE) + 236 | labs(title = "Rock, Paper, Scissors at t=") + 237 | theme_bdc_lattice_population() 238 | gg_animate(p = p, filename = "figure/lattice-anim.gif", interval = 0.2) 239 | ``` 240 | 241 | ![](figure/lattice-anim.gif) 242 | 243 | 244 | ### Modifying Plots 245 | 246 | Although you can always change a plot's properties using ggplot2's `theme` function, it's often difficult to remember which elements control a plot's visual characteristics. 247 | These and other `gg_` functions make it a bit easier to quickly alter a plot. 248 | 249 | 250 | #### gg_rescale_golden 251 | 252 | `gg_rescale_golden` adjusts the proportions of the axes of the given plot object so that follow the golden ratio (horizontally). 253 | If no plot is provided, the last plot that was displayed is used. 254 | 255 | ```{r gg_rescale_golden} 256 | ggplot(mtcars, aes(x = hp, y = mpg)) + 257 | geom_smooth(method = "loess") + 258 | geom_point(shape = 1) + 259 | labs(x = "Horsepower", y = "Fuel Efficiency (mpg)") + 260 | theme_bdc_grey() 261 | ``` 262 | 263 | ```{r gg_rescale_golden2} 264 | gg_rescale_golden() 265 | ``` 266 | 267 | 268 | #### gg_rescale_square 269 | 270 | `gg_rescale_square` adjusts the proportions of the axes of the given plot object so that they are equal. 271 | If no plot is provided, the last plot that was displayed is used. 272 | 273 | ```{r gg_rescale_square} 274 | ggplot(data = economics, aes(x = date, y = unemploy)) + 275 | geom_line() + 276 | labs(x = "Date", y = "Thousands of Unemployed Persons") + 277 | theme_bdc_grey() 278 | ``` 279 | 280 | ```{r gg_rescale_square2} 281 | gg_rescale_square() 282 | ``` 283 | 284 | 285 | #### gg_rescale 286 | 287 | `gg_rescale` adjusts the proportions of the axes of the given plot object to the given ratio. 288 | If no plot is provided, the last plot that was displayed is used. 289 | 290 | ```{r gg_rescale} 291 | ggplot(data = economics, aes(x = date, y = unemploy)) + 292 | geom_line() + 293 | labs(x = "Date", y = "Unemployed Persons (x1000)") + 294 | theme_bdc_grey() 295 | gg_rescale(ratio = 16 / 9) 296 | ``` 297 | 298 | 299 | #### ggsave_golden 300 | 301 | `ggsave_golden` saves the given plot to the given filename. 302 | The dimensions of the resulting image file's canvas will follow the golden ratio, which is useful in conjunction with `gg_rescale_golden`. 303 | If no plot is specified, the most recently displayed plot is used. 304 | 305 | ```{r ggsave_golden,eval=FALSE} 306 | # Save our plot of unemployment from earlier 307 | ggsave_golden(filename = "monthly_unemployment.pdf", plot = pUnemploy) 308 | ``` 309 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ggplot2bdc 2 | ========== 3 | 4 | ggplot2bdc is a collection of themes and other things that can be used 5 | when creating plots with [ggplot2](http://ggplot2.org/). For those using 6 | the [development version of ggplot](https://github.com/hadley/ggplot2), 7 | subtitles and captions are supported. 8 | 9 | - Themes 10 | - `theme_bdc_grey` 11 | - `theme_bdc_paneled` 12 | - `theme_bdc_microtiter` 13 | - `theme_bdc_lattice_population` 14 | - Modifying Plots 15 | - Removing Plot Elements 16 | - `gg_remove_titles`, `gg_remove_title`, `gg_remove_subtitle`, 17 | `gg_remove_caption`, `gg_remove_title.x`, 18 | `gg_remove_title.y` 19 | - `gg_remove_ticks`, `gg_remove_ticks_x`, `gg_remove_ticks_y` 20 | - `gg_remove_grid`, `gg_remove_grid_major`, 21 | `gg_remove_grid_minor`, `gg_remove_grid_x`, 22 | `gg_remove_grid_y` 23 | - `gg_remove_legend`, `gg_remove_legend_title`, 24 | `gg_remove_legend_key`, `gg_remove_legend_text`, 25 | `gg_remove_legend_background` 26 | - `gg_remove_background`, `gg_remove_background_canvas`, 27 | `gg_remove_background_legend`, `gg_remove_background_facet` 28 | - Rescaling 29 | - `gg_rescale` 30 | - `gg_rescale_golden` 31 | - `gg_rescale_square` 32 | - Modifying Files Containing Plots 33 | - `trim_whitespace` 34 | - Misc 35 | - `ggsave_golden` 36 | - `span` 37 | 38 | Installation 39 | ------------ 40 | 41 | `ggplot2bdc` is not on [CRAN](http://cran.r-project.org/), but you can 42 | use 43 | [devtools](http://cran.r-project.org/web/packages/devtools/index.html) 44 | to install the latest and greatest version. To do so: 45 | 46 | if(!require("devtools")) install.packages("devtools") 47 | devtools::install_github("briandconnelly/ggplot2bdc") 48 | 49 | Examples 50 | -------- 51 | 52 | To gain access to the following themes, etc. provided, first load the 53 | `gplot2bdc` package. We'll also load `ggplot`, `dplyr`, and `magrittr` 54 | for these examples. 55 | 56 | library(ggplot2bdc) 57 | library(ggplot2) 58 | library(dplyr) 59 | library(magrittr) 60 | 61 | ### Themes 62 | 63 | #### theme\_bdc\_grey 64 | 65 | `theme_bdc_grey` is a clean theme that uses thin grey panels on a white 66 | background. Legends are placed above. Facet labels are displayed as 67 | black text on a grey background. 68 | 69 | pUnemploy <- ggplot(data = economics, aes(x = date, y = unemploy)) + 70 | geom_line() + 71 | scale_x_date() + 72 | labs(x = "Year", y = "Thousands of Persons", 73 | title = "Monthly Unemployment", subtitle = "Seasonally Adjusted", 74 | caption = "Source: Federal Reserve Bank of St. Louis") + 75 | theme_bdc_grey() 76 | pUnemploy 77 | 78 | ![](figure/theme_bdc_grey-1.png) 79 | 80 | Subtle grid lines can be added to the panels with the `grid.x` and 81 | `grid.y` parameters. These also affect minor grid lines, which can 82 | further be controlled with the `gridmin.x` and `gridmin.y` parameters. 83 | 84 | midwest$inmetro <- factor(midwest$inmetro, levels = c(0, 1), 85 | labels = c("Rural", "Metro")) 86 | 87 | ggplot(data = midwest, 88 | aes(x = inmetro, y = percbelowpoverty, color = state, shape = state)) + 89 | stat_summary(fun.y = "mean", geom = "line", aes(group = state)) + 90 | stat_summary(fun.y = "mean", geom = "point") + 91 | scale_color_hue(name = "State") + 92 | scale_shape_discrete(name = "State") + 93 | labs(x = NULL, y = "Percent", 94 | title = "Poverty in the Midwest", 95 | subtitle = "Poverty rates in rural and metro communities") + 96 | coord_equal(ratio = 0.5) + 97 | theme_bdc_grey(ticks.x = FALSE, grid.y = TRUE) 98 | 99 | ![](figure/theme_bdc_grey_grid-1.png) 100 | 101 | Some people prefer to display categorical data without tick marks along 102 | the axis. These are included by default, but can be removed by setting 103 | either the `ticks.x` or `ticks.y` parameters to `FALSE`. 104 | 105 | We can also use facets to divide the data by state: 106 | 107 | ggplot(data = midwest, aes(x = inmetro, y = percbelowpoverty)) + 108 | facet_grid(. ~ state) + 109 | stat_summary(fun.y = "mean", geom = "line", aes(group = state)) + 110 | stat_summary(fun.y = "mean", geom = "point") + 111 | labs(x = NULL, y = "Percent", 112 | title = "Poverty in the Midwest", 113 | subtitle = "Poverty rates in rural and metro communities") + 114 | coord_equal(ratio = 0.5) + 115 | theme_bdc_grey(grid.y = TRUE) 116 | 117 | ![](figure/theme_bdc_grey-facets1-1.png) 118 | 119 | txcities <- txhousing %>% 120 | filter(city %in% c("Austin", "Dallas", "El Paso", "Fort Worth", "Houston", 121 | "San Antonio")) 122 | 123 | pTX <- ggplot(data = txcities, aes(x = year, y = median / 1000)) + 124 | facet_grid(city ~ .) + 125 | stat_summary(fun.data = "mean_cl_boot", geom = "ribbon", 126 | color = NA, alpha = 0.3) + 127 | stat_summary(fun.y = "mean", geom = "line") + 128 | labs(x = "Year", y = "Thousands of Dollars", 129 | title = "Home Prices are Getting Bigger in Texas", 130 | subtitle = "Median Home Prices in Texas' Largest Cities", 131 | caption = "Source: TAMU Real Estate Center") 132 | 133 | pTX + theme_bdc_grey() 134 | 135 | ![](figure/theme_bdc_grey-facets2-1.png) 136 | 137 | #### theme\_bdc\_paneled 138 | 139 | `theme_bdc_paneled` is a clean theme that displays plots without borders 140 | on grey panels. Legends are placed above. Facet labels are displayed as 141 | plan black text. Subtle grid lines can be added to the panels with the 142 | `grid.x` and `grid.y` parameters, and tick marks can be managed with 143 | `ticks.x` and `ticks.y`. By default, grid lines are used along the Y 144 | axis. This theme is best suited for plots with multiple facets. 145 | 146 | pTX + theme_bdc_paneled() 147 | 148 | ![](figure/theme_bdc_paneled-1.png) 149 | 150 | #### theme\_bdc\_microtiter 151 | 152 | `theme_bdc_microtiter` is a specialized theme for use in creating 153 | figures that represent 96-well microtiter plates. 154 | 155 | pPlate <- ggplot(data = platemap, aes(x = Column, y = Row)) + 156 | geom_point(data = expand.grid(Column = seq(1,12), Row = seq(1,8)), 157 | color = "grey90", fill = "white", shape = 21, size = 8) + 158 | geom_point(aes(shape = Environment, color = Strain), size = 9) + 159 | coord_fixed(ratio = (13/12)/(9/8), xlim = c(0.5, 12.5), ylim = c(0.6, 8.4)) + 160 | scale_y_reverse(breaks = seq(1, 8), labels = LETTERS[1:8]) + 161 | scale_x_continuous(breaks = seq(1, 12), position = "top") + 162 | labs(title = "Plate Layout for My Experiment", subtitle = "25 March 2016") + 163 | guides(shape = guide_legend(override.aes = list(size = 3)), 164 | color = guide_legend(override.aes = list(size = 3))) + 165 | theme_bdc_microtiter() 166 | 167 | pPlate 168 | 169 | ![](figure/theme_bdc_microtiter-1.png) 170 | 171 | For more information, see the [Plotting Microtiter Plate 172 | Maps](http://bconnelly.net/2014/05/plotting-microtiter-plate-maps/). 173 | 174 | #### theme\_bdc\_lattice\_population 175 | 176 | `theme_bdc_lattice_population` is a specialized theme intended to 177 | display populations of individuals structured spatially in a lattice. 178 | 179 | ggplot(data = filter(rockpaperscissors, Time == 10), 180 | aes(x = X, y = Y, color = Type)) + 181 | geom_point(shape=15) + 182 | coord_equal(ratio=1) + 183 | scale_color_hue() + 184 | theme_bdc_lattice_population() 185 | 186 | ![](figure/theme_bdc_lattice_population-1.png) 187 | 188 | We can also show multiple population states: 189 | 190 | ggplot(data = filter(rockpaperscissors, Time %in% c(0, 200, 400, 600)), 191 | aes(x = X, y = Y, color = Type)) + 192 | facet_wrap(~Time, nrow = 1, ncol = 4) + 193 | geom_point(shape = 15) + 194 | coord_equal(ratio = 1) + 195 | scale_color_hue(guide = FALSE) + 196 | labs(title = "Rock, Paper, Scissors", 197 | subtitle = "Wait, is it ON three or AFTER three?", 198 | caption = "Data from simulation on a 50x50 lattice") + 199 | theme_bdc_lattice_population() 200 | 201 | ![](figure/theme_bdc_lattice_population-facets-1.png) 202 | 203 | This is also a great opportunity to create an animation. We can use 204 | [gganimate](https://github.com/dgrtwo/gganimate) to create an animated 205 | GIF showing the population for the first 10 time steps. 206 | 207 | library(gganimate) 208 | 209 | p <- ggplot(data = filter(rockpaperscissors, Time < 10), 210 | aes(x = X, y = Y, color = Type, frame = Time)) + 211 | geom_point(shape = 15, size = 3) + 212 | coord_equal(ratio = 1) + 213 | scale_color_hue(guide = FALSE) + 214 | labs(title = "Rock, Paper, Scissors at t=") + 215 | theme_bdc_lattice_population() 216 | 217 | gg_animate(p = p, saver = "gif", interval = 0.2) 218 | 219 | ![](figure/lattice-anim.gif) 220 | 221 | ### Modifying Plots 222 | 223 | Although you can always change a plot's properties using ggplot2's 224 | `theme` function, it's often difficult to remember which elements 225 | control a plot's visual characteristics. These and other `gg_` functions 226 | make it a bit easier to quickly alter a plot. 227 | 228 | #### gg\_rescale\_golden 229 | 230 | `gg_rescale_golden` adjusts the proportions of the axes of the given 231 | plot object so that follow the golden ratio (horizontally). If no plot 232 | is provided, the last plot that was displayed is used. 233 | 234 | ggplot(mtcars, aes(x = hp, y = mpg)) + 235 | geom_smooth(method = "loess") + 236 | geom_point(shape = 1) + 237 | labs(x = "Horsepower", y = "Fuel Efficiency (mpg)") + 238 | theme_bdc_grey() 239 | 240 | ![](figure/gg_rescale_golden-1.png) 241 | 242 | gg_rescale_golden() 243 | 244 | ![](figure/gg_rescale_golden2-1.png) 245 | 246 | #### gg\_rescale\_square 247 | 248 | `gg_rescale_square` adjusts the proportions of the axes of the given 249 | plot object so that they are equal. If no plot is provided, the last 250 | plot that was displayed is used. 251 | 252 | ggplot(data = economics, aes(x = date, y = unemploy)) + 253 | geom_line() + 254 | labs(x = "Date", y = "Thousands of Unemployed Persons") + 255 | theme_bdc_grey() 256 | 257 | ![](figure/gg_rescale_square-1.png) 258 | 259 | gg_rescale_square() 260 | 261 | ![](figure/gg_rescale_square2-1.png) 262 | 263 | #### gg\_rescale 264 | 265 | `gg_rescale` adjusts the proportions of the axes of the given plot 266 | object to the given ratio. If no plot is provided, the last plot that 267 | was displayed is used. 268 | 269 | ggplot(data = economics, aes(x = date, y = unemploy)) + 270 | geom_line() + 271 | labs(x = "Date", y = "Unemployed Persons (x1000)") + 272 | theme_bdc_grey() 273 | 274 | ![](figure/gg_rescale-1.png) 275 | 276 | gg_rescale(ratio = 16 / 9) 277 | 278 | ![](figure/gg_rescale-2.png) 279 | 280 | #### ggsave\_golden 281 | 282 | `ggsave_golden` saves the given plot to the given filename. The 283 | dimensions of the resulting image file's canvas will follow the golden 284 | ratio, which is useful in conjunction with `gg_rescale_golden`. If no 285 | plot is specified, the most recently displayed plot is used. 286 | 287 | # Save our plot of unemployment from earlier 288 | ggsave_golden(filename = "monthly_unemployment.pdf", plot = pUnemploy) 289 | -------------------------------------------------------------------------------- /data/rockpaperscissors.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/data/rockpaperscissors.rda -------------------------------------------------------------------------------- /figure/gg_rescale-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/gg_rescale-1.png -------------------------------------------------------------------------------- /figure/gg_rescale-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/gg_rescale-2.png -------------------------------------------------------------------------------- /figure/gg_rescale_golden-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/gg_rescale_golden-1.png -------------------------------------------------------------------------------- /figure/gg_rescale_golden2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/gg_rescale_golden2-1.png -------------------------------------------------------------------------------- /figure/gg_rescale_square-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/gg_rescale_square-1.png -------------------------------------------------------------------------------- /figure/gg_rescale_square2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/gg_rescale_square2-1.png -------------------------------------------------------------------------------- /figure/lattice-anim.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/lattice-anim.gif -------------------------------------------------------------------------------- /figure/theme_bdc_grey-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_grey-1.png -------------------------------------------------------------------------------- /figure/theme_bdc_grey-facets1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_grey-facets1-1.png -------------------------------------------------------------------------------- /figure/theme_bdc_grey-facets2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_grey-facets2-1.png -------------------------------------------------------------------------------- /figure/theme_bdc_grey_grid-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_grey_grid-1.png -------------------------------------------------------------------------------- /figure/theme_bdc_lattice_population-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_lattice_population-1.png -------------------------------------------------------------------------------- /figure/theme_bdc_lattice_population-facets-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_lattice_population-facets-1.png -------------------------------------------------------------------------------- /figure/theme_bdc_microtiter-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_microtiter-1.png -------------------------------------------------------------------------------- /figure/theme_bdc_microtiter-switch-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_microtiter-switch-1.png -------------------------------------------------------------------------------- /figure/theme_bdc_paneled-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandconnelly/ggplot2bdc/624e9bfeaf9a32fd18eb04e9a68d4a2438af3e19/figure/theme_bdc_paneled-1.png -------------------------------------------------------------------------------- /ggplot2-bdc.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 4 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageInstallArgs: --no-multiarch --with-keep.source 17 | PackageRoxygenize: rd,namespace 18 | -------------------------------------------------------------------------------- /man/gg_remove_background.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_remove_background.R 3 | \name{gg_remove_background} 4 | \alias{gg_remove_background} 5 | \alias{gg_remove_background_canvas} 6 | \alias{gg_remove_background_facet} 7 | \alias{gg_remove_background_legend} 8 | \alias{gg_remove_background_panel} 9 | \title{Remove a plot's background.} 10 | \usage{ 11 | gg_remove_background(plot = last_plot(), canvas = TRUE, panel = FALSE, 12 | legend = FALSE, facet = FALSE) 13 | 14 | gg_remove_background_canvas(plot = last_plot()) 15 | 16 | gg_remove_background_panel(plot = last_plot()) 17 | 18 | gg_remove_background_legend(plot = last_plot()) 19 | 20 | gg_remove_background_facet(plot = last_plot()) 21 | } 22 | \arguments{ 23 | \item{plot}{A ggplot2 plot object. By default, the last plot displayed is 24 | used.} 25 | 26 | \item{canvas}{Whether or not to remove the background from the entire image (default: \code{TRUE})} 27 | 28 | \item{panel}{Whether or not to remove the background from the panel (i.e., the plotting area; default: \code{FALSE})} 29 | 30 | \item{legend}{Whether or not to remove the legend's background 31 | (default: \code{FALSE})} 32 | 33 | \item{facet}{Whether or not to remove the background from facet labels 34 | (default: \code{FALSE})} 35 | } 36 | \value{ 37 | A modified ggplot2 plot 38 | } 39 | \description{ 40 | \code{gg_remove_background} removes the background from the given plot. This 41 | is useful for creating plots with transparent backgrounds 42 | 43 | \code{gg_remove_background_canvas} Removes TODO 44 | 45 | \code{gg_remove_background_panel} Removes TODO 46 | 47 | \code{gg_remove_background_legend} Removes TODO 48 | 49 | \code{gg_remove_background_facet} Removes TODO 50 | } 51 | \examples{ 52 | p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 53 | geom_point(shape = 1) 54 | gg_remove_background(plot = p) 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /man/gg_remove_grid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_remove_grid.R 3 | \name{gg_remove_grid} 4 | \alias{gg_remove_grid} 5 | \alias{gg_remove_grid_major} 6 | \alias{gg_remove_grid_minor} 7 | \alias{gg_remove_grid_x} 8 | \alias{gg_remove_grid_y} 9 | \title{Remove grid lines from a plot} 10 | \usage{ 11 | gg_remove_grid(plot = last_plot(), major.x = TRUE, major.y = TRUE, 12 | minor.x = TRUE, minor.y = TRUE) 13 | 14 | gg_remove_grid_major(plot = last_plot(), major.x = TRUE, major.y = TRUE) 15 | 16 | gg_remove_grid_minor(plot = last_plot(), minor.x = TRUE, minor.y = TRUE) 17 | 18 | gg_remove_grid_x(plot = last_plot(), major = TRUE, minor = TRUE) 19 | 20 | gg_remove_grid_y(plot = last_plot(), major = TRUE, minor = TRUE) 21 | } 22 | \arguments{ 23 | \item{plot}{A ggplot2 plot object. By default, the last plot displayed is 24 | used.} 25 | 26 | \item{major.x}{Whether or not to remove grid lines at major breakpoints along the X axis (default: \code{TRUE})} 27 | 28 | \item{major.y}{Whether or not to remove grid lines at major breakpoints along the Y axis (default: \code{TRUE})} 29 | 30 | \item{minor.x}{Whether or not to remove grid lines at minor breakpoints along the X axis (default: \code{TRUE})} 31 | 32 | \item{minor.y}{Whether or not to remove grid lines at minor breakpoints along the Y axis (default: \code{TRUE})} 33 | } 34 | \value{ 35 | A modified ggplot2 plot 36 | } 37 | \description{ 38 | \code{gg_remove_grid} removes either the major or minor grid lines on either 39 | axis. 40 | 41 | \code{gg_remove_grid_major} Removes grid lines at major breaks 42 | 43 | \code{gg_remove_grid_minor} Removes grid lines at minor breaks 44 | 45 | \code{gg_remove_grid_x} Removes grid lines at major and minor 46 | breaks on the X axis 47 | 48 | \code{gg_remove_grid_y} Removes grid lines at major and minor 49 | breaks on the X axis 50 | } 51 | \examples{ 52 | p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 53 | geom_point(shape = 1) 54 | gg_remove_grid(plot = p) 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /man/gg_remove_legend.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_remove_legend.R 3 | \name{gg_remove_legend} 4 | \alias{gg_remove_legend} 5 | \alias{gg_remove_legend_background} 6 | \alias{gg_remove_legend_key} 7 | \alias{gg_remove_legend_text} 8 | \alias{gg_remove_legend_title} 9 | \title{Remove a legend or parts of a legend from a plot} 10 | \usage{ 11 | gg_remove_legend(plot = last_plot(), title = TRUE, key = TRUE, 12 | text = TRUE, background = TRUE) 13 | 14 | gg_remove_legend_title(plot = last_plot()) 15 | 16 | gg_remove_legend_key(plot = last_plot()) 17 | 18 | gg_remove_legend_text(plot = last_plot()) 19 | 20 | gg_remove_legend_background(plot = last_plot()) 21 | } 22 | \arguments{ 23 | \item{plot}{A ggplot2 plot object. By default, the last plot displayed is 24 | used.} 25 | 26 | \item{title}{Whether or not to remove the legend's title 27 | (default: \code{TRUE})} 28 | 29 | \item{key}{Whether or not to remove the legend's key 30 | (default: \code{TRUE})} 31 | 32 | \item{text}{Whether or not to remove the legend's key text 33 | (default: \code{TRUE})} 34 | 35 | \item{background}{Whether or not to remove the legend's background 36 | (default: \code{TRUE})} 37 | } 38 | \value{ 39 | A modified ggplot2 plot 40 | } 41 | \description{ 42 | \code{gg_remove_legend} Removes a plot's legend or some of its components 43 | 44 | \code{gg_remove_legend_title} Removes legend's title 45 | 46 | \code{gg_remove_legend_key} Removes legend's key 47 | 48 | \code{gg_remove_legend_text} Removes legend's item labels 49 | 50 | \code{gg_remove_legend_background} Removes legend's background 51 | } 52 | \examples{ 53 | p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 54 | geom_point(shape = 1) 55 | gg_remove_legend(plot = p) 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /man/gg_remove_ticks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_remove_ticks.R 3 | \name{gg_remove_ticks} 4 | \alias{gg_remove_ticks} 5 | \alias{gg_remove_ticks_x} 6 | \alias{gg_remove_ticks_y} 7 | \title{Remove tick marks from a plot's axes} 8 | \usage{ 9 | gg_remove_ticks(plot = last_plot(), x = TRUE, y = TRUE) 10 | 11 | gg_remove_ticks_x(plot = last_plot()) 12 | 13 | gg_remove_ticks_y(plot = last_plot()) 14 | } 15 | \arguments{ 16 | \item{plot}{A ggplot2 plot object. By default, the last plot displayed is 17 | used.} 18 | 19 | \item{x}{Whether or not to remove X-axis ticks (default: \code{TRUE})} 20 | 21 | \item{y}{Whether or not to remove Y-axis ticks (default: \code{TRUE})} 22 | } 23 | \value{ 24 | A modified ggplot2 plot 25 | } 26 | \description{ 27 | \code{gg_remove_ticks} can remove ticks on either the X or Y axes. By 28 | default, all tick marks are removed. 29 | 30 | \code{gg_remove_ticks_x} removes tick marks from the X axis 31 | 32 | \code{gg_remove_ticks_y} removes tick marks from the Y axis 33 | } 34 | \examples{ 35 | p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 36 | geom_point(shape = 1) 37 | gg_remove_ticks(plot = p) 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /man/gg_remove_titles.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_remove_titles.R 3 | \name{gg_remove_titles} 4 | \alias{gg_remove_caption} 5 | \alias{gg_remove_subtitle} 6 | \alias{gg_remove_title} 7 | \alias{gg_remove_title.x} 8 | \alias{gg_remove_title.y} 9 | \alias{gg_remove_titles} 10 | \title{Remove titles from a plot} 11 | \usage{ 12 | gg_remove_titles(plot = last_plot(), title = TRUE, subtitle = TRUE, 13 | caption = TRUE, x = TRUE, y = TRUE) 14 | 15 | gg_remove_title(plot = last_plot()) 16 | 17 | gg_remove_subtitle(plot = last_plot()) 18 | 19 | gg_remove_caption(plot = last_plot()) 20 | 21 | gg_remove_title.x(plot = last_plot()) 22 | 23 | gg_remove_title.y(plot = last_plot()) 24 | } 25 | \arguments{ 26 | \item{plot}{A ggplot2 plot object. By default, the last plot displayed is 27 | used.} 28 | 29 | \item{title}{Whether or not to remove the main title (default: \code{TRUE})} 30 | 31 | \item{subtitle}{Whether or not to remove the subtitle (default: \code{TRUE})} 32 | 33 | \item{caption}{Whether or not to remove the caption (default: \code{TRUE})} 34 | 35 | \item{x}{Whether or not to remove the X axis title (default: \code{TRUE})} 36 | 37 | \item{y}{Whether or not to remove the Y axis title (default: \code{TRUE})} 38 | } 39 | \value{ 40 | A modified ggplot2 plot 41 | } 42 | \description{ 43 | \code{gg_remove_titles} removes title elements such as the main title, 44 | subtitle, caption, or axis titles. By default, all are removed. 45 | 46 | \code{gg_remove_title} Removes the plot's main title 47 | 48 | \code{gg_remove_subtitle} Removes the plot's subtitle 49 | 50 | \code{gg_remove_caption} Removes the plot caption 51 | 52 | \code{gg_remove_title.x} Removes the X-axis title 53 | 54 | \code{gg_remove_title.y} Removes the Y-axis title 55 | } 56 | \examples{ 57 | p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 58 | geom_point(shape = 1) + 59 | labs(title = "Fuel Efficiency by Engine Type", 60 | subtitle = "Larger engines are less efficient", 61 | caption = "Source: Motor Trend", 62 | x = "Number of Cylinders", 63 | y = "Fuel Efficiency (MPG)") 64 | gg_remove_titles(plot = p) 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /man/gg_rescale.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_rescale.R 3 | \name{gg_rescale} 4 | \alias{gg_rescale} 5 | \alias{gg_rescale_golden} 6 | \alias{gg_rescale_square} 7 | \title{Rescale a ggplot2 plot so that axes follow a given ratio} 8 | \usage{ 9 | gg_rescale(plot = last_plot(), ratio) 10 | 11 | gg_rescale_golden(plot = last_plot(), orient = "h") 12 | 13 | gg_rescale_square(plot = last_plot()) 14 | } 15 | \arguments{ 16 | \item{plot}{A ggplot2 plot object. By default, the last plot displayed is 17 | used.} 18 | 19 | \item{ratio}{The aspect ratio to use for the axes. This is independent of 20 | units used in the plot, so the size of the X axis will be ratio times the 21 | total size of the Y axis.} 22 | 23 | \item{orient}{Whether the golden ratio should be horizontal 24 | (\code{h}; default) or vertical (\code{v})} 25 | } 26 | \value{ 27 | A modified ggplot2 plot 28 | } 29 | \description{ 30 | \code{gg_rescale} rescales the given ggplot2 so that the axes follow the 31 | given ratio (horizontally). If a plot is not specified, the last plot 32 | displayed is used. 33 | 34 | \code{gg_rescale_golden} rescales a ggplot2 plot so that axes 35 | follow golden ratio 36 | 37 | \code{gg_rescale_square} rescales a ggplot2 plot so that its 38 | axes are square 39 | } 40 | \examples{ 41 | p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + 42 | geom_point(shape = 1) 43 | gg_rescale(ratio = 1.67) 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /man/gg_supports_theme_attribute.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_supports_theme_attribute.R 3 | \name{gg_supports_theme_attribute} 4 | \alias{gg_supports_theme_attribute} 5 | \title{Determine whether installed ggplot2 supports a given theme attribute} 6 | \usage{ 7 | gg_supports_theme_attribute(x) 8 | } 9 | \arguments{ 10 | \item{x}{The name of an attribute (e.g., "plot.caption")} 11 | } 12 | \value{ 13 | A logical value indicating whether the given attribute is supported 14 | (\code{TRUE}) or not (\code{FALSE}). 15 | } 16 | \description{ 17 | Determine whether installed ggplot2 supports a given theme attribute 18 | } 19 | \examples{ 20 | gg_supports_theme_attribute("plot.caption") 21 | 22 | } 23 | \seealso{ 24 | \code{\link[ggplot2]{theme}} 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/ggplot2bdc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot2bdc.R 3 | \docType{package} 4 | \name{ggplot2bdc} 5 | \alias{ggplot2bdc} 6 | \alias{ggplot2bdc-package} 7 | \title{Themes and functions for creating plots with ggplot2} 8 | \description{ 9 | \code{ggplot2bdc} is a package that contains themes and functions that can 10 | be used when creating plots with \code{\link{ggplot2}}. 11 | } 12 | 13 | -------------------------------------------------------------------------------- /man/ggsave_golden.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggsave_golden.R 3 | \name{ggsave_golden} 4 | \alias{ggsave_golden} 5 | \title{Save a plot with proportions equal to the golden ratio} 6 | \usage{ 7 | ggsave_golden(filename, plot = last_plot(), ...) 8 | } 9 | \arguments{ 10 | \item{filename}{The name of the file to be written to} 11 | 12 | \item{plot}{The plot object to save. Defaults to last plot displayed.} 13 | 14 | \item{...}{Additional parameters to be passed to \code{\link{ggsave}}} 15 | 16 | \item{width}{The width of the resulting image (default: 8)} 17 | 18 | \item{height}{The height of the resulting image (default: 4.94)} 19 | } 20 | \description{ 21 | \code{ggsave_golden} is a wrapper for \code{\link{ggsave}} that saves a 22 | ggplot to a file with proportions equal to the golden ratio (wide). 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/rockpaperscissors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{rockpaperscissors} 5 | \alias{rockpaperscissors} 6 | \title{Data set containing locations of simulated rock-paper-scissors players} 7 | \format{A data frame with TODO rows and TODO variables: 8 | \describe{ 9 | \item{Time}{The simulation timestep} 10 | \item{X}{The X coordinate of the cell on the lattice} 11 | \item{Y}{The Y coordinate of the cell on the lattice} 12 | \item{Type}{The type of player: Rock, Paper, or Scissors} 13 | }} 14 | \source{ 15 | \url{https://github.com/briandconnelly/seeds} 16 | } 17 | \description{ 18 | Simulations were run on a 50x50 lattice. Each player played one strategy. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/span.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/span.R 3 | \name{span} 4 | \alias{span} 5 | \title{Calculate the distance between the minimum and maximum values} 6 | \usage{ 7 | span(n) 8 | } 9 | \description{ 10 | \code{span} calculates the distance between a vector's minimum and maximum 11 | values. Only finite and non-NA values are considered. 12 | } 13 | \examples{ 14 | vals <- sample(1:100, 10) 15 | span(vals) 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/theme_bdc_grey.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/theme_bdc_grey.R 3 | \name{theme_bdc_grey} 4 | \alias{theme_bdc_gray} 5 | \alias{theme_bdc_grey} 6 | \title{Clean theme with grey box and axis ticks} 7 | \usage{ 8 | theme_bdc_grey(base_size = 12, base_family = "", base_grey = "grey70", 9 | grid.x = FALSE, grid.y = FALSE, gridmin.x = grid.x, 10 | gridmin.y = grid.y, ticks.x = TRUE, ticks.y = TRUE, 11 | pmargin = base_size/2) 12 | } 13 | \arguments{ 14 | \item{base_size}{The base size for all text (default: 12)} 15 | 16 | \item{base_family}{The base font family for all text} 17 | 18 | \item{base_grey}{The base color to use for rects, lines, etc (default: "grey70")} 19 | 20 | \item{grid.x}{Show grid lines along the X axis (default: FALSE)} 21 | 22 | \item{grid.y}{Show grid lines along the Y axis (default: FALSE)} 23 | 24 | \item{gridmin.x}{Show minor grid lines along the X axis (default: FALSE)} 25 | 26 | \item{gridmin.y}{Show minor grid lines along the Y axis (default: FALSE)} 27 | 28 | \item{ticks.x}{Show tick marks along the X axis (default: TRUE)} 29 | 30 | \item{ticks.y}{Show tick marks along th Y axis (default: TRUE)} 31 | 32 | \item{pmargin}{Margin around the plot (default: 1/2 line)} 33 | } 34 | \value{ 35 | A list of ggplot theme parameters 36 | } 37 | \description{ 38 | \code{theme_bdc_grey} is a \code{\link{ggplot2}} theme that produces a plot 39 | in a simple grey panel on a white background. Facet labels are displayed as 40 | black text on a grey background. Grid lines can be enabled using 41 | the \code{grid.x} and \code{grid.y} parameters. Tick marks can be disabled 42 | using the \code{ticks.x} and \code{ticks.y} parameters. 43 | } 44 | \examples{ 45 | library(ggplot2) 46 | 47 | p <- ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point() + theme_bdc_grey() 48 | p 49 | 50 | 51 | } 52 | \seealso{ 53 | \code{\link{theme}} 54 | } 55 | 56 | -------------------------------------------------------------------------------- /man/theme_bdc_lattice_population.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/theme_bdc_lattice_population.R 3 | \name{theme_bdc_lattice_population} 4 | \alias{theme_bdc_lattice_population} 5 | \title{Theme for displaying populations structured on a lattice} 6 | \usage{ 7 | theme_bdc_lattice_population(base_size = 12, base_family = "") 8 | } 9 | \arguments{ 10 | \item{base_size}{The base size for all text (default: 10)} 11 | 12 | \item{base_family}{The base font family for all text} 13 | } 14 | \value{ 15 | A list of ggplot theme parameters 16 | } 17 | \description{ 18 | \code{theme_bdc_lattice_population} is a \code{\link{ggplot2}} theme that 19 | produces a plot where many graphical details such as tick marks and axis 20 | labels and text have been removed. This theme is intended to be used to 21 | display simluated populations where individuals are arranged on a lattice. 22 | } 23 | \seealso{ 24 | \code{\link{theme}} 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/theme_bdc_microtiter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/theme_bdc_microtiter.R 3 | \name{theme_bdc_microtiter} 4 | \alias{theme_bdc_microtiter} 5 | \title{Theme for displaying Microtiter plates} 6 | \usage{ 7 | theme_bdc_microtiter(base_size = 12, base_family = "") 8 | } 9 | \arguments{ 10 | \item{base_size}{The base size for all text (default: 14)} 11 | 12 | \item{base_family}{The base font family for all text} 13 | } 14 | \value{ 15 | A list of ggplot theme parameters 16 | } 17 | \description{ 18 | \code{theme_bdc_microtiter} is a \code{\link{ggplot2}} theme that produces a 19 | plot that resembles a 96-well microtiter plate. This is useful for displaying 20 | either data from the plate or information about the plate in a spatial 21 | context. 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/theme_bdc_paneled.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/theme_bdc_paneled.R 3 | \name{theme_bdc_paneled} 4 | \alias{theme_bdc_paneled} 5 | \title{Clean, borderless theme with grey panels and axis ticks} 6 | \usage{ 7 | theme_bdc_paneled(base_size = 12, base_family = "", grid.x = FALSE, 8 | grid.y = TRUE, gridmin.x = FALSE, gridmin.y = FALSE, ticks.x = TRUE, 9 | ticks.y = TRUE, pmargin = base_size/2) 10 | } 11 | \arguments{ 12 | \item{base_size}{The base size for all text (default: 12)} 13 | 14 | \item{base_family}{The base font family for all text} 15 | 16 | \item{grid.x}{Show grid lines along the X axis (default: FALSE)} 17 | 18 | \item{grid.y}{Show grid lines along the Y axis (default: TRUE)} 19 | 20 | \item{gridmin.x}{Show minor grid lines along the X axis (default: FALSE)} 21 | 22 | \item{gridmin.y}{Show minor grid lines along the Y axis (default: FALSE)} 23 | 24 | \item{ticks.x}{Show tick marks along the X axis (default: TRUE)} 25 | 26 | \item{ticks.y}{Show tick marks along th Y axis (default: TRUE)} 27 | 28 | \item{pmargin}{Margin around the plot (default: 1/2 line)} 29 | } 30 | \value{ 31 | A list of ggplot theme parameters 32 | } 33 | \description{ 34 | \code{theme_bdc_paneled} is a \code{\link{ggplot2}} theme that produces a plot 35 | with simple grey panels on a white background. Facet labels are displayed as 36 | black text. Grid lines can be enabled using the \code{grid.x} and 37 | \code{grid.y} parameters. By default, grid lines along the Y axis are shown. 38 | Tick marks can be disabled using the \code{ticks.x} and \code{ticks.y} 39 | parameters. 40 | } 41 | \examples{ 42 | library(ggplot2) 43 | 44 | p <- ggplot(movies, aes(x=year, y=budget)) + geom_point() + theme_bdc_paneled() 45 | p 46 | 47 | } 48 | \seealso{ 49 | \code{\link{theme}} 50 | } 51 | 52 | -------------------------------------------------------------------------------- /man/trim_whitespace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/trim_whitespace.R 3 | \name{trim_whitespace} 4 | \alias{trim_whitespace} 5 | \title{Remove whitespace from around an image} 6 | \usage{ 7 | trim_whitespace(filename, ...) 8 | } 9 | \arguments{ 10 | \item{filename}{Image to be cropped} 11 | 12 | \item{...}{Optional arguments} 13 | } 14 | \description{ 15 | \code{trim_whitespace} crops an image, removing any whitespace from around 16 | it. 17 | } 18 | \note{ 19 | This function requires \href{http://pdfcrop.sourceforge.net}{PDFCrop} 20 | for PDFs and \href{http://www.imagemagick.org/script/index.php}{ImageMagick} 21 | for other formats. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | trim_whitespace("my_figure.pdf") 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(ggplot2bdc) 3 | 4 | test_check("ggplot2bdc") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-span.R: -------------------------------------------------------------------------------- 1 | context("span") 2 | 3 | test_that("span works", { 4 | expect_equal(span(c(0, 0)), 0) 5 | expect_equal(span(c(0, 100)), 100) 6 | expect_equal(span(c(0, -100)), 100) 7 | expect_equal(span(c(40, -20)), 60) 8 | }) 9 | --------------------------------------------------------------------------------