geom_xspline: Xspline geom for ggplot2

View source: R/plot.R

geom_xsplineR Documentation

Xspline geom for ggplot2

Description

Based upon xsplineGrob in base R, geom_xspline draws an X-spline using control points. The end result is a smooth line that can be used as a replacement to geom_line.

Usage

geom_xspline(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  spline_shape = -1,
  open = TRUE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

stat

The statistical transformation to use on the data for this layer, as a string.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

spline_shape

A numeric value between -1 and 1 (shape of spline to control points geom_xspline).

open

A logical value for if the X-spline has open or closed shape.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

Details

This code was written since geom_xspline did not operate well with ggarrange at the time.

Source

Adjusted from geom_xspline by Bob Rudis (hrbrmstr): https://github.com/hrbrmstr/ggalt/blob/master/R/geom_xspline2.r.

References

Blanc, C. and Schlick, C. (1995), "X-splines : A Spline Model Designed for the End User", in Proceedings of SIGGRAPH 95, pp. 377-386. http://dept-info.labri.fr/~schlick/DOC/sig1.html

See Also

Extending ggplot2: https://ggplot2.tidyverse.org/articles/extending-ggplot2.html; Blog post on custom ggplot2 functions by hrbrmstr: https://rud.is/b/2015/09/08/roll-your-own-stats-and-geoms-in-ggplot2-part-1-splines/; xspline; grid.xspline.

Examples

## Not run: 
library(ggplot2)
library(magrittr)

# Create plot and then use ggarrange to merge the two
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
  geom_xspline(spline_shape = -.25) +
  geom_point()

ggpubr::ggarrange(myplot, myplot)

## End(Not run)

al-obrien/farrago documentation built on April 14, 2023, 6:20 p.m.