changeText {svgtools}R Documentation

Change text of text elements

Description

Changes the text entry of XML element of type 'text'. The XML element may be found by its name (XML attribute 'id') or based on its current text entry.

Usage

changeText(
  svg,
  element_name,
  text,
  alignment = NULL,
  in_group = NULL,
  hide_blank = FALSE
)

Arguments

svg

XML document with SVG content

element_name

Name (attribute 'id') of text (XML element 'text') or current text entry of text (XML element 'text').

text

New text entry.

alignment

Character value for text alignment. Accepts 'start', 'middle', and 'end' (default NULL = no change).

in_group

Name (attribute 'id') of group (XML element 'g') that contains the text element (default NULL = no group, search the entire SVG).

hide_blank

Should text elements with empty strings be hidden (set attribute 'display' to 'none')? (default FALSE)

Value

XML document with SVG content

Examples

#read SVG file
fpath <- system.file("extdata", "fig1.svg", package="svgtools")
svg <- read_svg(file = fpath)

#change a text
svg <- changeText(svg = svg, element_name = "Category A", text = "low")
svg <- changeText(svg = svg, element_name = "Category B", text = "medium")
svg <- changeText(svg = svg, element_name = "Category C", text = "high")

[Package svgtools version 1.1.2 Index]