geom_xspline | R Documentation |
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
.
geom_xspline(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
spline_shape = -1,
open = TRUE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
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 |
open |
A logical value for if the X-spline has open or closed shape. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
This code was written since geom_xspline
did not operate well with ggarrange
at the time.
Adjusted from geom_xspline
by Bob Rudis (hrbrmstr): https://github.com/hrbrmstr/ggalt/blob/master/R/geom_xspline2.r.
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
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
.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.