View source: R/bspline_closed.R
geom_bspline_closed | R Documentation |
This geom creates closed b-spline curves and draws them as shapes. The
closed b-spline is achieved by wrapping the control points rather than the
knots. The *0 version uses the grid::xsplineGrob()
function with
open = FALSE
and can thus not be manipulated as a shape geom in the same
way as the base version (expand, contract, etc).
stat_bspline_closed(
mapping = NULL,
data = NULL,
geom = "shape",
position = "identity",
na.rm = FALSE,
n = 100,
show.legend = NA,
inherit.aes = TRUE,
...
)
geom_bspline_closed(
mapping = NULL,
data = NULL,
stat = "bspline",
position = "identity",
n = 100,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
geom_bspline_closed0(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
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 |
geom |
The geometric object to use to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
n |
The number of points generated for each spline |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
stat |
The statistical transformation to use on the data for this
layer, either as a |
geom_bspline_closed understand the following aesthetics (required aesthetics are in bold):
x
y
color
fill
linewidth
linetype
alpha
The coordinates for the path describing the spline
The progression along the interpolation mapped between 0 and 1
Thomas Lin Pedersen. The C++ code for De Boor's algorithm has been adapted from Jason Yu-Tseh Chi implementation
# Create 6 random control points
controls <- data.frame(
x = runif(6),
y = runif(6)
)
ggplot(controls, aes(x, y)) +
geom_polygon(fill = NA, colour = 'grey') +
geom_point(colour = 'red') +
geom_bspline_closed(alpha = 0.5)
# The 0 version approximates the correct shape
ggplot(controls, aes(x, y)) +
geom_polygon(fill = NA, colour = 'grey') +
geom_point(colour = 'red') +
geom_bspline_closed0(alpha = 0.5)
# But only the standard version supports geom_shape operations
# Be aware of self-intersections though
ggplot(controls, aes(x, y)) +
geom_polygon(fill = NA, colour = 'grey') +
geom_point(colour = 'red') +
geom_bspline_closed(alpha = 0.5, expand = unit(2, 'cm'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.