stat_xspline | R Documentation |
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.
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,
...
)
mapping |
Set of aesthetic mappings created by |
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 |
show.legend |
logical. Should this layer be included in the legends? |
inherit.aes |
If |
spline_shape |
Numeric value controlling the shape of the spline. Default is -0.25. |
open |
Logical. If |
rep_ends |
Logical. If |
... |
Other arguments passed on to |
A ggplot2 layer that can be added to a plot.
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).
x X coordinates of the spline.
y Y coordinates of the spline.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.