scatterSymbols: Adjust symbols of a scatter plot

Description Usage Arguments Details Value Examples

View source: R/svgtools.R

Description

Adjusts the horizontal (XML attributes 'x', 'x1', 'x2', 'cx' etc.) and vertical (XML attributes 'y', 'y1', 'y2', 'cy' etc.) positions of symbols (see details). Positions are calculated relative to a given frame (XML element of type 'rect') and the position of a data value within the minimum and maximum of two given scales for x- and y-axis. This process is called scaling.
In preparation, it is necessary to name a group (set attribute 'id' of XML element of type 'g') of symbols. Symbols are automatically duplicated or removed to match the amount of data values.

Usage

1
2
3
4
5
6
7
8
9
scatterSymbols(
  svg,
  frame_name,
  group_name,
  scale_real_x,
  scale_real_y,
  values,
  symbol_type
)

Arguments

svg

XML document with SVG content

frame_name

Name (attribute 'id') of frame (XML element 'rect') for positioning of elements.

group_name

Name (attribute 'id') of group (XML element 'g') with symbols.

scale_real_x

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

scale_real_y

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

values

Dataframe or matrix with numeric vectors. First column corresponds to x-axis. Second column corresponds to y-axis.

symbol_type

Character value. Accepts 'circle', 'rect', 'polygon', 'linegroup', 'path', or 'guess' for guessing of type; see details.

Details

Symbols may be prepared in the SVG file in any amount. But be aware that the function will simply duplicate the first one (in the group) or remove the last ones to match the amount of data values. When, for example, you need to have different colors for different subgroups of cases, prepare several groups of symbols and call this function for each of them.
The function currently supports the following symbol_types:

Value

XML document with SVG content

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#read SVG file
fpath <- system.file("extdata", "fig13.svg", package="svgtools")
svg <- read_svg(file = fpath)

#scatter symbols
set.seed(12345)
df <- data.frame(g=rep(1:4,10), x=rnorm(40,500,75), y=rnorm(40,500,75))
df[df$g==1,]$x <- df[df$g==1,]$x-35
df[df$g==2,]$y <- df[df$g==2,]$y-35
df[df$g==3,]$x <- df[df$g==3,]$x+35
df[df$g==4,]$y <- df[df$g==4,]$y+35
svg <- scatterSymbols(svg = svg, frame_name = "frame", group_name = "gA", 
                      scale_real_x = c(250,750), scale_real_y = c(250,750), 
                      values = df[df$g==1,2:3], symbol_type = "rect")
svg <- scatterSymbols(svg = svg, frame_name = "frame", group_name = "gB", 
                      scale_real_x = c(250,750), scale_real_y = c(250,750), 
                      values = df[df$g==2,2:3], symbol_type = "circle")
svg <- scatterSymbols(svg = svg, frame_name = "frame", group_name = "gC", 
                      scale_real_x = c(250,750), scale_real_y = c(250,750), 
                      values = df[df$g==3,2:3], symbol_type = "polygon")
svg <- scatterSymbols(svg = svg, frame_name = "frame", group_name = "gD", 
                      scale_real_x = c(250,750), scale_real_y = c(250,750), 
                      values = df[df$g==4,2:3], symbol_type = "linegroup")

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