svg.lines {svgViewR} | R Documentation |
Add Connected Line Segments to SVG Viewer
Description
A function taking coordinates given in various ways and joining the corresponding points with line segments in an SVG Viewer.
Usage
svg.lines(x, y=NULL, col="black", z.index=0, layer="", name="line", label="",
lwd=1, opacity=1, seg=1, ontop=FALSE, file=NULL)
Arguments
x |
A vector, matrix or array of 2D or 3D coordinates to be joined by a line or lines. Coordinates input as an array will be animated. |
y |
If |
col |
The color of the line(s). |
z.index |
A number indicating the relative order in which the SVG object will be drawn in the viewer. Higher numbers correspond to closer to the front or top. |
layer |
A text string indicating the layer in which the SVG object belongs (not yet fully implemented). |
name |
The name of the drawn object. |
label |
A label to be added to the SVG object in SVG tag. |
lwd |
The thickness of the line(s). |
opacity |
A number between |
seg |
The number of segments to use in drawing the line. |
ontop |
Whether the line should appear on top of all other objects in the viewer (to manually set order in cases of incorrect ordering due to partial opacities). |
file |
File path (having the extenstion ".html") to add lines to a current SVG Viewer file. By default (i.e. |
Details
This function accepts input similar to the native plot function lines()
. If x
and y
are vectors, they are combined into a matrix using cbind()
. If x
is a matrix, this matrix is used directly. Lines are then drawn between points indicated by consecutive rows. So for a 2-row matrix one line would be drawn, for a 3-row matrix two lines would be drawn, etc.
If x
is an array, the array is interpreted as a series of matrices, each representing a state of the line or line(s) in an animation of length dim(x)[3]
. Each of the dim(x)[3]
matrices is used to draw each state in a manner identical to when x
is a matrix.
The graphical parameters col
, z.index
, layer
, label
, lwd
, and opacity
can all be vectors of length one or of the same length as the number of lines to be drawn (see Examples). This allows different parameters to be specified for each line or for different animation states, depending on the number of graphical parameters specified.
Value
NULL
Author(s)
Aaron Olsen
See Also
svg.new
,
svg.pathsC
,
svg.points
Examples
## Not run:
## Create static and animated lines
# Create new viewer
svg.new(file='svgviewr.html', animate.duration=1)
# Plot 3 connected lines with 3 different colors
svg.lines(x=rbind(c(30,-20,0), c(30,-30,0), c(40,-30,0), c(40,-35,0)),
col=c("red", "green", "blue"), lwd=5, opacity=0.7)
# Plot single line that switches among 3 colors
svg.lines(x=rbind(c(15,0,0), c(15,-20,0)), col=c("red", "green", "blue"), lwd=3, opacity=0.7)
# Create a line in two animation states
arr <- array(c(rbind(c(15,-30,0), c(15,-50,0)), rbind(c(10,-30,0), c(10,-50,0))), dim=c(2,3,2))
# Plot
svg.lines(x=arr, col=c("red", "green"), lwd=3, opacity=0.7)
# Create two connected lines in 3 animation states
arr <- array(c(30,30,40, -40,-50,-50, 0,0,0, 40,40,50, -40,-50,-50,
0,0,0, 50,50,60, -40,-50,-50, 0,0,0), dim=c(3,3,3))
# Plot
svg.lines(x=arr, col=c("red", "green"), lwd=5, opacity=0.7)
# Close connection
svg.close()
# Open svgviewr.html to visualize
## End(Not run)