| Title: | Consistent Fonts and Figure Export for Scientific Publication Workflows |
|---|---|
| Description: | Provides a unified interface for exporting figures created with base graphics, 'ggplot2', 'grid', 'pheatmap', and 'ComplexHeatmap' to PDF, PNG, JPEG, and TIFF files. Selects an appropriate rendering strategy based on the plot object and supports exporting a figure to multiple formats in one call. Also provides font configuration and diagnostics, reusable figure presets, publication-oriented themes, and colour palettes. The 'ggplot2' graphics framework is described by Wickham (2016, ISBN:978-3-319-24277-4). |
| Authors: | Tim Holy [aut, cre] |
| Maintainer: | Tim Holy <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.8 |
| Built: | 2026-09-23 12:01:13 UTC |
| Source: | https://github.com/scienceadvances/canton |
Apply a palette returned by hue() to discrete or continuous ggplot2
colour and fill scales.
scale_colour_canton_d(palette = "NPG", ...) scale_color_canton_d(palette = "NPG", ...) scale_fill_canton_d(palette = "NPG", ...) scale_colour_canton_c(palette = "NPG", ...) scale_color_canton_c(palette = "NPG", ...) scale_fill_canton_c(palette = "NPG", ...)scale_colour_canton_d(palette = "NPG", ...) scale_color_canton_d(palette = "NPG", ...) scale_fill_canton_d(palette = "NPG", ...) scale_colour_canton_c(palette = "NPG", ...) scale_color_canton_c(palette = "NPG", ...) scale_fill_canton_c(palette = "NPG", ...)
palette |
Canton palette name. |
... |
Additional arguments passed to the corresponding ggplot2 scale. |
A ggplot2 scale object.
Create reusable dimensions and output settings for imagesave(). Presets
are starting points rather than journal-specific guarantees; always compare
them with the current author instructions for the target journal.
figure_preset( name = c("publication", "single_column", "double_column", "high_resolution", "presentation"), format = NULL, width = NULL, height = NULL, units = NULL, dpi = NULL, bg = NULL, quality = NULL, compression = NULL, pointsize = NULL )figure_preset( name = c("publication", "single_column", "double_column", "high_resolution", "presentation"), format = NULL, width = NULL, height = NULL, units = NULL, dpi = NULL, bg = NULL, quality = NULL, compression = NULL, pointsize = NULL )
name |
Built-in preset name: |
format, width, height, units, dpi, bg, quality, compression, pointsize
|
Optional values that override the built-in preset. |
An object of class canton_figure_preset.
figure_preset("single_column") figure_preset("publication", format = c("pdf", "png"), dpi = 600)figure_preset("single_column") figure_preset("publication", format = c("pdf", "png"), dpi = 600)
Check whether a plotting font is available
fontcheck(family = "Arial", error = FALSE, quiet = FALSE)fontcheck(family = "Arial", error = FALSE, quiet = FALSE)
family |
Font family to check. |
error |
Whether to throw an informative error when the font is missing. |
quiet |
Whether to suppress the status message. |
A logical scalar.
fontcheck("sans", quiet = TRUE)fontcheck("sans", quiet = TRUE)
List font families detected by the operating system and by the systemfonts registry.
fontlist(pattern = NULL)fontlist(pattern = NULL)
pattern |
Optional regular expression used to filter family names. |
A sorted character vector of font family names.
head(fontlist(), 10) fontlist("Arial")head(fontlist(), 10) fontlist("Arial")
Return a named colour palette. Call hue() without a name to list the
available palettes.
hue(name = NULL)hue(name = NULL)
name |
Palette name. Matching is case-insensitive. If |
A character vector of colours, or invisibly a character vector of
available palette names when name is NULL.
hue("NPG") hue("dark2")hue("NPG") hue("dark2")
imagesave() saves ggplot2 plots, pheatmap and ComplexHeatmap objects, grid
graphical objects, recorded base R plots, lattice plots, and plotting
functions. When plot is NULL, the current plot is captured with
grDevices::recordPlot().
imagesave( plot = NULL, name = "plot", outdir, format = "pdf", preset = NULL, width = 9, height = 9, units = "in", dpi = 300, bg = "white", quality = 95, compression = "lzw", pointsize = 12, family = base::getOption("Canton.font_family", NULL), overwrite = TRUE )imagesave( plot = NULL, name = "plot", outdir, format = "pdf", preset = NULL, width = 9, height = 9, units = "in", dpi = 300, bg = "white", quality = 95, compression = "lzw", pointsize = 12, family = base::getOption("Canton.font_family", NULL), overwrite = TRUE )
plot |
A plot object or a zero-argument function that draws a plot.
Supported objects include |
name |
Output filename stem. A supported extension in |
outdir |
Required output directory. No files are written unless an explicit, non-empty directory is supplied. |
format |
One or more of |
preset |
Optional built-in preset name or an object returned by
|
width, height
|
Plot dimensions. |
units |
Units for |
dpi |
Resolution for raster formats. |
bg |
Background colour. |
quality |
JPEG quality from 0 to 100. |
compression |
TIFF compression method. |
pointsize |
Default text point size for graphics devices. |
family |
Optional font family passed to graphics devices. |
overwrite |
Whether existing files may be overwritten. |
ggplot2 and grid-based objects are saved with ggplot2::ggsave(). Recorded
plots and plotting functions are redrawn on a format-specific graphics
device.
Invisibly, a named character vector containing the output paths.
p <- ggplot2::ggplot(mtcars, ggplot2::aes(mpg, wt)) + ggplot2::geom_point() imagesave(p, "scatter", outdir = tempdir(), format = c("png", "pdf")) imagesave(function() plot(mtcars$mpg, mtcars$wt), name = "base-plot", outdir = tempdir(), format = "png")p <- ggplot2::ggplot(mtcars, ggplot2::aes(mpg, wt)) + ggplot2::geom_point() imagesave(p, "scatter", outdir = tempdir(), format = c("png", "pdf")) imagesave(function() plot(mtcars$mpg, mtcars$wt), name = "base-plot", outdir = tempdir(), format = "png")
Create one or more directories recursively. Existing directories are left unchanged, making the function safe to call repeatedly.
mkdir(directory)mkdir(directory)
directory |
One or more directory paths. |
Invisibly, normalized directory paths.
mkdir(file.path(tempdir(), "canton-example"))mkdir(file.path(tempdir(), "canton-example"))
Return the absolute path of the current working directory.
pwd()pwd()
A character scalar containing the current working directory.
pwd()pwd()
Font settings now restore automatically when the code block in
setfont() exits. This compatibility helper does not modify user settings.
resetfont(quiet = FALSE)resetfont(quiet = FALSE)
quiet |
Suppress the status message. |
Invisibly, FALSE; no persistent settings need restoring.
resetfont(quiet = TRUE)resetfont(quiet = TRUE)
Without code, validate and return a font family without changing settings.
With code, apply the font during evaluation and restore the previous
options, ggplot2 theme, and existing device's font on exit, including errors.
No graphics device is opened and no persistent plotting hook is installed.
Print ggplot objects inside the block to render them with the temporary theme.
setfont(family = "Arial", fallback = NULL, quiet = FALSE, code)setfont(family = "Arial", fallback = NULL, quiet = FALSE, code)
family |
Font family. Defaults to |
fallback |
Optional available fallback, used with a warning. |
quiet |
Suppress the status message. |
code |
Optional expression evaluated with temporary font settings. For base graphics, open an explicit device before calling this function. |
Without code, invisibly the validated family; otherwise the
result of evaluating code.
family <- setfont("sans", quiet = TRUE) theme_canton(base_family = family) setfont("sans", quiet = TRUE, code = { theme_canton() })family <- setfont("sans", quiet = TRUE) theme_canton(base_family = family) setfont("sans", quiet = TRUE, code = { theme_canton() })
A compact classic theme with explicit font, line, tick, legend, and grid defaults suitable as a starting point for scientific figures.
theme_canton( base_size = 10, base_family = base::getOption("Canton.font_family", "sans"), grid = c("none", "major", "both"), legend_position = "right" )theme_canton( base_size = 10, base_family = base::getOption("Canton.font_family", "sans"), grid = c("none", "major", "both"), legend_position = "right" )
base_size |
Base font size in points. |
base_family |
Base font family. Defaults to the temporary family inside
a |
grid |
Which panel grid lines to show: |
legend_position |
ggplot2 legend position. |
A ggplot2 theme object.
ggplot2::ggplot(mtcars, ggplot2::aes(mpg, wt)) + ggplot2::geom_point() + theme_canton()ggplot2::ggplot(mtcars, ggplot2::aes(mpg, wt)) + ggplot2::geom_point() + theme_canton()
Attach one or more installed packages while suppressing startup messages. Package names may be supplied as bare names, strings, or character vectors.
using(...)using(...)
... |
Package names supplied as bare names, character strings, or character vectors. |
Invisibly, a named logical vector indicating which packages were loaded successfully.
using(ggplot2) using(c("ggplot2", "grid"))using(ggplot2) using(c("ggplot2", "grid"))