The svg_group() function allows for grouping of several SVG elements. This is useful if we'd like to pass presentation attributes to several elements at once.

svg_group(
  svg,
  ...,
  .list = list2(...),
  attrs = list(),
  anims = list(),
  filters = list(),
  id = NULL
)

Arguments

svg

The svg object that is created using the SVG() function.

...

a collection of named arguments that consist of presentation attributes (e.g., stroke = "blue") and formulas that represent elements (e.g, ~ svg_rect(., x = 60, y = 60, width = 50, height = 50)).

.list

Allows for the use of a list as an input alternative to ....

attrs

A presentation attribute list. The helper function svg_attrs_pres() can help us easily generate this named list object. For the most part, the list's names are the presentation attribute names and the corresponding values are the matching attribute values.

anims

An animation directive list for the element. This should be structured using the anims() function.

filters

A filter directive list for the element. This is easily created by using a list of filter_*() functions (e.g., list(filter_gaussian_blur(2), filter_drop_shadow(2, 2))).

id

An optional ID value to give to the built tag. This is useful for modifying this element in a later function call or for interacting with CSS.

Examples

# Create an SVG with two rectangles # contained within a group SVG(width = 300, height = 300) %>% svg_group( fill = "steelblue", stroke = "red", opacity = 0.5, ~ svg_rect(., x = 20, y = 20, width = 50, height = 50), ~ svg_rect(., x = 40, y = 40, width = 50, height = 50, fill = "red") )
#> <svg width="300" height="300"> #> <g fill="steelblue" stroke="red" opacity="0.5"> #> <rect x="20" y="20" width="50" height="50"/> #> <rect x="40" y="40" width="50" height="50" fill="red"/> #> </g> #> </svg>
# Create an SVG with two rectangles # that are nested within two # different groups SVG(width = 300, height = 300) %>% svg_group( fill = "green", stroke = "red", ~ svg_rect(., x = 30, y = 30, width = 40, height = 50), ~ svg_group(., fill = "steelblue", opacity = 0.5, ~ svg_rect(., x = 60, y = 60, width = 50, height = 50) ) )
#> <svg width="300" height="300"> #> <g fill="green" stroke="red"> #> <rect x="30" y="30" width="40" height="50"/> #> <g fill="steelblue" opacity="0.5"> #> <rect x="60" y="60" width="50" height="50"/> #> </g> #> </g> #> </svg>