Set or query graphical parameters

Description

Extends par, serving as a (near) drop-in replacement for setting or querying graphical parameters. The key differences is that, beyond supporting the standard group of R graphical parameters in par, tpar also supports additional graphical parameters that are provided by tinyplot. Similar to par, parameters are set by passing appropriate key = value argument pairs, and multiple parameters can be set or queried at the same time.

Usage

tpar(..., hook = FALSE)

Arguments

arguments of the form key = value. This includes all of the parameters typically supported by par, as well as the tinyplot-specific ones described in the ‘Graphical Parameters’ section below.
hook Logical. If TRUE, base graphical parameters persist across plots via a hook applied before each new plot (see ?setHook).

Details

The tinyplot-specific parameters are saved in an internal environment called .tpar for performance and safety reasons. However, they can also be set at package load time via options, which may prove convenient for users that want to enable different default behaviour at startup (e.g., through an .Rprofile file). These options all take a tinyplot_* prefix, e.g. options(tinyplot_grid = TRUE, tinyplot_facet.bg = “grey90”).

For their part, any "base" graphical parameters are caught dynamically and passed on to par as appropriate. Technically, only parameters that satisfy par(…, no.readonly = TRUE) are evaluated.

However, note the important distinction: tpar only evaluates parameters from par if they are passed explicitly by the user. This means that tpar should not be used to capture the (invisible) state of a user’s entire set of graphics parameters, i.e. tpar() != par(). If you want to capture the all existing graphics settings, then you should rather use par() instead.

Value

When parameters are set, their previous values are returned in an invisible named list. Such a list can be passed as an argument to tpar to restore the parameter values.

When just one parameter is queried, the value of that parameter is returned as (atomic) vector. When two or more parameters are queried, their values are returned in a list, with the list names giving the parameters.

Note the inconsistency: setting one parameter returns a list, but querying one parameter returns a vector.

Additional Graphical Parameters

  • adj.xlab: Numeric value between 0 and 1 controlling the alignment of the x-axis label.

  • adj.ylab: Numeric value between 0 and 1 controlling the alignment of the y-axis label.

  • dynmar: Logical indicating whether tinyplot should attempt dynamic adjustment of margins to reduce whitespace and/or account for spacing of text elements (e.g., long horizontal y-axis labels). Note that this parameter is tightly coupled to internal tinythemes() logic and should not be adjusted manually unless you really know what you are doing or don’t mind risking unintended consequences to your plot.

  • facet.bg: Character or integer specifying the facet background colour. If an integer, will correspond to the user’s default colour palette (see palette). Passed to rect. Defaults to NULL (none).

  • facet.border: Character or integer specifying the facet border colour. If an integer, will correspond to the user’s default colour palette (see palette). Passed to rect. Defaults to NA (none).

  • facet.cex: Expansion factor for facet titles. Defaults to 1.

  • facet.col: Character or integer specifying the facet text colour. If an integer, will correspond to the user’s default global colour palette (see palette). Defaults to NULL, which is equivalent to "black".

  • facet.font: An integer corresponding to the desired font face for facet titles. For most font families and graphics devices, one of four possible values: 1 (regular), 2 (bold), 3 (italic), or 4 (bold italic). Defaults to NULL, which is equivalent to 1 (i.e., regular).

  • file.height: Numeric specifying the height (in inches) of any plot that is written to disk using the tinyplot(…, file = X) argument. Defaults to 7.

  • file.res: Numeric specifying the resolution (in dots per square inch) of any plot that is written to disk in bitmap format (i.e., PNG or JPEG) using the tinyplot(…, file = X) argument. Defaults to 300.

  • file.width: Numeric specifying the width (in inches) of any plot that is written to disk using the tinyplot(…, file = X) argument. Defaults to 7.

  • fmar: A numeric vector of form c(b,l,t,r) for controlling the (base) margin padding, in terms of lines, between the individual facets in a faceted plot. Defaults to c(1,1,1,1). If more than three facets are detected, the fmar parameter is scaled by 0.75 to reduce excess whitespace. For 2x2 plots, the padding better matches the cex expansion logic of base graphics.

  • grid.col: Character or (integer) numeric that specifies the color of the panel grid lines. Defaults to “lightgray”.

  • grid.lty: Character or (integer) numeric that specifies the line type of the panel grid lines. Defaults to “dotted”.

  • grid.lwd: Non-negative numeric giving the line width of the panel grid lines. Defaults to 1.

  • grid: Logical indicating whether a background panel grid should be added to plots automatically. Defaults to NULL, which is equivalent to FALSE.

  • lmar: A numeric vector of form c(inner, outer) that gives the margin padding, in terms of lines, around the automatic tinyplot legend. Defaults to c(1.0, 0.1). The inner margin is the gap between the legend and the plot region, and the outer margin is the gap between the legend and the edge of the graphics device.

  • palette.qualitative: Palette for qualitative colors. See the palette argumetn in ?tinyplot.

  • palette.sequential: Palette for sequential colors. See the palette argumetn in ?tinyplot.

  • ribbon.alpha: Numeric factor in the range [0,1] for modifying the opacity alpha of "ribbon" and "area" type plots. Default value is 0.2.

See Also

graphics::par which tpar builds on top of. get_saved_par is a convenience function for retrieving graphical parameters at different stages of a tinyplot call (and used for internal accounting purposes). tinytheme allows users to easily set a group of graphics parameters in a single function call, according to a variety of predefined themes.

Examples

library("tinyplot")

# Return a list of existing base and tinyplot graphic params
tpar("las", "pch", "facet.bg", "facet.cex", "grid")
$las
[1] 0

$pch
[1] 1

$facet.bg
NULL

$facet.cex
[1] 1

$grid
[1] FALSE
# Simple facet plot with these default values
tinyplot(mpg ~ wt, data = mtcars, facet = ~am)

# Set params to something new. Similar to graphics::par(), note that we save
# the existing values at the same time by assigning to an object.
op = tpar(
  las       = 1,
  pch       = 2,
  facet.bg  = "grey90",
  facet.cex = 2,
  grid      = TRUE
)

# Re-plot with these new params
tinyplot(mpg ~ wt, data = mtcars, facet = ~am)

# Reset back to original values
tpar(op)

# Important: tpar() only evalutes parameters that have been passed explicitly
#   by the user. So it it should not be used to query and set (restore)
#   parameters that weren't explicitly requested, i.e. tpar() != par().

# Note: The tinyplot-specific parameters can also be be set via `options`
#   with a `tinyplot_*` prefix, which can be convenient for enabling
#   different default behaviour at startup time (e.g., via an .Rprofile
#   file). Example:
# options(tinyplot_grid = TRUE, tinyplot_facet.bg = "grey90")