The svg_text() function adds text to an svg object. As with many of the functions that create shape elements (such as svg_rect()), the starting position is defined by x and y values. All point positions are in units of px.

svg_text(
  svg,
  x,
  y,
  text,
  fill = NULL,
  opacity = NULL,
  path = NULL,
  attrs = list(),
  anims = list(),
  filters = list(),
  id = NULL
)

Arguments

svg

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

x, y

The x and y positions of the upper left of the text to be drawn. The x and y values are relative to upper left of the SVG drawing area itself.

text

A character vector that contains the text to be rendered.

fill

The color of the text.

opacity

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

path

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

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 # text element svg <- SVG(width = 300, height = 300) %>% svg_text( x = 10, y = 20, text = "A line of text" )