Rev 85977 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/grid/man/grid.xspline.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2025 R Core Team% Distributed under GPL 2 or later\name{grid.xspline}\alias{grid.xspline}\alias{xsplineGrob}\title{ Draw an \I{Xspline} }\description{These functions create and draw an \I{xspline}, a curve drawnrelative to control points.}\usage{grid.xspline(...)xsplineGrob(x = c(0, 0.5, 1, 0.5), y = c(0.5, 1, 0.5, 0),id = NULL, id.lengths = NULL,default.units = "npc",shape = 0, open = TRUE, arrow = NULL, repEnds = TRUE,name = NULL, gp = gpar(), vp = NULL)}\arguments{\item{x}{A numeric vector or unit object specifying x-locations ofspline control points.}\item{y}{A numeric vector or unit object specifying y-locations ofspline control points.}\item{id}{A numeric vector used to separate locations in \code{x} and\code{y} into multiple \I{xspline}s. All locations with the same\code{id} belong to the same \I{xspline}.}\item{id.lengths}{A numeric vector used to separate locations in \code{x} and\code{y} into multiple \I{xspline}s. Specifies consecutive blocks oflocations which make up separate \I{xspline}s.}\item{default.units}{A string indicating the default units to useif \code{x} or \code{y}are only given as numeric vectors.}\item{shape}{A numeric vector of values between -1 and 1, whichcontrol the shape of the spline relative to the control points.}\item{open}{A logical value indicating whether the spline isa line or a closed shape.}\item{arrow}{A list describing arrow heads to place at either endof the \I{xspline}, as produced by the \code{arrow} function.}\item{repEnds}{A logical value indicating whether the first andlast control points should be replicated for drawing the curve(see Details below).}\item{name}{ A character identifier. }\item{gp}{An object of class \code{"gpar"}, typically the outputfrom a call to the function \code{\link{gpar}}. This is basicallya list of graphical parameter settings.}\item{vp}{A Grid viewport object (or NULL).}\item{\dots}{Arguments to be passed to \code{xsplineGrob}.}}\value{A grob object.}\details{Both functions create an \I{xspline} grob (a graphical object describing an\I{xspline}), but only \code{grid.xspline}draws the \I{xspline}.An \I{xspline} is a line drawn relative to control points. For eachcontrol point, the linemay pass through (interpolate) the control point or itmay only approach (approximate) the controlpoint; the behaviour is determined by a shape parameter for eachcontrol point.If the shape parameter is greater than zero, the splineapproximates the control points (and isvery similar to a cubic B-spline when the shape is1). If the shape parameter is less than zero, the spline interpolatesthe control points (and is very similar to a \I{Catmull}-\I{Rom} spline whenthe shape is -1). If the shape parameter is 0, the spline forms asharp corner at that control point.For open \I{xspline}s, the start and end control points must have a shapeof 0 (and non-zero values are silently converted to zero without warning).For open \I{xspline}s, by default the start and end control points areactually replicated before the curve is drawn. A curve is drawnbetween (interpolating or approximating)the second and third of each set of four control points, sothis default behaviour ensures thatthe resulting curve starts at the first control point you havespecified and ends at the last control point.The defaultbehaviour can be turned off via the \code{repEnds} argument,in which case the curve that is drawn starts (approximately) atthe second control point and ends (approximately) at the first andsecond-to-last control point.The \code{repEnds} argument is ignored for closed \I{xspline}s.Missing values are not allowed for \code{x} and \code{y}(i.e., it is not valid for a control point to be missing).For closed \I{xspline}s, a curve is automatically drawnbetween the final control point and the initial control point.}\references{\bibshow{R:Blanc+Schlick:1995}}\seealso{\link{Grid},\code{\link{viewport}},\code{\link{arrow}}.\code{\link{xspline}}.}\examples{x <- c(0.25, 0.25, 0.75, 0.75)y <- c(0.25, 0.75, 0.75, 0.25)xsplineTest <- function(s, i, j, open) {pushViewport(viewport(layout.pos.col=j, layout.pos.row=i))grid.points(x, y, default.units="npc", pch=16, size=unit(2, "mm"))grid.xspline(x, y, shape=s, open=open, gp=gpar(fill="grey"))grid.text(s, gp=gpar(col="grey"),x=unit(x, "npc") + unit(c(-1, -1, 1, 1), "mm"),y=unit(y, "npc") + unit(c(-1, 1, 1, -1), "mm"),hjust=c(1, 1, 0, 0),vjust=c(1, 0, 0, 1))popViewport()}pushViewport(viewport(width=.5, x=0, just="left",layout=grid.layout(3, 3, respect=TRUE)))pushViewport(viewport(layout.pos.row=1))grid.text("Open Splines", y=1, just="bottom")popViewport()xsplineTest(c(0, -1, -1, 0), 1, 1, TRUE)xsplineTest(c(0, -1, 0, 0), 1, 2, TRUE)xsplineTest(c(0, -1, 1, 0), 1, 3, TRUE)xsplineTest(c(0, 0, -1, 0), 2, 1, TRUE)xsplineTest(c(0, 0, 0, 0), 2, 2, TRUE)xsplineTest(c(0, 0, 1, 0), 2, 3, TRUE)xsplineTest(c(0, 1, -1, 0), 3, 1, TRUE)xsplineTest(c(0, 1, 0, 0), 3, 2, TRUE)xsplineTest(c(0, 1, 1, 0), 3, 3, TRUE)popViewport()pushViewport(viewport(width=.5, x=1, just="right",layout=grid.layout(3, 3, respect=TRUE)))pushViewport(viewport(layout.pos.row=1))grid.text("Closed Splines", y=1, just="bottom")popViewport()xsplineTest(c(-1, -1, -1, -1), 1, 1, FALSE)xsplineTest(c(-1, -1, 0, -1), 1, 2, FALSE)xsplineTest(c(-1, -1, 1, -1), 1, 3, FALSE)xsplineTest(c( 0, 0, -1, 0), 2, 1, FALSE)xsplineTest(c( 0, 0, 0, 0), 2, 2, FALSE)xsplineTest(c( 0, 0, 1, 0), 2, 3, FALSE)xsplineTest(c( 1, 1, -1, 1), 3, 1, FALSE)xsplineTest(c( 1, 1, 0, 1), 3, 2, FALSE)xsplineTest(c( 1, 1, 1, 1), 3, 3, FALSE)popViewport()}\keyword{dplot}