The SVG() function is the entry point for building an SVG from the ground up. We can provide predefined height and width attributes that define the canvas size for the SVG. From here, we would want to use functions that add elements to the SVG object (e.g., svg_rect(), svg_circle(), etc.) and thus progressively build the graphic.

SVG(
  width = NULL,
  height = NULL,
  viewbox = NULL,
  title = NULL,
  desc = NULL,
  incl_xmlns = FALSE,
  oneline = FALSE,
  anim_iterations = "infinite"
)

Arguments

width, height

The width and height attributes on the top-level <svg> element. Both of these attributes are optional but, if provided, take in a variety of dimensions and keywords. If numerical values are solely used, they are assumed to be 'px' length values. Dimensions can be percentage values (i.e., "75%") or length values with the following units: "em", "ex", "px", "in", "cm", "mm", "pt", and "pc". Using NULL, the default, excludes the attribute.

viewbox

An optional set of dimensions that defines the SVG viewBox attribute. The viewBox for an SVG element is the position and dimension, in user space, of an SVG viewport. If supplied, this could either be in the form of a four-element, numeric vector corresponding to the "min-x", "min-y", "width", and "height" of the rectangle, or, as TRUE which uses the vector c(0, 0, width, height). Using NULL, the default, excludes this attribute.

title

The <title> tag for the finalized SVG.

desc

The <desc> tag for the finalized SVG.

incl_xmlns

Should the xmlns attribute be included in the <svg> tag? This attribute is only required on the outermost svg element of SVG documents, and, it's unnecessary for inner svg elements or inside of HTML documents. By default, this is set to FALSE.

oneline

An option to compress the resulting SVG tags such that they are reduced to one line.

anim_iterations

How many should an SVG animation (if defined by use of the anims() function) be played? By default this is "infinite" (i.e., looped indefinitely) but we can specify the animation iteration count as a positive number.

Examples

# Create an SVG with nothing drawn # within it svg <- SVG(width = 200, height = 100) # Add a rectangle and then a circle svg <- svg %>% svg_rect(x = 20, y = 20, width = 40, height = 40) %>% svg_circle(x = 100, y = 40, diameter = 40)