diffBar {svgtools}R Documentation

Adjust bar chart where bars lie to the left/right or bottom/top of a given nullvalue

Description

Adjusts the horizontal (XML attribute 'x') or vertical (XML attribute 'y') position as well as width/height of bar segments (XML elements of type 'rect') and optionally value labels (XML elements of type 'text'). Positions are calculated relative to a given frame (XML element of type 'rect'), a nullvalue and the position of a data value within the minimum and maximum of a given scale. Bar segments and, optionally, value labels with values lower than the nullvalue are positioned to the left (in horizontal alignment) or to the bottom (in vertical alignment) of the scaled nullvalue, higher values on the opposite side.
For further description see stackedBar.

Usage

diffBar(
  svg,
  frame_name,
  group_name,
  scale_real,
  values,
  nullvalue = 0,
  alignment = "horizontal",
  has_labels = TRUE,
  label_position = "center",
  decimals = 0,
  display_limits = c(0, 0)
)

Arguments

svg

XML document with SVG content

frame_name

Name (attribute 'id') of frame (XML element 'rect') for positioning bar segments (and value labels).

group_name

Name (attribute 'id') of group (XML element 'g') containing either bar segments (and value labels) or further groups, containing bar segments (and value labels) themselves.

scale_real

Numeric vector (e.g. c(0,100)) of arbitrary length. Only minimum and maximum are used for scaling of values.

values

Either a numeric vector, a numeric matrix or a dataframe with only numeric columns.
If a vector is given, it corresponds to one bar (group of bar segments and, optionally, value labels).
If a matrix or dataframe is given, rows define the value set for several (stacked) bars grouped together.

nullvalue

Value that defines the "center" of the bar segments (for left/right or bottom/top positioning)

alignment

Character value. Accepts 'horizontal' (default) or 'vertical'. See details.

has_labels

Are there value labels (of XML type 'text') to adjust? (default TRUE)

label_position

Character value. Accepts 'start', 'center' (default) and 'end'. This refers to the underlying bar segments.

decimals

Integer value defining the number of decimal digits of value labels (default 0). It is possible to set the rounding of the labels to rounding away from zero by options("svgtools.roundAwayFromZero" = TRUE).

display_limits

Interval for (small) values, that lead to suppression of the corresponding value labels. If only one value x is given, it is turned into the interval c(-x,x). (default 0 = no suppression)

Details

See stackedBar.

Value

XML document with SVG content

Examples

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

#adjust bars
df <- data.frame(diff_negative = c(NA,NA,-0.7,NA,-0.33), 
                 diff_positive = c(0.4,0.55,NA,0.02,NA))
svg <- diffBar(svg = svg, frame_name = "frame", group_name = "group", 
               scale_real = c(-1,1), values = df, nullvalue = 0, 
               label_position = "end", decimals = 1, display_limits = 0.1)

[Package svgtools version 1.1.2 Index]