changeText: Change text of text elements

Description Usage Arguments Value Examples

View source: R/svgtools.R

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

1
2
3
4
5
6
7
8
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

1
2
3
4
5
6
7
8
#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")

Example output



svgtools documentation built on Dec. 14, 2021, 5:10 p.m.