| Title: | Area-Proportional Euler and Venn Diagrams with Ellipses |
| Version: | 8.0.0 |
| Description: | Generate area-proportional Euler diagrams using numerical optimization. An Euler diagram is a generalization of a Venn diagram, relaxing the criterion that all interactions need to be represented. Diagrams may be fit with ellipses and circles via a wide range of inputs and can be visualized in numerous ways. |
| Depends: | R (≥ 4.2) |
| Imports: | graphics, grDevices, grid, stats, utils |
| Suggests: | covr, knitr, lattice, pBrackets, RConics, rmarkdown, testthat, spelling |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| LazyData: | true |
| VignetteBuilder: | knitr |
| URL: | https://github.com/jolars/eulerr, https://jolars.github.io/eulerr/ |
| BugReports: | https://github.com/jolars/eulerr/issues |
| RoxygenNote: | 7.3.3 |
| Language: | en-US |
| Config/rextendr/version: | 0.4.2 |
| SystemRequirements: | Cargo (Rust's package manager), rustc >= 1.84.1 |
| NeedsCompilation: | yes |
| Packaged: | 2026-05-29 14:54:09 UTC; jola |
| Author: | Johan Larsson |
| Maintainer: | Johan Larsson <johanlarsson@outlook.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-05-29 17:10:03 UTC |
eulerr: Area-Proportional Euler and Venn Diagrams with Ellipses
Description
Generate area-proportional Euler diagrams using numerical optimization. An Euler diagram is a generalization of a Venn diagram, relaxing the criterion that all interactions need to be represented. Diagrams may be fit with ellipses and circles via a wide range of inputs and can be visualized in numerous ways.
Author(s)
Maintainer: Johan Larsson johanlarsson@outlook.com (ORCID)
Other contributors:
A. Jonathan R. Godfrey [contributor]
Peter Gustafsson [contributor]
David H. Eberly (geometric algorithms) [contributor]
Emanuel Huber (root solver code) [contributor]
Florian Privé [contributor]
See Also
Useful links:
Report bugs at https://github.com/jolars/eulerr/issues
Fixed padding in pt for the panel viewport scale.
Description
Geometry / labels that land flush with the bbox would otherwise be clipped at the device edge by stroke width and anti-aliasing — both of which are in device units, not native units, so the padding is in pt rather than a fraction of the coordinate range.
Usage
EULER_PANEL_PAD_PT
Format
An object of class numeric of length 1.
Enumerate all 2^n - 1 combination labels for a set of names
Description
Generates labels in cardinality-first order: singletons first, then pairs, then triples, etc. Within each cardinality, set names appear in their original order. Used only by the Venn path (bounded at n = 5).
Usage
all_set_combinations(setnames)
Arguments
setnames |
a character vector of set names |
Value
A character vector of length 2^n - 1.
Run eunoia label placement, expanding limits so exterior labels are
not clipped. Drives one initial pass plus one re-measure pass when
the limits widened by more than re_measure_threshold on the short
side. Updates centers (and the complement slot on container_data)
in place with placed (x, y) plus kind, tether_x, tether_y,
leader_end_x, leader_end_y.
Description
When placement_opts is NULL, defaults to eunoia's raycast + POI
tether.
Usage
apply_label_placement(
centers,
container_data,
shapes,
labels,
quantities,
annotations = NULL,
placement_opts = NULL,
do_complement_label = FALSE,
limits,
n_vertices,
label_precision,
re_measure_threshold = 0.01
)
Details
Returns a list with centers, container_data, and limits.
Overlay per-panel overrides onto a styling parameter
Description
Used to apply by_group overrides to fills, patterns, edges, labels,
and quantities for a single panel produced by euler(..., by = ...). The
override list contains gpar-level fields (and optionally rot), which are
overlaid onto param$gp (and param$set_gp for shape-mode patterns).
Structural fields are not overlaid here — they must be filtered upstream.
Usage
apply_panel_overrides(param, override)
Arguments
param |
a list with |
override |
a flat named list of fields to overlay. |
Value
The param list with overlaid fields.
Build the polyline leader for an exterior tag, or grid::nullGrob()
for interior / missing-tether placements.
Description
Draws the polyline tether → waypoints[1..] → leader_end. For
straight leaders (raycast / force-directed) waypoints_* are empty,
so the polyline collapses to the single tether → leader_end
segment. For elbow leaders eunoia emits one knee waypoint, producing
the orthogonal tether → knee → leader_end bend.
Usage
build_leader_grob(
ax,
ay,
kind,
tx,
ty,
lend_x,
lend_y,
waypoints_x = numeric(0),
waypoints_y = numeric(0),
leader_gp_list,
fallback_gp,
name
)
Details
Terminates at (lend_x, lend_y) — the point on the label box AABB
edge supplied by eunoia (LabelPlacement::leader_end). Falls back
to the anchor when the leader endpoint isn't finite so older /
partial placement results still draw something sensible.
Build the leader / label / quantity / annotation gList for one tag.
Description
Shared between setup_tag() (initial construction in setup_grobs())
and makeContent.EulerTags() (draw-time re-placement on resize).
Pure factory — no measurement; takes anchor + tether already in
native units, plus the stashed text / gpar bundle. The label /
quantity / annotation stack is centered vertically on (ax, ay)
so the bbox center matches the anchor eunoia placed and leader
endpoints land on the actual bbox edge.
Usage
build_tag_grobs(
ax,
ay,
kind,
tx,
ty,
lend_x,
lend_y,
label_text,
quantity_text,
annotation_text,
has_label,
has_quantity,
has_annotation,
label_gp,
quantity_gp,
annotation_gp,
label_rot,
quantity_rot,
annotation_rot,
number,
leader_gp_list,
padding,
waypoints_x = numeric(0),
waypoints_y = numeric(0),
name_prefix = "tag"
)
Return the fitted shape parameters from the euler object
Description
Returns the $shapes data frame — a tagged uniform schema with one row
per set, a type column, and shape-specific columns
(h, k, a, b, phi, width, height, side) populated according to the
chosen shape (other columns are NA). For circle/ellipse fits the
legacy $ellipses slot is still populated for back-compat; consumers
that need the new shapes (rectangle, square) must read $shapes.
Usage
## S3 method for class 'euler'
coef(object, ...)
Arguments
object |
object of class |
... |
ignored |
Value
a data frame of the fitted shape parameters
Default placement options used when the caller doesn't supply any.
Description
Mirrors eunoia::plotting::PlacementStrategy::default(): raycast
exterior solver, POI tether, proportional margin. Per-strategy knobs
iterations (force-directed) and min_gap (elbow) live alongside in
the flat shape that the Rust FFI expects; the user-facing sublists in
eulerr_options(labels = list(force_directed = ..., elbow = ...)) are
flattened into this shape by plot.euler() before placement runs.
Usage
default_placement_opts()
Dummy code a data.frame
Description
Dummy code a data.frame
Usage
dummy_code(x, sep = "_", factor_names = TRUE)
Arguments
x |
a data.frame |
sep |
character for separating dummy code factors and their levels when constructing names |
factor_names |
whether to include factor names when creating new names for dummy codes |
Value
A dummy-coded version of x.
Bounding box of a vector of rotated ellipses.
Description
Bounding box of a vector of rotated ellipses.
Usage
ellipse_bounding_box(h, k, a, b, phi)
Promote a legacy 5-column ellipse data frame (h, k, a, b, phi) into the
wide $shapes schema. Used by the venn() path, where the precomputed
venn-shape lookup is still expressed as ellipses.
Description
Promote a legacy 5-column ellipse data frame (h, k, a, b, phi) into the
wide $shapes schema. Used by the venn() path, where the precomputed
venn-shape lookup is still expressed as ellipses.
Usage
ellipse_frame_to_shapes(fpar, shape)
Error plot for euler objects
Description
This is a diagnostic tool for evaluating the fit from a call
to euler() visually. A color key is provided by default, which
represents the chosen error metric so that one can easily detect
which areas in the diagram to be skeptical about.
Usage
error_plot(
x,
type = c("regionError", "residuals"),
quantities = TRUE,
pal = NULL,
...
)
Arguments
x |
an object of class |
type |
error metric. |
quantities |
whether to draw the error metric on the plot |
pal |
color palette for the fills in the legend |
... |
arguments passed down to |
Details
Notice that this function is purely provided for diagnostic reasons
and does not come with the same kind of customization that
plot.euler() provides: the color legend can only be customized
in regards to its color palette and another key (instead of labels)
is completely turned off.
Value
Returns an object of class eulergram, which will be
plotted on the device in the same manner as objects from
plot.euler(). See plot.eulergram() for details.
See Also
plot.euler(), euler(),
plot.eulergram()
Examples
error_plot(euler(organisms), quantities = FALSE)
Area-proportional Euler diagrams
Description
Fit Euler diagrams (a generalization of Venn diagrams) using numerical optimization to find exact or approximate solutions to a specification of set relationships. The shape of the diagram may be a circle, an ellipse, an axis-aligned rectangle, or an axis-aligned square.
Usage
euler(combinations, ...)
## Default S3 method:
euler(
combinations,
input = c("disjoint", "union"),
shape = c("circle", "ellipse", "rectangle", "square"),
loss = c("sum_squared", "sum_absolute", "sum_absolute_region_error",
"sum_squared_region_error", "max_absolute", "max_squared", "root_mean_squared",
"stress", "diag_error"),
loss_aggregator = NULL,
complement = NULL,
control = list(),
...
)
## S3 method for class 'data.frame'
euler(
combinations,
weights = NULL,
by = NULL,
sep = "_",
factor_names = TRUE,
...
)
## S3 method for class 'matrix'
euler(combinations, ...)
## S3 method for class 'table'
euler(combinations, ...)
## S3 method for class 'list'
euler(combinations, ...)
Arguments
combinations |
set relationships as a named numeric vector, matrix, or data.frame (see methods (by class)) |
... |
arguments passed down to other methods |
input |
type of input: disjoint identities
( |
shape |
geometric shape used in the diagram |
loss |
type of loss to minimize over. The default,
|
loss_aggregator |
deprecated; use |
complement |
an optional single non-negative number giving the area
of the complement — that is, the universe outside every named set.
When supplied, the fitter jointly optimizes a containing rectangle
together with the diagram shapes so that the area of the rectangle
minus the union of (clipped) shapes matches |
control |
a list of control parameters.
|
weights |
a numeric vector of weights of the same length as
the number of rows in |
by |
a factor or character matrix to be used in |
sep |
a character to use to separate the dummy-coded factors if there are factor or character vectors in 'combinations'. |
factor_names |
whether to include factor names when constructing dummy codes |
Details
If the input is a matrix or data frame and argument by is specified,
the function returns a list of euler diagrams.
The function minimizes the residual sums of squares,
\sum_{i=1}^n (A_i - \omega_i)^2,
by default, where \omega_i the size of the ith disjoint subset, and
A_i the corresponding area in the diagram, that is, the unique
contribution to the total area from this overlap. The loss function
can, however, be controlled via the loss argument.
euler() also returns stress (from venneuler), as well as
diagError, and regionError from eulerAPE.
The stress statistic is computed as
\frac{\sum_{i=1}^n (A_i - \beta\omega_i)^2}{\sum_{i=1}^n A_i^2},
where
\beta = \sum_{i=1}^n A_i\omega_i / \sum_{i=1}^n \omega_i^2.
regionError is computed as
\left| \frac{A_i}{\sum_{i=1}^n A_i} - \frac{\omega_i}{\sum_{i=1}^n \omega_i}\right|.
diagError is simply the maximum of regionError.
Value
A list object of class 'euler' with the following parameters.
shapes |
a data frame of fitted shape parameters. One row per set
with a |
ellipses |
for |
original.values |
set relationships in the input |
fitted.values |
set relationships in the solution |
residuals |
residuals |
regionError |
the difference in percentage points between each disjoint subset in the input and the respective area in the output |
diagError |
the largest |
stress |
normalized residual sums of squares |
Methods (by class)
-
euler(default): a named numeric vector, with combinations separated by an ampersand, for instanceA&B = 10. Missing combinations are treated as being 0. -
euler(data.frame): adata.frameof logicals, binary integers, or factors. -
euler(matrix): a matrix that can be converted to a data.frame of logicals (as in the description above) viabase::as.data.frame.matrix(). -
euler(table): A table withmax(dim(x)) < 3. -
euler(list): a list of vectors, each vector giving the contents of that set (with no duplicates). Vectors in the list must be named.
References
Wilkinson L. Exact and Approximate Area-Proportional Circular Venn and Euler Diagrams. IEEE Transactions on Visualization and Computer Graphics (Internet). 2012 Feb (cited 2016 Apr 9);18(2):321-31. Available from: doi:10.1109/TVCG.2011.56
Micallef L, Rodgers P. eulerAPE: Drawing Area-Proportional 3-Venn Diagrams Using Ellipses. PLOS ONE (Internet). 2014 Jul (cited 2016 Dec 10);9(7):e101717. Available from: doi:10.1371/journal.pone.0101717
See Also
plot.euler(), print.euler(), eulerr_options(), venn()
Examples
# Fit a diagram with circles
combo <- c(A = 2, B = 2, C = 2, "A&B" = 1, "A&C" = 1, "B&C" = 1)
fit1 <- euler(combo)
# Investigate the fit
fit1
# Refit using ellipses instead
fit2 <- euler(combo, shape = "ellipse")
# Investigate the fit again (which is now exact)
fit2
# Plot it
plot(fit2)
# A set with no perfect solution
euler(c(
"a" = 3491, "b" = 3409, "c" = 3503,
"a&b" = 120, "a&c" = 114, "b&c" = 132,
"a&b&c" = 50
))
# Using grouping via the 'by' argument through the data.frame method
euler(fruits, by = list(sex, age))
# Using the matrix method
euler(organisms)
# Using weights
euler(organisms, weights = c(10, 20, 5, 4, 8, 9, 2))
# The table method
euler(pain, factor_names = FALSE)
# A euler diagram from a list of sample spaces (the list method)
euler(plants[c("erigenia", "solanum", "cynodon")])
Compute polygon geometry and label anchors for plotting a fitted Euler diagram, including the optional complement region inside a fitted container.
Description
Inputs are the fitted shape parameters for the non-empty sets only,
in the order eulerr stores them (x$shapes rows after dropping rows
with NA). The leading shape argument selects which per-set columns are
active: "circle"/"ellipse" consume (h, k, a, b, phi),
"rectangle" consumes (h, k, width, height), "square" consumes
(h, k, side). The remaining vectors must still be provided (NaN
padding is acceptable). When container_* are non-NULL they describe
the fitted universe-box rectangle; in that case the result also carries
the complement region geometry (the area inside the rectangle outside
every shape) and a label anchor for it. Eunoia's decompose_regions
emits this region under the empty Combination whenever the spec
carries a complement and a container is supplied.
Usage
euler_plot_data(
set_names,
shape,
h,
k,
a,
b,
phi,
width,
height,
side,
container_h,
container_k,
container_width,
container_height,
n_vertices,
label_precision
)
Compose Euler Diagrams
Description
Arrange two eulergram objects side-by-side or stacked, building up
multi-panel layouts with operator syntax. Compositions can be nested
arbitrarily, e.g. (p1 | p2) / p3.
Usage
## S3 method for class 'eulergram'
e1 | e2
## S3 method for class 'eulergram'
e1 / e2
Arguments
e1, e2 |
|
Details
| arranges the two plots horizontally; / stacks them vertically.
The result is itself an eulergram, so further composition chains
naturally.
The gap between adjacent plots is controlled by the
composition$spacing entry of eulerr_options(), which must be a
grid::unit() and defaults to grid::unit(1, "lines").
Because composition is binary and recursive, panels at different
nesting levels are not size-aligned. In (p1 | p2) / p3, p3 spans
the full bottom row while p1 and p2 split the top row equally.
Value
An eulergram containing the composed layout.
See Also
plot.euler(), eulerr_options()
Examples
p1 <- plot(euler(c(A = 1, B = 8, "A&B" = 1)))
p2 <- plot(euler(c(A = 1, C = 1, "A&C" = 1)))
p1 | p2
p1 / p2
p3 <- plot(euler(c(X = 3, Y = 2, "X&Y" = 1)))
(p1 | p2) / p3
Default options for eulerr
Description
Default options for eulerr
Usage
eulerr_default_options()
Value
default options for eulerr
Deprecated functions in package eulerr.
Description
The functions listed below are deprecated and will be defunct in
the near future. When possible, alternative functions with similar
functionality are also mentioned. Help pages for deprecated functions are
available at help("_deprecated").
Get or set global graphical parameters for eulerr
Description
This function provides a means to set default parameters for functions
in eulerr. Query eulerr_options() (without any
argument) to see all the available options and read more about
the plot-related ones in grid::gpar() and graphics::par().
Usage
eulerr_options(...)
Arguments
... |
objects to update the global graphical parameters for eulerr with. |
Details
Currently, the following items will be considered:
- pointsize
size in pts to be used as basis for fontsizes and some margin sizes in the resulting plot
#'
- fills
a list of items
fillandalpha- patterns
a list of items
type,angle,col,lwd, andalpha- edges
a list of items
col,alpha,lex,lwd, andlty- labels
a list of items
rot,col,alpha,fontsize,cex,fontfamily,fontface,lineheight, andfont- quantities
a list of items
type,template,format,total,rot,col,alpha,fontsize,cex,fontfamily,lineheight, andfont- annotations
a list of items
rot,col,alpha,fontsize,cex,fontfamily,lineheight,font, andlabels(a named character vector keyed by subset name). Used to add a third stacked text element per region below the quantity.- strips
col,alpha,fontsize,cex,fontfamily,lineheight, andfont- legend
arguments to
grid::legendGrob()as well ascol,alpha,fontsize,cex,symbol_size(symbol size multiplier, independent of text size; defaults tocexifNULL),fontfamily,lineheight, andfont- main
arguments to
grid::textGrob()- complement
a list of styling defaults for the container box and its complement label drawn when
euler()is called withcomplement =. Items:fill,alpha,col,lty,lwd,lex,fontsize,cex,font,fontfamily,lineheight. The defaultlty = 2draws the container with a dashed outline.- padding
a
grid::unit()giving the padding between various elements in plots fromplot.euler(), which you can change if you, for instance, want to increase spacing between labels, quantities, and percentages.- composition
a list controlling how
eulergramobjects are arranged when composed via|or/. Contains a singlespacingitem (agrid::unit()) that sets the gap between adjacent plots.
Value
This function gets or sets updates in the global environment
that are used in plot.euler().
See Also
plot.euler(), grid::gpar(), graphics::par()
Examples
eulerr_options(edges = list(col = "blue"), fontsize = 10)
eulerr_options(n_threads = 2)
Union the current xlim/ylim with the canvas bbox reported by
eunoia. Returns the (possibly widened) limits.
Description
slack pads the canvas bbox before the union (multiplicative,
centered on the bbox center). The setup-time bbox is sized for one
reference device; padding gives the draw-time placement headroom
when the user resizes the device smaller than that reference and
labels grow in native units accordingly. A slack of 1.4 absorbs
roughly a 30 % linear resize before exterior labels start to fall
outside the panel viewport.
Usage
expand_limits_with_canvas(limits, placements, slack = 1.4)
Find the EulerTags child of an EulerPanel, if any.
Description
Find the EulerTags child of an EulerPanel, if any.
Usage
find_eulertags(panel)
Fit an Euler diagram using the eunoia Rust library.
Description
Fit an Euler diagram using the eunoia Rust library.
Usage
fit_euler_diagram(
combo_names,
combo_values,
input,
shape,
loss,
extraopt_threshold,
tolerance,
max_sets,
complement,
seed
)
Fitted values of euler object
Description
Fitted values of euler object
Usage
## S3 method for class 'euler'
fitted(object, dense = FALSE, ...)
Arguments
object |
object of class |
dense |
if |
... |
ignored |
Value
A named numeric vector of fitted areas keyed by combination label
(set names joined by &).
Fruits
Description
A synthethic data set of preferences for fruits and their overlaps, generated only to be a showcase for the examples for this package.
Usage
fruits
Format
A data.frame with 100 observations of 5 variables:
- banana
whether the person likes bananas, a logical
- apple
whether the person likes apples, a logical
- orange
whether the person likes oranges, a logical
- sex
the sex of the person, a factor with levels 'male' and 'female'
- age
the age of the person, a factor with levels 'child' and 'adult'
Get the bounding box for a row-wise collection of fitted shapes.
Description
Dispatches on the shape kind. Ellipse/circle use the rotated-ellipse bounding-box formula; rectangle/square use width/height (or side) directly since both are axis-aligned in eunoia.
Usage
get_bounding_box(shapes, k = NULL, a = NULL, b = NULL, phi = NULL)
Arguments
shapes |
the |
k, a, b, phi |
legacy ellipse parameters; only used when |
Value
The bounding box as a list with xlim and ylim.
Check if object is strictly FALSE
Description
Check if object is strictly FALSE
Usage
is_false(x)
Arguments
x |
object to check |
Value
A logical.
Check if a vector is an integer
Description
Check if a vector is an integer
Usage
is_integer(x, tol = .Machine$double.eps^0.5)
Arguments
x |
a vector |
Value
TRUE of FALSE.
Check if vector is a real (numeric non-integer)
Description
Check if vector is a real (numeric non-integer)
Usage
is_real(x, tol = .Machine$double.eps^0.5)
Arguments
x |
Value
A logical.
Re-place tags at draw time so resizing the device doesn't clip labels.
Description
The panel viewport is active when makeContent fires, so we can
measure each tag's footprint in current native units via
grid::convertWidth(grobWidth(...), "native") and call eunoia's
place_euler_labels() again. On resize, grid invalidates the tree
and makeContent re-runs, so the placement tracks the current
device automatically.
Usage
## S3 method for class 'EulerTags'
makeContent(x)
Details
Tags whose measured size is zero (or whose anchor / kind eunoia
can't compute) keep the positions they were built with — typically
the setup-time placement stored on centers$x / centers$y.
Set the panel viewport's xscale/yscale at draw time.
Description
Fires before grid pushes the panel viewport. We can therefore
measure labels against the live cell, run eunoia's placement, and
compute a viewport bbox that fits both the diagram and the labels.
On window resize grid invalidates the gTree and makeContext
re-runs, so the panel grows or shrinks to track the current device
and exterior labels never extend past the viewport edge.
Usage
## S3 method for class 'EulerPanel'
makeContext(x)
Details
Aspect preservation: the new bbox keeps xrng / yrng equal to the
geometry's natural aspect (set by setup_geometry()) so that
circles render as circles. The smaller dimension is padded if the
label-driven canvas bbox is asymmetric.
Default number of sets that eunoia accepts before rejecting a spec.
Used by the R-side input validator so the cap is not hardcoded.
Description
Default number of sets that eunoia accepts before rejecting a spec.
Used by the R-side input validator so the cap is not hardcoded.
Usage
max_sets_default()
Absolute upper bound on the number of sets that eunoia can represent
in a single diagram. Used by the R-side input validator so the cap is
not hardcoded.
Description
Absolute upper bound on the number of sets that eunoia can represent
in a single diagram. Used by the R-side input validator so the cap is
not hardcoded.
Usage
max_sets_hard_cap()
Measure every drawable tag inside tags_grob against the current
viewport. Returns parallel vectors of combo / width / height suitable
for handing to place_euler_labels(), plus the resolved leader gap
in native units (so the FFI sees one number per draw pass).
Description
Measure every drawable tag inside tags_grob against the current
viewport. Returns parallel vectors of combo / width / height suitable
for handing to place_euler_labels(), plus the resolved leader gap
in native units (so the FFI sees one number per draw pass).
Usage
measure_all_tags(tags_grob, padding, gap = NULL)
Native-unit AABB of one composite tag (label stacked above quantity,
annotation stacked below quantity, separated by padding). The
geometry matches what setup_tag() renders at draw time, so the size
handed to eunoia agrees with the actual on-screen footprint.
Description
Native-unit AABB of one composite tag (label stacked above quantity,
annotation stacked below quantity, separated by padding). The
geometry matches what setup_tag() renders at draw time, so the size
handed to eunoia agrees with the actual on-screen footprint.
Usage
measure_tag(
label,
quantity,
annotation,
labels_par_id,
quantities_par_id,
annotations_par_id,
labels_gp,
quantities_gp,
annotations_gp,
padding_native
)
Measure one tag's combined AABB in the current viewport's native units.
Description
Measure one tag's combined AABB in the current viewport's native units.
Usage
measure_tag_native(tag, padding_native)
Measure all candidate tag sizes (regions + optional complement) inside
a fresh measurement viewport scaled to xlim/ylim.
Description
Measure all candidate tag sizes (regions + optional complement) inside
a fresh measurement viewport scaled to xlim/ylim.
Usage
measure_tag_sizes(
centers,
do_complement_label,
complement_label,
labels_gp,
quantities_gp,
annotations_gp,
padding,
gap,
xlim,
ylim
)
Blend (average) colors
Description
Blend (average) colors
Usage
mix_colors(rcol_in)
Arguments
rcol_in |
a vector of R colors |
Value
A single R color
Get the number of sets in he input
Description
Get the number of sets in he input
Usage
n_sets(combinations)
Arguments
combinations |
a vector of combinations (see |
Value
The number of sets in the input
Allocate a fresh $shapes data frame for n_all sets. Rows for empty
sets keep NA in every column so downstream plotting can detect them via
is.na(shapes$h) regardless of shape kind.
Description
Allocate a fresh $shapes data frame for n_all sets. Rows for empty
sets keep NA in every column so downstream plotting can detect them via
is.na(shapes$h) regardless of shape kind.
Usage
new_shape_frame(shape, n_all, row_names)
Open a temporary grid measurement device + viewport.
Description
Returns an idempotent closer thunk that pops the viewport and
closes the null PDF device. Used so we can call
grid::convertWidth(grobWidth(...), "native", ...) at setup time —
i.e. before plot.eulergram() ever opens a real device — to size
the label boxes that drive label placement.
Usage
open_measurement_viewport(xlim, ylim)
Details
Always opens its own off-screen PDF rather than reusing the caller's
active device. Pushing a viewport onto the caller's device adds an
entry to its display list, which knitr's plot capture
treats as visible change and emits as an extra blank plot before
the real plot.eulergram() draws. The off-screen PDF keeps
measurement entirely out of the user's display list.
Organisms
Description
Example data from the VennMaster package.
Usage
organisms
Format
A matrix with 7 observations, consisting of various organisms, and 5 variables: animal, mammal, plant, sea, and, spiny, indicating whether the organism belongs to the category or not.
Details
Note that this data is difficult to fit using an Euler diagram, even if we use ellipses, which is clear if one chooses to study the various overlaps in the resulting diagrams.
Source
https://github.com/sysbio-bioinf/VennMaster/blob/master/data_examples/deploy/example1.list
Pad an axis range by pt_pad points, converted to native units
against a measurement viewport with the supplied scale. Returns the
original range unchanged if the conversion isn't finite (e.g. zero
range, no device).
Description
Pad an axis range by pt_pad points, converted to native units
against a measurement viewport with the supplied scale. Returns the
original range unchanged if the conversion isn't finite (e.g. zero
range, no device).
Usage
pad_axis_native(
lim,
pt_pad,
axis = c("x", "y"),
layout_pos_row = NULL,
layout_pos_col = NULL
)
Pain distribution data
Description
Data from a study on pain distribution for patients with persistent neck pain in relation to a whiplash trauma.
Usage
pain
Format
A flat table (cross-table) with with sex in columns and pain distribution in rows and integer counts making up the cells of the table.
Disclaimer
Note that the maintainer of this package is an author of the source for this data.
Source
Westergren H, Larsson J, Freeman M, Carlsson A, Jöud A, Malmström E-M. Sex-based differences in pain distribution in a cohort of patients with persistent post-traumatic neck pain. Disability and Rehabilitation. 2017 Jan 27
Place per-region labels using eunoia's place_labels API.
Description
Inputs mirror euler_plot_data for shape geometry and add per-region
label sizes plus placement-strategy options. Returns, parallel to
label_combos:
Usage
place_euler_labels(
set_names,
shape,
h,
k,
a,
b,
phi,
width,
height,
side,
container_h,
container_k,
container_width,
container_height,
n_vertices,
label_combos,
label_widths,
label_heights,
placement,
placement_margin,
placement_iterations,
placement_min_gap,
placement_tether,
placement_leader_gap,
label_precision
)
Details
-
anchor_x/anchor_y— placed label anchor (NA on miss); -
kind— one of"interior","exterior_raycast","exterior_force_directed","exterior_elbow";""if no placement was produced; -
tether_x/tether_y— tether point for the leader line (NA for interior placements / misses). -
leader_end_x/leader_end_y— point on the label box AABB where the leader terminates (NA for interior placements / misses). -
leader_waypoints_x/leader_waypoints_y/leader_waypoints_lengths— concatenated waypoint coordinates and per-label counts. Empty for straight leaders; carries one knee point per elbow placement.
Plus a canvas bbox (canvas_bbox_h/k/width/height) from eunoia's
placements_bbox — NaN when no placements were produced — for the R
side to grow xlim/ylim so exterior labels are never clipped.
The complement region is requested with "" in label_combos; when
container_* are non-NULL the spec is built with .complement(1.0)
so eunoia emits the empty Combination from decompose_regions.
Plants
Description
Data on plants and the states in the US and Canada they occur in.
Usage
plants
Format
A list with 33,721 plants, each containing a character vector listing the states in the US and Canada in which they occur. The names in the list specify the species or genus of the plant.
Source
USDA, NRCS. 2008. The PLANTS Database, 31 December 2008). National Plant Data Center, Baton Rouge, LA 70874-4490 USA.
Dua, D. and Karra Taniskidou, E. (2017). UCI Machine Learning Repository http://archive.ics.uci.edu/ml/. Irvine, CA: University of California, School of Information and Computer Science.
Plot Euler and Venn diagrams
Description
Plot diagrams fit with euler() and venn() using grid::Grid() graphics.
This
function sets up all the necessary plot parameters and computes
the geometry of the diagram. plot.eulergram(), meanwhile,
does the actual plotting of the diagram. Please see the Details section
to learn about the individual settings for each argument.
Usage
## S3 method for class 'euler'
plot(
x,
fills = TRUE,
patterns = FALSE,
edges = TRUE,
legend = FALSE,
labels = identical(legend, FALSE),
quantities = FALSE,
annotations = NULL,
strips = NULL,
bg = FALSE,
main = NULL,
complement = TRUE,
rotate = 0,
n = 200L,
adjust_labels = TRUE,
...
)
## S3 method for class 'eulerr_venn'
plot(
x,
fills = TRUE,
patterns = FALSE,
edges = TRUE,
legend = FALSE,
labels = identical(legend, FALSE),
quantities = TRUE,
strips = NULL,
bg = FALSE,
main = NULL,
complement = TRUE,
n = 200L,
adjust_labels = TRUE,
...
)
## S3 method for class 'venn'
plot(...)
Arguments
x |
an object of class |
fills |
a logical, vector, or list of graphical parameters for the fills
in the diagram. Vectors are assumed to be colors for the fills.
See |
patterns |
a logical, vector, or list of graphical parameters for
fill patterns in the diagram. Vectors are assumed to be pattern types
(currently |
edges |
a logical, vector, or list of graphical parameters for the edges
in the diagram. Vectors are assumed to be colors for the edges.
See |
legend |
a logical scalar or list. If a list, the item |
labels |
a logical, vector, or list. Vectors are assumed to be
text for the labels. See |
quantities |
a logical, vector, or list. Vectors are assumed to be
text for the quantities' labels, which by
default are the original values in the input to |
annotations |
free-form per-region text rendered as a third
stacked element below the quantity (or below the label when no
quantity is drawn). Accepts a named character vector keyed by
subset name (e.g. |
strips |
a list, ignored unless the |
bg |
a logical, character, or list controlling the background grob. Character values are interpreted as the background fill color. |
main |
a title for the plot in the form of a
character, expression, list or something that can be
sensibly converted to a label via |
complement |
a logical, character, or list controlling the
container box and complement region for diagrams fit with
|
rotate |
a numeric value giving the angle in degrees by which to rotate
the entire diagram layout. Positive values rotate counter-clockwise.
Defaults to |
n |
number of vertices for the |
adjust_labels |
a logical. If |
... |
parameters to update |
Details
The only difference between plot.euler() and plot.venn() is that
quantities is set to TRUE by default in the latter and FALSE in
the former.
Most of the arguments to this function accept either a logical, a vector, or a list where
logical values set the attribute on or off,
vectors are shortcuts to commonly used options (see the individual parameters), and
lists enable fine-grained control, including graphical parameters as described in
grid::gpar()and control arguments that are specific to each argument.
The various grid::gpar() values that are available for each argument
are:
| fills | edges | labels | quantities | annotations | strips | legend | main | |
| col | x | x | x | x | x | x | x | |
| fill | x | |||||||
| alpha | x | x | x | x | x | x | x | x |
| lty | x | |||||||
| lwd | x | |||||||
| lex | x | |||||||
| fontsize | x | x | x | x | x | x | ||
| cex | x | x | x | x | x | x | ||
| fontfamily | x | x | x | x | x | x | ||
| lineheight | x | x | x | x | x | x | ||
| font | x | x | x | x | x | x |
Defaults for these values, as well as other parameters of the plots, can
be set globally using eulerr_options().
If the diagram has been fit using the data.frame or matrix methods
and using the by argument, the plot area will be split into panels for
each combination of the one to two factors. The fills, patterns, edges,
labels, quantities, and annotations arguments each accept an optional
by_group entry: a named list of override lists keyed by panel name (the
names of the fitted object). For multi-by fits the panel name is the
levels joined by ., e.g. "Male.German". Panels not listed in by_group
use the top-level settings unchanged. Only graphical fields (and rot for
labels, quantities, and annotations) may be overridden per panel;
structural fields such as quantities$type, quantities$format,
annotations$labels, or named-by-subset fills$fill must be set at the
top level.
For users who are looking to plot their diagram using another package, all the necessary parameters can be collected if the result of this function is assigned to a variable (rather than printed to screen).
Value
Provides an object of class 'eulergram' , which is a
description of the diagram to be drawn. plot.eulergram() does the actual
drawing of the diagram.
See Also
euler(), plot.eulergram(), grid::gpar(),
grid::grid.polyline(), grid::grid.path(),
grid::grid.legend(), grid::grid.text()
Examples
fit <- euler(c("A" = 10, "B" = 5, "A&B" = 3))
# Customize colors, remove borders, bump alpha, color labels white
plot(fit,
fills = list(fill = c("red", "steelblue4"), alpha = 0.5),
labels = list(col = "white", font = 4))
# Add quantities to the plot
plot(fit, quantities = TRUE)
# Add free-form per-region annotations below the counts
plot(
fit,
quantities = TRUE,
annotations = c(A = "mean = 35", "A&B" = "mean = 41")
)
# Add a custom legend and retain quantities
plot(fit, quantities = TRUE, legend = list(labels = c("foo", "bar")))
# Plot without fills and distinguish sets with border types instead
plot(fit, fills = "transparent", lty = 1:2)
# Save plot parameters to plot using some other method
diagram_description <- plot(fit)
# Plots using 'by' argument
plot(euler(fruits[, 1:4], by = list(sex)), legend = TRUE)
# Per-panel styling with `by_group`
plot(
venn(fruits[, 1:4], by = list(sex)),
quantities = list(
by_group = list(
male = list(col = "steelblue"),
female = list(col = "tomato")
)
)
)
Print (plot) Euler diagram
Description
This function is responsible for the actual drawing of
'eulergram' objects created through plot.euler(). print.eulergram()
is an alias for plot.eulergram(), which has been provided so that
plot.euler() gets called automatically.
Usage
## S3 method for class 'eulergram'
plot(x, newpage = TRUE, ...)
## S3 method for class 'eulergram'
print(x, ...)
Arguments
x |
an object of class |
newpage |
if |
... |
ignored |
Value
A plot is drawn on the current device using grid::Grid() graphics.
Clip a (possibly multi-polygon) subject path against a single clip
polygon. Mirrors the slice of polyclip::polyclip behavior eulerr
actually uses at the stripe-pattern site.
Description
Clip a (possibly multi-polygon) subject path against a single clip
polygon. Mirrors the slice of polyclip::polyclip behavior eulerr
actually uses at the stripe-pattern site.
Usage
polygon_clip_rust(subject_x, subject_y, subject_id_lengths, clip_x, clip_y, op)
Print a summary of an Euler diagram
Description
This function is responsible for printing fits from euler() and provides
a summary of the fit. Prints a data frame of the original set relationships
and the fitted values as well as diagError and stress statistics.
Usage
## S3 method for class 'euler'
print(x, round = 3, vsep = strrep("-", 0.75 * getOption("width")), ...)
Arguments
x |
|
round |
number of decimal places to round to |
vsep |
character string to paste in between |
... |
arguments passed to |
Value
Summary statistics of the fitted Euler diagram are printed to screen.
See Also
euler(), base::print.data.frame()
Examples
euler(organisms)
Print a summary of a Venn diagram
Description
This function is responsible for printing objects from
from venn() and provides a simple description of the number of
sets and the specifications for the ellipses of the Venn diagram.
Usage
## S3 method for class 'eulerr_venn'
print(x, round = 3, vsep = strrep("-", 0.75 * getOption("width")), ...)
## S3 method for class 'venn'
print(...)
Arguments
x |
an object of class |
round |
number of digits to round the ellipse specification to |
vsep |
character string to paste in between |
... |
arguments passed to |
Value
Summary statistics of the fitted Venn diagram are printed to screen.
See Also
venn(), base::print.data.frame()
Examples
venn(organisms)
Replace (refresh) a list
Description
Unlike update_list, this function only modifies, and does not add,
items in the list.
Usage
replace_list(old, new)
Arguments
old |
the original list |
new |
the things to update |
Value
A refreshed list.
Rescale values to new range
Description
Rescale values to new range
Usage
rescale(x, new_min, new_max)
Arguments
x |
numeric vector |
new_min |
new min |
new_max |
new max |
Value
Rescaled vector
Residuals of euler object
Description
Residuals of euler object
Usage
## S3 method for class 'euler'
residuals(object, dense = FALSE, ...)
Arguments
object |
object of class |
dense |
same meaning as in |
... |
ignored |
Value
A named numeric vector of residuals (input minus fit) keyed by combination label.
Resolve a gap option to a numeric in native units inside the current
measurement viewport. NULL → falls back to padding_native so the
visible leader-tip gap matches the spacing between label and quantity.
A grid::unit value converts to native; a bare numeric is interpreted
as lines (same convention as eulerr_options()$padding).
Description
Resolve a gap option to a numeric in native units inside the current
measurement viewport. NULL → falls back to padding_native so the
visible leader-tip gap matches the spacing between label and quantity.
A grid::unit value converts to native; a bare numeric is interpreted
as lines (same convention as eulerr_options()$padding).
Usage
resolve_gap_native(gap, padding_native)
Merge user-supplied placement options onto the defaults.
Description
Merge user-supplied placement options onto the defaults.
Usage
resolve_placement_opts(opts)
Single placement pass: measure tags, call the Rust FFI, return the placement records and the canvas bbox returned by eunoia.
Description
Single placement pass: measure tags, call the Rust FFI, return the placement records and the canvas bbox returned by eunoia.
Usage
run_placement_pass(
centers,
container_data,
shapes,
labels_gp,
quantities_gp,
annotations_gp,
padding,
placement_opts,
do_complement_label,
xlim,
ylim,
n_vertices,
label_precision
)
Setup the complement-count tag, in the same shape as a region tag so
it shares one makeContent.EulerTags() pass.
Description
Acts as a quantity-only tag with combo_key = "". The complement
label text comes either from complement$label (user override) or
from container_data$quantity_label (the fitted complement count).
Usage
setup_complement_tag(container_data, complement, number)
Compute geometries and label locations
Description
Compute geometries and label locations
Usage
setup_geometry(
x,
fills,
edges,
labels,
quantities,
annotations,
n,
merged_sets,
placement_opts = NULL,
do_complement_label = FALSE
)
Arguments
x |
an object of class 'euler' |
fills |
fills |
edges |
edges |
labels |
labels |
quantities |
quantities |
n |
number of vertices to use to render each ellipse |
merged_sets |
which sets have been merged? |
Value
a list object with slots for the various objects
Setup gpars
Description
Setup gpars
Usage
setup_gpar(default = list(), user = list(), n)
Arguments
default |
default values |
user |
user-inputted values |
n |
required number of items |
Value
a gpar object
Grobify Euler objects
Description
Grobify Euler objects
Usage
setup_grobs(
x,
fills,
patterns,
edges,
labels,
quantities,
annotations = NULL,
complement = NULL,
number,
merged_sets,
n_vertices = 200L,
placement_opts = NULL
)
Arguments
x |
geometry data |
fills |
fills params |
patterns |
pattern params |
edges |
edges params |
labels |
labels params |
quantities |
quantities params |
number |
current diagram number |
merged_sets |
sets that are the same and have been merged |
Value
A grid::gList() is returned.
Setup grobs for one tag (label + quantity + annotation + leader).
Description
Builds the gList via build_tag_grobs() and stashes the text / gpar
bundle on the resulting EulerTag gTree so makeContent.EulerTags()
can rebuild it at draw time with fresh measurements.
Usage
setup_tag(data, labels, quantities, annotations, number)
Per-shape bounding box dispatch. Reads the type tag on shapes (rows
are assumed to share a tag since a diagram fixes one shape kind), then
picks the appropriate width/height calculation. Falls back to the
rotated-ellipse formula when the type is unknown so external callers
constructing ad-hoc $shapes frames still get a sensible box.
Description
Per-shape bounding box dispatch. Reads the type tag on shapes (rows
are assumed to share a tag since a diagram fixes one shape kind), then
picks the appropriate width/height calculation. Falls back to the
rotated-ellipse formula when the type is unknown so external callers
constructing ad-hoc $shapes frames still get a sensible box.
Usage
shape_bounding_box(shapes)
Project the wide $shapes schema back into the legacy 5-column
(h, k, a, b, phi) ellipse data frame for circle/ellipse fits. Preserves
the row order and row names so back-compat consumers see exactly the
shape they used to.
Description
Project the wide $shapes schema back into the legacy 5-column
(h, k, a, b, phi) ellipse data frame for circle/ellipse fits. Preserves
the row order and row names so back-compat consumers see exactly the
shape they used to.
Usage
shapes_to_ellipse_frame(shapes)
Split a placement's flat leader_waypoints_x / _y / _lengths
return triple into a per-label list of list(x = ..., y = ...)
coordinate pairs. Each list element has length-lengths[i] x/y
vectors (often 0 — straight leaders carry no waypoints).
Description
Split a placement's flat leader_waypoints_x / _y / _lengths
return triple into a per-label list of list(x = ..., y = ...)
coordinate pairs. Each list element has length-lengths[i] x/y
vectors (often 0 — straight leaders carry no waypoints).
Usage
split_waypoints(placements)
Tally set relationships
Description
Tally set relationships
Usage
tally_combinations(sets, weights)
Arguments
sets |
a data.frame with set relationships and weights |
weights |
a numeric vector |
Value
Calls euler() after the set relationships have been coerced to a
named numeric vector.
Update list with input
Description
A wrapper for utils::modifyList() that attempts to coerce non-lists to
lists before updating.
Usage
update_list(old, new)
Arguments
old |
a list to be updated |
new |
stuff to update |
Value
Returns an updated list.
See Also
Venn diagrams
Description
This function fits Venn diagrams using an interface that is
almost identical to euler(). Strictly speaking,
Venn diagrams are Euler diagrams where every intersection is visible,
regardless of whether or not it is zero. In almost every incarnation of
Venn diagrams, however, the areas in the diagram are also
non-proportional to the input; this is also the case here.
Usage
venn(combinations, ...)
## Default S3 method:
venn(
combinations,
input = c("disjoint", "union"),
names = letters[length(combinations)],
...
)
## S3 method for class 'table'
venn(combinations, ...)
## S3 method for class 'data.frame'
venn(
combinations,
weights = NULL,
by = NULL,
sep = "_",
factor_names = TRUE,
...
)
## S3 method for class 'matrix'
venn(combinations, ...)
## S3 method for class 'list'
venn(combinations, ...)
Arguments
combinations |
set relationships as a named numeric vector, matrix, or data.frame (see methods (by class)) |
... |
arguments passed down to other methods |
input |
type of input: disjoint identities
( |
names |
a character vector for the names of each set of the same
length as 'combinations'. Must not be |
weights |
a numeric vector of weights of the same length as
the number of rows in |
by |
a factor or character matrix to be used in |
sep |
a character to use to separate the dummy-coded factors if there are factor or character vectors in 'combinations'. |
factor_names |
whether to include factor names when constructing dummy codes |
Value
Returns an object of class 'eulerr_venn', 'venn', 'euler' with items
shapes |
a data frame of the precomputed ellipse parameters (one
row per set, columns |
ellipses |
the legacy 5-column data frame
( |
original.values |
set relationships in the input |
fitted.values |
set relationships in the solution |
Methods (by class)
-
venn(default): a named numeric vector, with combinations separated by an ampersand, for instanceA&B = 10. Missing combinations are treated as being 0. -
venn(table): A table withmax(dim(x)) < 3. -
venn(data.frame): adata.frameof logicals, binary integers, or factors. -
venn(matrix): a matrix that can be converted to a data.frame of logicals (as in the description above) viabase::as.data.frame.matrix(). -
venn(list): a list of vectors, each vector giving the contents of that set (with no duplicates). Vectors in the list do not need to be named.
See Also
plot.eulerr_venn(), print.eulerr_venn(), euler()
Examples
# The trivial version
f1 <- venn(5, names = letters[1:5])
plot(f1)
# Using data (a numeric vector)
f2 <- venn(c(A = 1, "B&C" = 3, "A&D" = 0.3))
# The table method
venn(pain, factor_names = FALSE)
# Using grouping via the 'by' argument through the data.frame method
venn(fruits, by = list(sex, age))
# Using the matrix method
venn(organisms)
# Using weights
venn(organisms, weights = c(10, 20, 5, 4, 8, 9, 2))
# A venn diagram from a list of sample spaces (the list method)
venn(plants[c("erigenia", "solanum", "cynodon")])