| geom_xspline | R Documentation |
Draw an X-spline through control points with proper grouping support
geom_xspline(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
na.rm = FALSE,
shape = 0,
open = TRUE,
rep_ends = TRUE,
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.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
shape |
A numeric vector of values between -1 and 1, which control the shape of the spline relative to the control points. |
open |
A logical value indicating whether the spline is an open or a closed shape. |
rep_ends |
For open X-splines, a logical value indicating whether the first and last control points should be replicated for drawing the curve. Ignored for closed X-splines. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to
|
library(ggplot2)
set.seed(123)
df <- data.frame(
x = 1:10,
y = cumsum(rnorm(10))
)
ggplot(df, aes(x, y)) +
geom_point() +
geom_xspline(color = "blue", linewidth = 1.2, shape=1)
ggplot(df, aes(x, y)) +
geom_point() +
geom_xspline(color = "blue", linewidth = 1.2, shape=-1)
df2 <- data.frame(
x = rep(1:10, 2),
y = c(cumsum(rnorm(10)), cumsum(rnorm(10))),
group = rep(c("A", "B"), each = 10)
)
ggplot(df2, aes(x, y, color = group, group = group)) +
geom_point() +
geom_xspline(linewidth = 1) +
scale_color_manual(values = c("A" = "tomato", "B" = "steelblue"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.