| geom_bspline {ggforce} | R Documentation |
This set of stats and geoms makes it possible to draw b-splines based on a
set of control points. As with geom_bezier there exists several
versions each having there own strengths. The base version calculates the
b-spline as a number of points along the spline and connects these with a
path. The *2 version does the same but in addition interpolates aesthetics
between each control point. This makes the *2 version considerably slower
so it shouldn't be used unless needed. The *0 version uses
xsplineGrob with shape = 1 to approximate a
b-spline for a high performant version.
stat_bspline(mapping = NULL, data = NULL, geom = "path", position = "identity", na.rm = FALSE, n = 100, show.legend = NA, inherit.aes = TRUE, ...) geom_bspline(mapping = NULL, data = NULL, stat = "bspline", position = "identity", arrow = NULL, n = 100, lineend = "butt", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) stat_bspline2(mapping = NULL, data = NULL, geom = "path_interpolate", position = "identity", na.rm = FALSE, n = 100, show.legend = NA, inherit.aes = TRUE, ...) geom_bspline2(mapping = NULL, data = NULL, stat = "bspline2", position = "identity", arrow = NULL, n = 100, lineend = "butt", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) stat_bspline0(mapping = NULL, data = NULL, geom = "bspline0", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) geom_bspline0(mapping = NULL, data = NULL, stat = "identity", position = "identity", arrow = NULL, lineend = "butt", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
mapping |
Set of aesthetic mappings created by |
data |
A data frame. If specified, overrides the default data frame defined at the top level of the plot. |
geom, |
stat Override the default connection between |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
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, as a string. |
arrow |
specification for arrow heads, as created by arrow() |
lineend |
Line end style (round, butt, square) |
geom_edge_bundle understand the following aesthetics (required aesthetics are in bold):
x
y
color
size
linetype
alpha
lineend
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
Holten, D. (2006). Hierarchical edge bundles: visualization of adjacency relations in hierarchical data. IEEE Transactions on Visualization and Computer Graphics, 12(5), 741-748. http://doi.org/10.1109/TVCG.2006.147
# Define some control points
cp <- data.frame(
x = c(0, -5, -5, 5, 5, 2.5, 5, 7.5, 5, 2.5, 5, 7.5, 5, -2.5, -5, -7.5, -5,
-2.5, -5, -7.5, -5),
y = c(0, -5, 5, -5, 5, 5, 7.5, 5, 2.5, -5, -7.5, -5, -2.5, 5, 7.5, 5, 2.5,
-5, -7.5, -5, -2.5),
class = sample(letters[1:3], 21, replace = TRUE)
)
# Now create some paths between them
paths <- data.frame(
ind = c(7,5,8,8,5,9,9,5,6,6,5,7,7,5,1,3,15,8,5,1,3,17,9,5,1,2,19,6,5,1,4,
12,7,5,1,4,10,6,5,1,2,20),
group = c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,
9,9,9,9,9,10,10,10,10,10)
)
paths$x <- cp$x[paths$ind]
paths$y <- cp$y[paths$ind]
paths$class <- cp$class[paths$ind]
ggplot() +
geom_bspline(aes(x=x, y=y, group=group, colour = ..index..), data=paths) +
geom_point(aes(x=x, y=y), data=cp, color='steelblue')
ggplot() +
geom_bspline2(aes(x=x, y=y, group=group, colour = class), data=paths) +
geom_point(aes(x=x, y=y), data=cp, color='steelblue')
ggplot() +
geom_bspline0(aes(x=x, y=y, group=group), data=paths) +
geom_point(aes(x=x, y=y), data=cp, color='steelblue')