Changelog
Source:NEWS.md
ggvfields (development version)
Changes in behavior
The gam smoother of
geom_vector_smooth(),geom_stream_smooth()and their stats fitsfxandfytogether in mgcv’s multivariate normal family, which also estimates the correlation of their residuals. Ellipses and wedges account for that correlation, so ellipses tilt whenfxandfyare correlated, and the prediction regions have their stated coverage. Each smooth uses at most half as many basis functions as there are locations. With fewer than 10 locations, or data without noise,fxandfyare fitted separately as before. ## New featuresgeom_vector_smooth(pi_type = "length")draws a prediction interval for the length of each vector, as a band along it, from the exact distribution of the length of the predicted tip. It joins the ellipse (a joint region for the tip) and the wedge (an interval for the direction), for every method.grid = "even"in the stream layers (geom_stream_field(),geom_gradient_field(type = "stream")and their relatives) draws evenly spaced streamlines (Jobard and Lefer, 1997): streams are grown until they come close to another stream, and new ones are started beside earlier ones, so they fill the plot about one grid spacing apart.The stream, vector and gradient field layers take a
domainfunction that restricts the field to a region: seeds outside it are dropped and streams stop at its boundary, so a field only defined on part of the plot can be drawn there (#37).
Bug fixes
-
scale_length_continuous()with a transformation that makes some values negative, such astransform = "log10"with norms below 1, keeps every vector’s direction: lengths run from a tenth ofmax_rangefor the smallest value tomax_rangefor the largest (#24).
ggvfields 1.1.0
CRAN release: 2026-11-15
Changes in behavior
- Streams are now computed with a Runge-Kutta 4 integrator by default (
method = "rk4"), ingeom_stream_field()and its relatives as well asgeom_gradient_field(type = "stream"),geom_stream_smooth()andgeom_gradient_smooth(). Streams follow the field more closely, which changesavg_spdslightly. Streams stop at sinks and at singularities such as point charges, and cross jumps in the field, such as one defined withsign()orifelse(). The adaptive deSolve integrator remains available asmethod = "lsoda", and"euler"is also available. An unknownmethodis an error. -
geom_stream_field2()andstat_stream_field2()now grow every stream to lengthLand then crop all of them back to the time of the fastest one, so a stream’s length shows its speed relative to the fastest, as the vectors ofgeom_vector_field2()do.type = "vector"is unchanged. - Mapped lengths are proportional to the mapped value: in
geom_vector2(),geom_vector_field2()andgeom_gradient_field2(type = "vector"), a vector with half the largest norm is drawn half as long. The longest vector ismax_rangecentimeters (0.5 by default; set it withscale_length_continuous()), and the legend shows the same lengths. - The ellipses and wedges of
geom_vector_smooth(method = "gam"), the default, are now prediction intervals for a new observation at each location, as formethod = "lm"andmethod = "kriging": they include each component’s residual variance as well as the variance of the fit. They are larger than before. - The wedges of
geom_vector_smooth(pi_type = "wedge")are computed from the exact distribution of the angle of the predicted vector tip, so they cover the statedconf_levelhowever large the uncertainty, and are asymmetric when the uncertainty is. They are wider than before where the uncertainty is large. - Supplying
formulawith the defaultmethod = "gam"ingeom_stream_smooth(),stat_stream_smooth(),geom_vector_smooth()orstat_vector_smooth()now gives a warning, since the gam smoothers fitfxandfywiths(x, y). Usemethod = "lm"to fit a formula. - The default of
conf_levelingeom_vector_smooth()is now0.95. Results are the same.
New features and improvements
-
geom_stream_smooth(),geom_vector_smooth()and their stats work with small data sets: with fewer than 30 distinct locations the gam smoother uses half as many basis functions as locations. At least 5 locations are needed; with fewer, the error suggestsmethod = "lm". - With a supplied
griddata frame, the default lengthLof vectors and streams is 0.85 times the grid’s spacing (the median distance between neighboring points), so dense grids do not overplot. Regular grids get the same length as before. -
geom_vector_smooth()andstat_vector_smooth()choose the interval style by default (pi_type = NULL): ellipses ateval_pointsand wedges on a grid, without a message. They also gainxlimandylimto set the range of the grid, which defaults to the range of the data. -
geom_vector_smooth(method = "kriging")estimates the range of its variogram from the data and works in standardized coordinates, so the smoothed field does not depend on the units ofxandy. The fitted coregionalization is kept positive definite. - Vectors in polar form take their magnitude from the
normaesthetic, the same name as the computed variable, withangleorangle_deg.distanceis accepted as another name for it. The stream smoothers take polar input without an “unknown aesthetics” warning. -
geom_gradient_field(),geom_gradient_field2()and their stats take amethodargument for the stream integrator, asgeom_stream_field()does. -
stat_vector_smooth()is exported. -
StatStreamSmoothandStatGradientSmoothare the stats behindgeom_stream_smooth()andgeom_gradient_smooth(). -
stat_vector()mapscolor = after_stat(norm)by default, likegeom_vector(). -
geom_gradient_field2(type = "vector")andstat_gradient_field2(type = "vector")maplength = after_stat(norm), so vectors are scaled by the size of the gradient, likegeom_vector_field2(). Streams are unchanged. - Layers computed from a function (
stat_stream_field(),geom_gradient_field(),geom_gradient_field2(),geom_potential()and theirstat_*()versions) default toinherit.aes = FALSE, likegeom_vector_field()andgeom_stream_field(), so they can be added to a plot that has its own data, for example to draw a field behind observed vectors. -
stat_stream_field()passesnormalizeandstat_stream_field2()passestolthrough to the computation, asgeom_stream_field()andgeom_stream_field2()do. -
efield_maker()passeskandq_testto the field it returns, and the field keeps the argument valuesefield_maker()was called with, so fields can be made in a loop. -
linetypeapplies to vector layers such asgeom_vector()andgeom_vector_field().
Stream speeds (avg_spd)
-
avg_spd, the default color of streams, is the length of the drawn stream divided by the time it took, in every mode:- streams run to a time
T, and streams withnormalize = FALSEthat are cropped to the time of the fastest stream, use that shared time, so color and length agree; - a stream run to a length
Lthat stops short of it at a sink would take unbounded time to reach the sink, so its speed is measured up to 99% of the length it achieved. This makes it the same for every integrator.
- streams run to a time
Bug fixes
Streams stop where the field becomes infinite, and the field function is only called at finite points.
Streams computed with
method = "lsoda"only include points where the field is defined, so a stream that runs to the edge of the field’s domain is drawn up to that edge.geom_vector_smooth()takes a fixed or mappedcolourfor its vectors (blue by default), and keeps a fixedlinewidthwhen there is a single evaluation point.geom_gradient_smooth()keeps a color mapping supplied inmapping, and every field layer, includinggeom_gradient_field2(), gives the same error for an unknowntype.geom_stream_smooth(),geom_gradient_smooth()andgeom_vector_smooth()always use the stat that fits their model; a differentstatis ignored with a warning.Centered streams (
center = TRUE, the default) are drawn when a stream can move only one way from its seed, for example on the edge of the domain where the field is defined.Stream layers skip seed points where the field is undefined, for example a grid point on a charge with
efield_maker(), and draw the remaining streams.geom_stream()gives the same message asgeom_path()when every group has a single observation.geom_stream_smooth()andstat_stream_smooth()accept fixed aesthetics such ascolor = "red"orlinewidth = 2without a warning, and respectcolour = "red".
Performance
-
geom_stream_smooth()andgeom_gradient_smooth()fit their model once per group rather than at every evaluation of the field, which is much faster. - Computing streams with
method = "lsoda"is about twice as fast.
Documentation
- The help pages document the defaults of
pi_typeingeom_vector_smooth()(ellipses ateval_points, wedges on a grid) and ofningeom_potential(), whosefunreturns a vector. - The smoothers are documented as using a gam by default, with
formulaapplying tomethod = "lm". - Angles in
geom_stream_smooth()are documented as radians, and thegeom_vector_smooth()examples are clarified. - The help for
geom_stream_field(),geom_vector_field()andgeom_gradient_field()describes howL,Tandnormalizeset the length of streams and vectors, including that a centered stream run to a timeTruns forTin each direction. -
geom_gradient_field()documents its defaulttype("vector") and its default colors (normfor vectors,avg_spdfor streams). - The
normcomputed variable,Lingeom_vector2(),loginefield()and the computed variables ofgeom_potential()are described more precisely. - Examples are run when the package is checked.
- The pkgdown site is at https://dustysturner.com/ggvfields/.
Internal
- sp and gstat are suggested rather than imported, since only
method = "kriging"ingeom_vector_smooth()needs them; you are asked to install them the first time you use it. farver is no longer a dependency, and rlang is declared. - The package uses only exported ggplot2 functions.
- Each
geom_*()/stat_*()pair is built by one shared internal constructor, and a test checks that both members of a pair pass the same parameters and default mappings. - Errors are raised with cli throughout.
- Added tests for the changes above, visual snapshot tests with vdiffr (now in Suggests; CRAN skips them), and an R CMD check workflow.
ggvfields 1.0.1
CRAN release: 2026-06-18
- Fixed the
lengthlegend forgeom_vector_field2()(and the related stream geoms):GeomStreamnow uses a customdraw_keythat dispatches todraw_key_length()when thelengthaesthetic is mapped, so the legend relating segment lengths to vector norms is drawn again. - Corrected the handling of the time variable
tingeom_stream(). - Fixed the draw order of grobs in the stream and vector geoms and suppressed spurious output from the kriging step.
- Fixed handling of the
linewidthargument. - Added an option to choose between
gamandlmwhen smoothing.