### Install ggprism from GitHub Source: https://github.com/csdaw/ggprism/blob/master/README.md Use this command to install the development version of the ggprism package directly from GitHub. Ensure the 'remotes' package is installed. ```r remotes::install_github("csdaw/ggprism") ``` -------------------------------- ### Bracket Axis Guide for Discrete Axes Source: https://context7.com/csdaw/ggprism/llms.txt Illustrates the use of guide_prism_bracket for discrete axes, replacing standard ticks with bracket glyphs around labels. This guide is particularly effective for emphasizing categories on discrete scales. ```r base + scale_x_discrete(guide = "prism_bracket") ``` ```r base + guides(x = "prism_bracket") ``` ```r base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12)) ``` ```r base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12, outside = FALSE)) ``` ```r base + scale_x_discrete(guide = "prism_bracket") + coord_flip() ``` ```r base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12)) + theme(axis.line.x = element_line(colour = "red"), axis.ticks.x = element_line(colour = "blue"), axis.text.x = element_text(colour = "darkgreen")) ``` -------------------------------- ### Offset Axis Guide with Custom Limits and Breaks Source: https://context7.com/csdaw/ggprism/llms.txt Demonstrates using the prism_offset guide for continuous axes with custom limits and breaks. This guide creates an axis line that only appears between the outermost ticks. ```r base + guides(x = "prism_offset", y = "prism_offset") + scale_x_continuous(limits = c(1, 6), breaks = seq(1, 6, by = 1)) ``` ```r base + scale_x_continuous(limits = c(0, 6), guide = "prism_offset") + scale_y_continuous(limits = c(10, 35), guide = "prism_offset") + theme(axis.ticks.length = unit(10, "pt"), axis.ticks = element_line(colour = "red"), axis.line = element_line(colour = "blue")) ``` -------------------------------- ### guide_prism_offset() Source: https://context7.com/csdaw/ggprism/llms.txt Axis guide that draws the axis line only between the outermost tick marks, creating an "offset axis" style from GraphPad Prism. ```APIDOC ## guide_prism_offset() Axis guide that draws the axis line only between the outermost tick marks — a characteristic "offset axis" style from GraphPad Prism. Control the axis extent by adjusting `breaks` in the scale. ### Usage Apply this guide to an axis scale using the `guide` argument in `scale_x_continuous()` or `scale_y_continuous()`, or via `guides()`. ### Parameters - `breaks` (numeric vector, optional) - Defines the locations of the major tick marks, which also define the extent of the axis line. ### Examples ```r library(ggplot2) library(ggprism) base <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme(axis.line = element_line(colour = "black")) # Apply offset guide to both axes base + scale_x_continuous(limits = c(1, 6), breaks = seq(1, 6, by = 1), guide = "prism_offset") + scale_y_continuous(guide = "prism_offset") ``` ``` -------------------------------- ### Create Offset Axis with guide_prism_offset Source: https://context7.com/csdaw/ggprism/llms.txt guide_prism_offset creates an axis guide that draws the axis line only between the outermost tick marks, characteristic of GraphPad Prism's offset axis style. Adjust 'breaks' in the scale to control the axis extent. ```r library(ggplot2) library(ggprism) base <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme(axis.line = element_line(colour = "black")) # Apply offset guide to both axes base + scale_x_continuous( limits = c(1, 6), breaks = seq(1, 6, by = 1), guide = "prism_offset" ) + scale_y_continuous(guide = "prism_offset") ``` -------------------------------- ### Basic ggplot2 setup with ggprism customization Source: https://github.com/csdaw/ggprism/blob/master/README.md This code demonstrates setting up a ggplot object with ToothGrowth data and then applying ggprism themes, color scales, fill scales, and p-value annotations. It requires loading both ggplot2 and ggprism libraries. ```r library(ggplot2) library(ggprism) tg <- ToothGrowth tg$dose <- as.factor(tg$dose) base <- ggplot(tg, aes(x = dose, y = len)) + geom_violin(aes(colour = dose, fill = dose), trim = FALSE) + geom_boxplot(aes(fill = dose), width = 0.2, colour = "black") + scale_y_continuous(limits = c(-5, 40)) p_vals <- tibble::tribble( ~group1, ~group2, ~p.adj, ~y.position, "0.5", "1", 8.80e-14, 35, "0.5", "2", 1.27e-7, 39 ) ``` ```r base base + scale_color_prism("floral") + scale_fill_prism("floral") + guides(y = "prism_offset_minor") + theme_prism(base_size = 16) + theme(legend.position = "none") + add_pvalue(p_vals, label = "p = {p.adj}", tip.length = 0, label.size = 4) ``` -------------------------------- ### Install ggprism from CRAN Source: https://github.com/csdaw/ggprism/blob/master/README.md Use this command to install the latest stable version of the ggprism package from the Comprehensive R Archive Network (CRAN). ```r install.packages("ggprism") ``` -------------------------------- ### guide_prism_minor() Source: https://context7.com/csdaw/ggprism/llms.txt Axis guide that adds minor tick marks between major ticks, mimicking GraphPad Prism's style. Minor tick length is controlled by `prism.ticks.length` theme element. ```APIDOC ## guide_prism_minor() Axis guide that adds minor tick marks between the standard major ticks, mirroring the minor-tick style common in GraphPad Prism. Minor tick length is controlled via the custom `prism.ticks.length` theme element. ### Usage Apply this guide to an axis scale using the `guide` argument in `scale_x_continuous()` or `scale_y_continuous()`, or via `guides()`. ### Parameters - `minor_breaks` (numeric vector, optional) - Specifies the locations of the minor tick marks. ### Examples ```r library(ggplot2) library(ggprism) base <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() # Add minor ticks to both axes base + scale_x_continuous(guide = "prism_minor") + scale_y_continuous(guide = "prism_minor") # Control number of minor ticks via minor_breaks base + scale_x_continuous(minor_breaks = seq(0, 6, 0.5), guide = "prism_minor") + scale_y_continuous(minor_breaks = seq(10, 35, 1.25), guide = "prism_minor") # Log10 axis with minor ticks ggplot(msleep, aes(bodywt, brainwt)) + geom_point(na.rm = TRUE) + scale_x_log10(minor_breaks = rep(1:9, 4) * (10^rep(0:3, each = 9)), guide = "prism_minor") ``` ``` -------------------------------- ### Add Minor Ticks with guide_prism_minor Source: https://context7.com/csdaw/ggprism/llms.txt Use guide_prism_minor for an axis guide that adds minor tick marks between major ticks, mimicking GraphPad Prism's style. Minor tick length is controlled by the 'prism.ticks.length' theme element. Minor breaks can be specified. ```r library(ggplot2) library(ggprism) base <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() # Add minor ticks to both axes base + scale_x_continuous(limits = c(0, 6), guide = "prism_minor") + scale_y_continuous(limits = c(10, 35), guide = "prism_minor") # Use guides() shorthand base + guides(x = "prism_minor", y = "prism_minor") # Control number of minor ticks via minor_breaks base + scale_x_continuous( limits = c(0, 6), minor_breaks = seq(0, 6, 0.5), guide = "prism_minor" ) + scale_y_continuous( limits = c(10, 35), minor_breaks = seq(10, 35, 1.25), guide = "prism_minor" ) + theme( axis.ticks.length = unit(10, "pt"), # major tick length prism.ticks.length = unit(5, "pt") # minor tick length ) # Log10 axis with minor ticks at each mantissa ggplot(msleep, aes(bodywt, brainwt)) + geom_point(na.rm = TRUE) + scale_x_log10( limits = c(1e0, 1e4), minor_breaks = rep(1:9, 4) * (10^rep(0:3, each = 9)), guide = "prism_minor" ) ``` -------------------------------- ### prism_fill_pal() Source: https://context7.com/csdaw/ggprism/llms.txt Low-level function to get a fill colour-generating function for a named Prism palette. Returns a function that produces hex fill colours. ```APIDOC ## prism_fill_pal() Low-level fill palette function — the fill counterpart to `prism_colour_pal()`. Returns a function that produces hex fill colours. ### Parameters - `palette` (character) - The name of the fill palette. See `ggprism_data$fill_palettes` for available options. - `alpha` (numeric, optional) - Alpha transparency for the colours. ### Returns A function that takes an integer `n` and returns `n` fill colours from the specified palette. ### Examples ```r library(ggprism) # Retrieve 3 fill colours from "flames" prism_fill_pal(palette = "flames")(3) # Inspect maximum capacity pal <- prism_fill_pal("ocean") attr(pal, "max_n") ``` ``` -------------------------------- ### prism_colour_pal() / prism_color_pal() Source: https://context7.com/csdaw/ggprism/llms.txt Low-level function to get a colour-generating function for a named Prism palette. Useful for retrieving raw hex colour codes. ```APIDOC ## prism_colour_pal() / prism_color_pal() Low-level palette function that returns a colour-generating function for a named Prism palette. Useful when you need the raw hex colour codes outside of a scale context. ### Parameters - `palette` (character) - The name of the colour palette. See `ggprism_data$colour_palettes` for available options. - `alpha` (numeric, optional) - Alpha transparency for the colours. ### Returns A function that takes an integer `n` and returns `n` colours from the specified palette. ### Examples ```r library(ggprism) library(scales) # Get the first 4 colours from the "starry" palette prism_colour_pal(palette = "starry")(4) # Show all colours in a palette visually show_palette <- function(palette) { pal_fn <- prism_colour_pal(palette = palette) n_max <- attr(pal_fn, "max_n") scales::show_col(pal_fn(n_max)) } show_palette("pearl") ``` ``` -------------------------------- ### prism_shape_pal() Source: https://context7.com/csdaw/ggprism/llms.txt Low-level function to get a shape palette function. Returns a function that produces R `pch` integer codes for Prism-style point symbols. ```APIDOC ## prism_shape_pal() Low-level shape palette function. Returns a function that produces R `pch` integer codes corresponding to Prism-style point symbols. ### Parameters - `palette` (character) - The name of the shape palette. Options: `"default"`, `"filled"`, `"complete"`. ### Returns A function that takes an integer `n` and returns `n` `pch` codes from the specified palette. ### Examples ```r library(ggprism) library(ggplot2) # Retrieve 3 pch codes from the "filled" palette prism_shape_pal(palette = "filled")(3) # Use directly in geom_point ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point(shape = prism_shape_pal("default")(1), size = 4) ``` ``` -------------------------------- ### Get Prism Fill Palettes Source: https://context7.com/csdaw/ggprism/llms.txt prism_fill_pal is the fill counterpart to prism_colour_pal, returning a function that produces hex fill colors. The 'max_n' attribute indicates the maximum number of colors available in the palette. ```r library(ggprism) # All fill palettes and their sizes lengths(ggprism_data$fill_palettes) # Retrieve 3 fill colours from "flames" prism_fill_pal(palette = "flames")(3) #> [1] "#B61F26" "#E36B23" "#F9A03F" # Inspect maximum capacity pal <- prism_fill_pal("ocean") attr(pal, "max_n") ``` -------------------------------- ### Get Prism Shape Palettes Source: https://context7.com/csdaw/ggprism/llms.txt prism_shape_pal returns a function that produces R pch integer codes for Prism-style point symbols. The 'max_n' attribute indicates the maximum number of shapes available in the palette. ```r library(ggprism) # Retrieve 3 pch codes from the "filled" palette prism_shape_pal(palette = "filled")(3) #> [1] 19 15 17 # Maximum number of shapes pal <- prism_shape_pal("complete") attr(pal, "max_n") # 14 # Use directly in geom_point library(ggplot2) ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point(shape = prism_shape_pal("default")(1), size = 4) ``` -------------------------------- ### Get Prism Color Palettes Source: https://context7.com/csdaw/ggprism/llms.txt prism_colour_pal returns a color-generating function for a named Prism palette. Useful for obtaining raw hex color codes outside of a scale context. The 'max_n' attribute indicates the palette's capacity. ```r library(ggprism) library(scales) # List all palettes with their sizes lengths(ggprism_data$colour_palettes) # Get the first 4 colours from the "starry" palette prism_colour_pal(palette = "starry")(4) #> [1] "#2D2B55" "#5C5CA0" "#9DA7D5" "#C4C9E8" # Show all colours in a palette visually show_palette <- function(palette) { pal_fn <- prism_colour_pal(palette = palette) n_max <- attr(pal_fn, "max_n") scales::show_col(pal_fn(n_max)) } show_palette("pearl") show_palette("candy_bright") # Use max_n attribute to know the palette's capacity pal <- prism_colour_pal("floral") attr(pal, "max_n") # e.g. 9 ``` -------------------------------- ### scale_fill_prism() Source: https://context7.com/csdaw/ggprism/llms.txt Discrete fill scale using GraphPad Prism palettes. Direct counterpart to `scale_colour_prism()` for `fill` aesthetics. ```APIDOC ## scale_fill_prism() ### Description Discrete fill scale using GraphPad Prism palettes. Direct counterpart to `scale_colour_prism()` for `fill` aesthetics. ### Usage ```r library(ggplot2) library(ggprism) # List all available fill palettes lengths(ggprism_data$fill_palettes) tg <- ToothGrowth tg$dose <- as.factor(tg$dose) ggplot(tg, aes(x = dose, y = len, fill = dose)) + geom_boxplot() + scale_fill_prism(palette = "colorblind_safe") + theme_prism() # Use "warm_and_sunny" palette with custom legend ggplot(mpg, aes(x = class, y = hwy, fill = class)) + geom_violin() + scale_fill_prism( palette = "warm_and_sunny", name = "Car class", labels = function(x) tools::toTitleCase(x) ) + theme_prism(axis_text_angle = 45) ``` ``` -------------------------------- ### preview_theme() Source: https://context7.com/csdaw/ggprism/llms.txt Quickly preview any named ggprism theme palette as a boxplot using a generated colour-spread dataset — useful for choosing a palette before applying it. ```APIDOC ## preview_theme() ### Description Quickly preview any named ggprism theme palette as a boxplot using a generated colour-spread dataset — useful for choosing a palette before applying it. ### Usage ```r library(ggplot2) library(ggprism) # See all available theme names names(ggprism_data$themes) #> [1] "all_null" "black_and_white" "blueprint" "candy_bright" #> [5] "candy_soft" "colorblind_safe" "earth_tones" "floral" ... # Preview a specific theme — returns a ggplot object preview_theme("floral") preview_theme("candy_bright") preview_theme("office") ``` ``` -------------------------------- ### Apply GraphPad Prism Theme Source: https://context7.com/csdaw/ggprism/llms.txt Use theme_prism() to apply a GraphPad Prism-style theme. It supports various palettes and customization options like font, size, and borders. Ensure coord_cartesian(clip = "off") is used when border = TRUE. ```r library(ggplot2) library(ggprism) # List all available theme palettes names(ggprism_data$themes) # Basic usage: default "black_and_white" palette ggplot(mpg, aes(x = displ, y = cty, colour = class)) + geom_point() + theme_prism() # Use a different theme palette and match the colour scale ggplot(mpg, aes(x = displ, y = cty, colour = class)) + geom_point() + theme_prism(palette = "stained_glass") + scale_color_prism(palette = "stained_glass") # Rotate x-axis text, change font, and add a border ggplot(mpg, aes(x = class, y = hwy, fill = class)) + geom_boxplot() + theme_prism( palette = "floral", base_size = 16, base_family = "serif", base_fontface = "plain", axis_text_angle = 45, border = TRUE ) + scale_fill_prism(palette = "floral") + coord_cartesian(clip = "off") # required when border = TRUE # Change border thickness separately from base_size ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme_prism(border = TRUE, base_size = 14, base_rect_size = 2) + coord_cartesian(clip = "off") ``` -------------------------------- ### scale_colour_prism() / scale_color_prism() Source: https://context7.com/csdaw/ggprism/llms.txt Discrete colour scale using one of GraphPad Prism's named colour palettes. Works identically to `scale_colour_manual()` but pulls from the built-in ggprism palette library. ```APIDOC ## scale_colour_prism() / scale_color_prism() ### Description Discrete colour scale using one of GraphPad Prism's named colour palettes. Works identically to `scale_colour_manual()` but pulls from the built-in ggprism palette library. ### Usage ```r library(ggplot2) library(ggprism) # List all palettes and their maximum number of colours lengths(ggprism_data$colour_palettes) base <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl))) + geom_point(size = 3) # Apply a palette base + scale_colour_prism(palette = "candy_bright") # With custom legend title and labels base + scale_colour_prism( palette = "candy_bright", name = "Cylinders", labels = c("4 cyl", "6 cyl", "8 cyl") ) # Change legend label order base + scale_colour_prism( palette = "candy_bright", name = "Cylinders", breaks = c(8, 4, 6) ) # Combine colour and fill scales ggplot(mpg, aes(x = class, y = hwy, fill = class, colour = class)) + geom_boxplot() + scale_fill_prism(palette = "floral") + scale_colour_prism(palette = "floral") ``` ``` -------------------------------- ### Offset Axis with Minor Ticks (guide_prism_offset_minor) Source: https://context7.com/csdaw/ggprism/llms.txt Applies the guide_prism_offset_minor to continuous axes, combining offset axis lines with minor tick marks. This is useful for detailed axis representation on continuous scales. ```r base + scale_x_continuous(limits = c(0, 6), minor_breaks = seq(0, 6, 0.5), guide = "prism_offset_minor") + scale_y_continuous(limits = c(10, 35), minor_breaks = seq(10, 35, 1.25), guide = "prism_offset_minor") + theme(axis.ticks.length = unit(10, "pt"), prism.ticks.length = unit(5, "pt")) ``` ```r ggplot(msleep, aes(bodywt, brainwt)) + geom_point(na.rm = TRUE) + scale_x_log10(limits = c(1e0, 1e4), minor_breaks = rep(1:9, 4) * (10^rep(0:3, each = 9)), guide = "prism_offset_minor") + theme(axis.line = element_line(colour = "black")) ``` -------------------------------- ### theme_prism() Source: https://context7.com/csdaw/ggprism/llms.txt Apply a GraphPad Prism-style ggplot2 theme with bold fonts, no gridlines, clean axes, and optional coloured backgrounds drawn from named Prism colour schemes. ```APIDOC ## theme_prism() ### Description Apply a GraphPad Prism-style ggplot2 theme with bold fonts, no gridlines, clean axes, and optional coloured backgrounds drawn from named Prism colour schemes. ### Usage ```r library(ggplot2) library(ggprism) # List all available theme palettes names(ggprism_data$themes) # Basic usage: default "black_and_white" palette ggplot(mpg, aes(x = displ, y = cty, colour = class)) + geom_point() + theme_prism() # Use a different theme palette and match the colour scale ggplot(mpg, aes(x = displ, y = cty, colour = class)) + geom_point() + theme_prism(palette = "stained_glass") + scale_color_prism(palette = "stained_glass") # Rotate x-axis text, change font, and add a border ggplot(mpg, aes(x = class, y = hwy, fill = class)) + geom_boxplot() + theme_prism( palette = "floral", base_size = 16, base_family = "serif", base_fontface = "plain", axis_text_angle = 45, border = TRUE ) + scale_fill_prism(palette = "floral") + coord_cartesian(clip = "off") # required when border = TRUE # Change border thickness separately from base_size ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme_prism(border = TRUE, base_size = 14, base_rect_size = 2) + coord_cartesian(clip = "off") ``` ``` -------------------------------- ### Preview ggprism Theme Palettes Source: https://context7.com/csdaw/ggprism/llms.txt Use preview_theme() to quickly visualize any named ggprism theme palette. This function generates a boxplot using a sample dataset, aiding in palette selection before application. ```r library(ggplot2) library(ggprism) # See all available theme names names(ggprism_data$themes) #> [1] "all_null" "black_and_white" "blueprint" "candy_bright" #> [5] "candy_soft" "colorblind_safe" "earth_tones" "floral" ... # Preview a specific theme — returns a ggplot object preview_theme("floral") preview_theme("candy_bright") preview_theme("office") ``` -------------------------------- ### Apply Prism Discrete Colour Scale Source: https://context7.com/csdaw/ggprism/llms.txt Use scale_colour_prism() or scale_color_prism() for discrete colour scales with GraphPad Prism palettes. It functions like scale_colour_manual() but uses built-in ggprism palettes. Custom legend titles, labels, and order are supported. ```r library(ggplot2) library(ggprism) # List all palettes and their maximum number of colours lengths(ggprism_data$colour_palettes) base <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl))) + geom_point(size = 3) # Apply a palette base + scale_colour_prism(palette = "candy_bright") # With custom legend title and labels base + scale_colour_prism( palette = "candy_bright", name = "Cylinders", labels = c("4 cyl", "6 cyl", "8 cyl") ) # Change legend label order base + scale_colour_prism( palette = "candy_bright", name = "Cylinders", breaks = c(8, 4, 6) ) # Combine colour and fill scales ggplot(mpg, aes(x = class, y = hwy, fill = class, colour = class)) + geom_boxplot() + scale_fill_prism(palette = "floral") + scale_colour_prism(palette = "floral") ``` -------------------------------- ### Apply Prism Discrete Fill Scale Source: https://context7.com/csdaw/ggprism/llms.txt Use scale_fill_prism() for discrete fill scales, mirroring scale_colour_prism() for the fill aesthetic. It allows selection from GraphPad Prism palettes and customization of legend titles and labels. ```r library(ggplot2) library(ggprism) # List all available fill palettes lengths(ggprism_data$fill_palettes) tg <- ToothGrowth tg$dose <- as.factor(tg$dose) ggplot(tg, aes(x = dose, y = len, fill = dose)) + geom_boxplot() + scale_fill_prism(palette = "colorblind_safe") + theme_prism() # Use "warm_and_sunny" palette with custom legend ggplot(mpg, aes(x = class, y = hwy, fill = class)) + geom_violin() + scale_fill_prism( palette = "warm_and_sunny", name = "Car class", labels = function(x) tools::toTitleCase(x) ) + theme_prism(axis_text_angle = 45) ``` -------------------------------- ### Scale Shapes with Prism Palettes Source: https://context7.com/csdaw/ggprism/llms.txt Use scale_shape_prism to map factor levels to GraphPad Prism-style point symbols. Offers 'default', 'filled', and 'complete' palettes. Custom legend titles and labels can be applied. ```r library(ggplot2) library(ggprism) # Inspect available shape palettes ggprism_data$shape_palettes base <- ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(cyl))) + geom_point(size = 4) # Default palette (9 shapes, no fill) base + scale_shape_prism(palette = "default") # Filled palette (first 5 shapes have fill) base + scale_shape_prism(palette = "filled") # Complete palette (14 shapes) base + scale_shape_prism(palette = "complete") # Custom legend title and labels base + scale_shape_prism( palette = "filled", name = "Cylinders", labels = c("4-cyl", "6-cyl", "8-cyl") ) # Visualise all shapes in a palette show_shapes <- function(palette) { df <- ggprism_data$shape_palettes[[palette]][, -1] df$pch_f <- factor(df$pch, levels = df$pch) ggplot(df, aes(x = 0, y = 0, shape = pch)) + geom_point(aes(shape = pch), size = 5, fill = "red") + scale_shape_identity() + facet_wrap (~ pch_f) + theme_void() } show_shapes("complete") ``` -------------------------------- ### Annotation Ticks for Mirrored and Minor Ticks Source: https://context7.com/csdaw/ggprism/llms.txt Shows how to use annotation_ticks to add tick marks as an annotation layer, useful for mirrored ticks on bordered plots or minor ticks on secondary axes. Customization of tick appearance is also demonstrated. ```r ggplot(mtcars, aes(x = mpg, y = disp)) + geom_point() + theme_prism(border = TRUE) + coord_cartesian(clip = "off") + annotation_ticks(sides = "tr", type = "major", outside = TRUE) + theme(plot.margin = unit(c(4, 4, 4, 4), "mm")) ``` ```r ggplot(mtcars, aes(x = mpg, y = disp)) + geom_point() + scale_x_continuous(guide = "prism_minor") + scale_y_continuous(guide = "prism_minor") + theme_prism(border = TRUE) + coord_cartesian(clip = "off") + annotation_ticks(sides = "tr", type = "both", outside = TRUE) + theme(plot.margin = unit(c(4, 4, 4, 4), "mm")) ``` ```r ggplot(sample_data, aes(x = day)) + geom_line(aes(y = temperature), colour = "magenta") + geom_line(aes(y = price / 10), colour = "blue") + scale_y_continuous(sec.axis = sec_axis(~. * 10, name = "price"), guide = "prism_minor") + theme_prism(border = TRUE) + coord_cartesian(clip = "off") + annotation_ticks(sides = "r", type = "minor", outside = TRUE) ``` ```r ggplot(mtcars, aes(x = mpg, y = disp)) + geom_point() + theme_prism(border = TRUE) + coord_cartesian(clip = "off") + annotation_ticks(sides = "tr", type = "major", outside = TRUE, tick.length = unit(10, "pt"), colour = "red", linewidth = 2, linetype = "dashed") ``` -------------------------------- ### scale_shape_prism() Source: https://context7.com/csdaw/ggprism/llms.txt Applies GraphPad Prism-style point symbols to shapes in ggplot2 plots. Supports different palettes and custom legend options. ```APIDOC ## scale_shape_prism() Discrete shape scale that maps factor levels to GraphPad Prism-style point symbols. Offers three palettes: `"default"` (9 unfilled symbols), `"filled"` (10 symbols, first 5 filled), and `"complete"` (14 symbols). ### Parameters - `palette` (character) - The name of the shape palette to use. Options: `"default"`, `"filled"`, `"complete"`. - `name` (character, optional) - The title for the legend. - `labels` (character vector, optional) - Custom labels for the legend. ### Examples ```r library(ggplot2) library(ggprism) base <- ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(cyl))) + geom_point(size = 4) # Default palette base + scale_shape_prism(palette = "default") # Filled palette base + scale_shape_prism(palette = "filled") # Complete palette base + scale_shape_prism(palette = "complete") # Custom legend title and labels base + scale_shape_prism(palette = "filled", name = "Cylinders", labels = c("4-cyl", "6-cyl", "8-cyl")) ``` ``` -------------------------------- ### geom_bracket() Source: https://context7.com/csdaw/ggprism/llms.txt Low-level geom that draws a square bracket from (x, y) to (xend, yend). Used internally by add_pvalue() but can be used directly for custom bracket annotations. ```APIDOC ## geom_bracket() Low-level geom that draws a square bracket from `(x, y)` to `(xend, yend)`. Used internally by `add_pvalue()` but can be used directly for custom bracket annotations. ### Minimal bracket ```r library(ggplot2) library(ggprism) ggplot( data.frame(x = 1, xend = 4, y = 1, yend = 1), aes(x = x, xend = xend, y = y, yend = yend) ) + geom_bracket() ``` ### Custom tip length and direction ```r ggplot( data.frame(x = 1, xend = 3, y = 5, yend = 5), aes(x = x, xend = xend, y = y, yend = yend) ) + geom_bracket( tip.length = c(0.2, 0.05), direction = "up", colour = "steelblue", linewidth = 1 ) ``` ``` -------------------------------- ### Draw custom brackets with geom_bracket() Source: https://context7.com/csdaw/ggprism/llms.txt Use geom_bracket() for direct control over drawing square brackets between specified coordinates. Customize tip lengths, direction, color, and line width. This is a lower-level function used internally by add_pvalue(). ```r library(ggplot2) library(ggprism) # Minimal bracket ggplot( data.frame(x = 1, xend = 4, y = 1, yend = 1), aes(x = x, xend = xend, y = y, yend = yend) ) + geom_bracket() ``` ```r # Custom tip length and direction ggplot( data.frame(x = 1, xend = 3, y = 5, yend = 5), aes(x = x, xend = xend, y = y, yend = yend) ) + geom_bracket( tip.length = c(0.2, 0.05), direction = "up", colour = "steelblue", linewidth = 1 ) ``` -------------------------------- ### ggprism_data Source: https://context7.com/csdaw/ggprism/llms.txt Built-in list object providing the raw colour hex codes, fill hex codes, shape pch integers, and theme element colours used across all ggprism functions. ```APIDOC ## ggprism_data Built-in list object providing the raw colour hex codes, fill hex codes, shape `pch` integers, and theme element colours used across all ggprism functions. ### Explore the structure ```r library(ggprism) # Explore the structure str(ggprism_data, max.level = 1) #> List of 4 #> $ themes :List of N (named theme element colour tibbles) #> $ colour_palettes :List of N (named character vectors of hex codes) #> $ fill_palettes :List of N (named character vectors of hex codes) #> $ shape_palettes :List of 3 (data frames with pch codes) ``` ### List all theme names ```r names(ggprism_data$themes) ``` ### List all colour palettes and their sizes ```r lengths(ggprism_data$colour_palettes) ``` ### Get hex codes for the "ocean" colour palette ```r ggprism_data$colour_palettes[["ocean"]] ``` ### Get the default shape palette as a data frame ```r ggprism_data$shape_palettes[["default"]] ``` ### Access raw theme colours for "flames" ```r ggprism_data$themes[["flames"]] ``` ``` -------------------------------- ### add_pvalue() Source: https://context7.com/csdaw/ggprism/llms.txt Adds p-value brackets (or text-only labels) to a ggplot from a data frame of statistical results. Supports glue-style label expressions, grouped/faceted plots, dodged data, customisable bracket aesthetics, and plotmath expressions. ```APIDOC ## add_pvalue() Adds p-value brackets (or text-only labels) to a ggplot from a data frame of statistical results. Supports glue-style label expressions, grouped/faceted plots, dodged data, customisable bracket aesthetics, and plotmath expressions. ### Basic bracket comparing two groups ```r library(ggplot2) library(ggprism) tg <- ToothGrowth tg$dose <- as.factor(tg$dose) two_means <- tibble::tribble( ~group1, ~group2, ~p, ~y.position, "OJ", "VC", 0.0606, 36 ) ggplot(tg, aes(x = supp, y = len)) + geom_boxplot() + add_pvalue(two_means) ``` ### Glue expression label with plotmath parsing ```r ggplot(tg, aes(x = supp, y = len)) + geom_boxplot() + add_pvalue(two_means, label = "p = {p}", parse = TRUE) ``` ### Custom bracket and label aesthetics ```r ggplot(tg, aes(x = supp, y = len)) + geom_boxplot() + add_pvalue( two_means, label = "p = {p}", parse = TRUE, colour = "red", label.size = 5, fontface = "bold", bracket.colour = "blue", bracket.size = 1.2, tip.length = c(0.1, 0), # asymmetric tips linetype = "dashed" ) ``` ### Pairwise comparisons with bracket shortening ```r pairwise <- tibble::tribble( ~group1, ~group2, ~p.signif, ~y.position, "0.5", "1", "****", 38, "0.5", "2", "****", 36, "1", "2", "****", 38 ) ggplot(tg, aes(x = dose, y = len)) + geom_boxplot(aes(fill = dose)) + add_pvalue(pairwise, bracket.shorten = c(0.05, 0, 0.05)) + scale_fill_prism(palette = "floral") + theme_prism() ``` ### Grouped data: step spacing between brackets ```r pairwise_grouped <- tibble::tribble( ~group1, ~group2, ~p.adj, ~y.position, ~supp, "0.5", "1", 2.63e-4, 33.5, "OJ", "0.5", "2", 3.96e-6, 37.6, "OJ", "1", "2", 1.18e-1, 41.6, "OJ", "0.5", "1", 2.04e-6, 36.5, "VC", "0.5", "2", 1.40e-7, 40.6, "VC", "1", "2", 2.75e-4, 44.6, "VC" ) ggplot(tg, aes(x = dose, y = len)) + geom_boxplot(aes(fill = supp)) + add_pvalue( pairwise_grouped, colour = "supp", tip.length = 0, step.group.by = "supp", step.increase = 0.03 ) ``` ### Faceted plot: one bracket per facet ```r facet_stats <- tibble::tribble( ~group1, ~group2, ~p.adj, ~y.position, ~dose, "OJ", "VC", 0.0127, 24, "0.5", "OJ", "VC", 0.00312, 30, "1", "OJ", "VC", 0.964, 36.5, "2" ) ggplot(tg, aes(x = supp, y = len)) + geom_boxplot() + facet_wrap(~ dose, scales = "free") + add_pvalue(facet_stats) # data frame must contain the faceting column ``` ### Text-only label (no bracket) ```r ggplot(tg, aes(x = supp, y = len)) + geom_boxplot() + add_pvalue(two_means, remove.bracket = TRUE, x = 1.5) ``` ### Non-default column names ```r custom_cols <- tibble::tribble( ~left, ~right, ~significance, ~height, "OJ", "VC", "ns", 36 ) ggplot(tg, aes(x = supp, y = len)) + geom_boxplot() + add_pvalue( custom_cols, xmin = "left", xmax = "right", label = "significance", y.position = "height" ) ``` ``` -------------------------------- ### Access ggprism built-in data Source: https://context7.com/csdaw/ggprism/llms.txt ggprism_data is a list containing raw color hex codes, fill hex codes, shape pch integers, and theme element colors used in ggprism. Explore its structure and access specific palettes or theme colors. ```r library(ggprism) # Explore the structure str(ggprism_data, max.level = 1) #> List of 4 #> $ themes :List of N (named theme element colour tibbles) #> $ colour_palettes :List of N (named character vectors of hex codes) #> $ fill_palettes :List of N (named character vectors of hex codes) #> $ shape_palettes :List of 3 (data frames with pch codes) ``` ```r # List all theme names names(ggprism_data$themes) ``` ```r # List all colour palettes and their sizes lengths(ggprism_data$colour_palettes) ``` ```r # Get hex codes for the "ocean" colour palette ggprism_data$colour_palettes[["ocean"]] ``` ```r # Get the default shape palette as a data frame ggprism_data$shape_palettes[["default"]] ``` ```r # Access raw theme colours for "flames" ggprism_data$themes[["flames"]] ```