Learn R Programming

TransProR (version 1.0.5)

stat_xspline: X-spline Statistic for ggplot2 (adapted from ggalt)

Description

This statistic adds an X-spline interpolation to your ggplot2 plots, allowing for smooth curves through a series of points. The implementation is adapted from the stat_xspline function in the ggalt package (GPL-3), originally authored by Bob Rudis.

Usage

stat_xspline(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  na.rm = TRUE,
  show.legend = NA,
  inherit.aes = TRUE,
  spline_shape = -0.25,
  open = TRUE,
  rep_ends = TRUE,
  ...
)

Value

A ggplot2 layer that can be added to a plot.

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_().

data

The data to be displayed in this layer.

geom

The geometric object to use display the data.

position

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

na.rm

If FALSE (the default), removes missing values with a warning. If TRUE silently removes missing values.

show.legend

logical. Should this layer be included in the legends?

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

spline_shape

Numeric value controlling the shape of the spline. Default is -0.25.

open

Logical. If TRUE, the spline is open; if FALSE, it is closed.

rep_ends

Logical. If TRUE, the end points are repeated.

...

Other arguments passed on to layer().

License and Attribution

This code is adapted from the ggalt package (https://github.com/hrbrmstr/ggalt), which is licensed under GPL-3. Original author: Bob Rudis (bob@rud.is).

Computed variables

  • x X coordinates of the spline.

  • y Y coordinates of the spline.

Examples

Run this code
# \donttest{
library(ggplot2)
df <- data.frame(x = 1:10, y = cumsum(rnorm(10)))
ggplot(df, aes(x, y)) +
  geom_point() +
  stat_xspline(spline_shape = 0.5)
# }

Run the code above in your browser using DataLab