The svg_path() function adds a path to an svg object. A path can potentially be quite complex (with an interplay of line and curve commands), so, a hand-encoded path string is not often done by hand. For this reason, the path argument accepts only a formatted string that complies with the input requirements for the d attribute of the SVG <path> tag. All point positions are in units of px.

svg_path(
  svg,
  path,
  stroke = NULL,
  stroke_width = NULL,
  fill = NULL,
  opacity = NULL,
  attrs = list(),
  anims = list(),
  filters = list(),
  id = NULL
)

Arguments

svg

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

path

A single-length character vector that holds the formatted path string.

stroke

The color of the stroke applied to the element (i.e., the outline).

stroke_width

The width of the stroke in units of pixels.

fill

The fill color of the element.

opacity

The opacity of the element. Must be a value in the range of 0 to 1.

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 a single # path element svg <- SVG(width = 300, height = 300) %>% svg_path( path = "M 50 160 q 100 -300 200 0", stroke = "magenta", stroke_width = 5, fill = "lightblue" )