ggblanket R Package

repository·main·Indexed 41 days ago

https://github.com/davidhodge931/ggblanket

An R package providing ggplot2 wrapper functions to create publication-quality visualizations more efficiently. It features single-function plotting via gg_*() wrappers, bare name mapping, inherited aesthetics, and global configuration through set_blanket() for consistent themes, palettes, and aesthetic defaults.

Tokens
667
Snippets
2
Records
3
Agent score
3%

What's inside ggblanket

  1. Configure global settings with set_blanket()

    main

    Use the set_blanket() function to define global defaults for your visualizations. This allows you to maintain a consistent style across multiple plots without repeating arguments.

    With set_blanket(), you can adjust:

    • Global Theme: Set the base theme for all plots.
    • Theme Refinement: Control how themes are refined based on plot scale types.
    • Aesthetic Defaults: Set global values for fill, colour, linewidth, shape, linetype, size, and stroke.
    • Palettes: Define global fill_palette, colour_palette, shape_palette, and linetype_palette.
    • Border Transformations:
      • colour_border: A function to transform colour and colour_palette based on fill and fill_palette.
      • fill_border: A function to transform fill and fill_palette based on colour and colour_palette.
  2. Install ggblanket

    main

    You can install the stable version of ggblanket from CRAN or the development version from GitHub using install.packages() or pak::pak().

    # From CRAN
    install.packages("ggblanket") 
    
    # From GitHub
    pak::pak("davidhodge931/ggblanket")
  3. Use gg_*() wrapper functions for streamlined plotting

    main

    The gg_*() functions (such as gg_point() or gg_area()) act as wrappers for ggplot2 to simplify publication-quality visualization. Key features include:

    • Single-function plotting: Combines the ggplot() call and the geom_* layer into one step.
    • Bare name mapping: Map aesthetic and facet variables using bare names instead of aes().
    • Inherited aesthetics: colour and colour_* arguments are automatically inherited from fill and fill_* arguments.
    • Simplified scales: Change scale arguments easily using prefixed arguments.
    • Smart expansion: If lower x/y scale limits are zero, the package applies a default scale expansion of ggplot2::expansion(c(0, 0.5)).
    • Passthrough arguments: Access all other geom_* specific arguments via ....

    Example usage:

    library(ggblanket)
    library(ggplot2)
    library(dplyr)
    
    set_blanket()
    
    # Scatter plot with gg_point
    iris |> 
      gg_point(
        x = Sepal.Width,
        y = Sepal.Length,
        fill = Species,
        shape = Species
      )
    
    # Area plot with gg_area
    ggplot2::economics_long |> 
      gg_area(
        x = date,
        y = value01,
        facet = variable
      )