| Title: | Standard and 'rgl' Plots with Legends |
|---|---|
| Description: | Provides tools to combine standard R plots or 'rgl' 3D plots with a legend. Facilitates the creation of composite figures that mix 2D or 3D visualizations with a categorical or continuous legend. |
| Authors: | Ruben Fernandez-Casal [aut, cre] (ORCID: <https://orcid.org/0000-0002-5785-3739>) |
| Maintainer: | Ruben Fernandez-Casal <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.4-1 |
| Built: | 2026-09-22 12:01:32 UTC |
| Source: | https://github.com/rubenfcasal/legendplot |
This package provides tools to combine standard R plots or 'rgl' 3D plots with a legend, facilitating the creation of composite figures that mix 2D or 3D visualizations with a categorical or continuous legend. For more information visit https://rubenfcasal.github.io/legendplot/articles/legendplot.html.
Maintainer: Ruben Fernandez-Casal [email protected] (ORCID)
Authors:
Ruben Fernandez-Casal [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/rubenfcasal/legendplot/issues/
Modification of rgl::axis3d() that adds three extra parameters,
ticksize, labeldist and tickangle, to independently control the
length of the axis tick marks, the distance between those tick marks and
their labels, and the direction (within the plane orthogonal to the axis)
in which both the tick marks and the labels are offset (see Details).
Based on the solution proposed on Stack Overflow (see References).
axis3( edge, at = NULL, labels = TRUE, tick = TRUE, line = TRUE, pos = NULL, nticks = 5, ticksize = 0.05, tickangle = 45, labeldist = 3, ... )axis3( edge, at = NULL, labels = TRUE, tick = TRUE, line = TRUE, pos = NULL, nticks = 5, ticksize = 0.05, tickangle = 45, labeldist = 3, ... )
edge |
character string indicating the edge of the bounding box on
which the axis is drawn (same format as in |
at |
positions at which the tick marks are drawn; if |
labels |
tick labels: logical, indicating whether to automatically label the axes or be omitted, or a vector of labels. |
tick |
logical; if |
line |
logical; if |
pos |
optional position of the axis (see |
nticks |
approximate number of tick marks when |
ticksize |
length of the tick marks, as a fraction of the distance to the center of the scene's range. |
tickangle |
direction, in degrees, of the tick marks and labels
within the plane orthogonal to the axis (e.g. |
labeldist |
distance between the tick marks and the labels, as a
multiple of |
... |
additional arguments passed to |
By default (tickangle = 45), tick marks and labels are offset
simultaneously along both coordinates perpendicular to the axis, towards
the corresponding corner of the bounding box.
The original behavior of axis3d() can be reproduced by setting
tickangle = 45 and ticksize = 0.05 * sqrt(2) (the actual relative
length of the tick marks).
An rglId object (see rgl::lowlevel()) with the identifiers of the
rgl elements added (line, tick marks and labels).
Dominic Woolf (2013, Mar 23). R rgl distance between axis ticks and tick labels, Stack Overflow, https://stackoverflow.com/a/39299740/4303451.
splot3d(), fplot3d(), rgl::axis3d()
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one set.seed(1) points3d(rnorm(100), rnorm(100), rnorm(100)) box3d() # Draw several z axis at z+- and z--, with longer tick marks and # labels closer to them than usual axis3('z+-', ticksize = 0.5, labeldist = 1) axis3('z+-', ticksize = 0.5, labeldist = 1, tickangle = 0) axis3('z--', ticksize = 0.5, labeldist = 1, tickangle = 90)library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one set.seed(1) points3d(rnorm(100), rnorm(100), rnorm(100)) box3d() # Draw several z axis at z+- and z--, with longer tick marks and # labels closer to them than usual axis3('z+-', ticksize = 0.5, labeldist = 1) axis3('z+-', ticksize = 0.5, labeldist = 1, tickangle = 0) axis3('z--', ticksize = 0.5, labeldist = 1, tickangle = 90)
hcld.colors() and hot.colors() create a color table useful for
coding qualitative information and fcolor() assigns colors to categorical
(factor) values.
fcolor(f, col = hcld.colors(length(labels)), labels = levels(as.factor(f))) hcld.colors(n, palette = "Dark 3", ...) cat.colors(n)fcolor(f, col = hcld.colors(length(labels)), labels = levels(as.factor(f))) hcld.colors(n, palette = "Dark 3", ...) cat.colors(n)
f |
(factor, or vector coercible to factor) values to be converted to colors. |
col |
colors for each level. Defaults to |
labels |
levels to use. Defaults to |
n |
number of colors ( |
palette |
a valid palette name for |
... |
additional arguments passed to |
fcolor() returns vector of colors, one per element of f.
hcld.colors() and cat.colors() return a character vector of colors (similar to
hcl.colors() or rainbow(); see rgb()).
jet.colors and hot.colors create a color table useful for contiguous
color scales and scolor assigns colors to a numerical vector.
scolor(s, col = jet.colors(128), slim = range(s, finite = TRUE)) jet.colors(n) hot.colors(n, rev = TRUE)scolor(s, col = jet.colors(128), slim = range(s, finite = TRUE)) jet.colors(n) hot.colors(n, rev = TRUE)
s |
values to be converted to the color scale. |
col |
color table used to set up the color scale (see |
slim |
limits used to set up the color scale. |
n |
number of colors ( |
rev |
logical; if |
scolor converts a real valued vector to a color scale. The range
slim is divided into length(col) + 1 pieces of equal length.
Values which fall outside the range of the scale are coded as NA.
jet.colors generates a rainbow style color table similar to the MATLAB (TM)
jet color scheme. It may be appropriate to distinguish between values above and
below a central value (e.g. between positive and negative values).
hot.colors generates a color table similar to the MATLAB (TM)
hot color scheme (reversed by default). It may be appropriate to represent values
ranging from 0 to some maximum level (e.g. density estimation).
The default value rev = TRUE may be adequate to grayscale conversion.
scolor, jet.colors and hot.colors return a character
vector of colors.
heat.colors, terrain.colors, rgb.
fplot() is designed to combine a standard R plot with a categorical (factor) legend.
Analogous to splot(), splits the plotting region into a main panel and a
legend panel, and uses legend() to draw the labels with their colors and symbols.
fplot( labels, col = hcld.colors(length(labels)), type = c("box", "point", "line"), pch = 16, lty = 1, lwd = 2, cex = 1, border = col, pt.cex = cex * 1.5, seg.len = 1.5, horizontal = FALSE, legend.shrink = 1, legend.width = NULL, legend.mar = NULL, legend.lab = NULL, legend.x = "center", bigplot = NULL, smallplot = NULL, add = FALSE, ... )fplot( labels, col = hcld.colors(length(labels)), type = c("box", "point", "line"), pch = 16, lty = 1, lwd = 2, cex = 1, border = col, pt.cex = cex * 1.5, seg.len = 1.5, horizontal = FALSE, legend.shrink = 1, legend.width = NULL, legend.mar = NULL, legend.lab = NULL, legend.x = "center", bigplot = NULL, smallplot = NULL, add = FALSE, ... )
labels |
vector with the category labels. |
col |
colors associated with each level (same order as |
type |
type of symbols shown in the legend: |
pch |
plotting ‘character’ (symbol) used when |
lty, lwd
|
line types and widths for lines appearing in the legend,
when |
cex |
text/symbol size in the legend. |
border, pt.cex, seg.len
|
additional |
horizontal |
logical; if |
legend.shrink |
amount to shrink the size of legend relative to the full height or width of the plot. |
legend.width, legend.mar
|
control the size and margin of the legend
panel, as in |
legend.lab |
legend title. |
legend.x |
legend location relative to the legend panel (argument |
bigplot, smallplot
|
plot coordinates for main and legend panels. If not passed these will be determined within the function. |
add |
logical; if |
... |
additional arguments passed to |
fplot() invisibly returns a list with components: bigplot,
smallplot, old.par, col and labels (par(old.par) will reset plot
parameters to the values before entering the function).
The plotting region (par("plt")) may be changed
after exiting, to make it possible to add more features to the plot.
They can be restored using the old.par returned values or by calling
function par.reset().
legend(), fcolor(), hcld.colors(), cat.colors(), fpoints().
# Plot equivalent to fpoints(): f <- as.factor(mtcars$cyl) res <- fplot(levels(f), col = cat.colors(f), type = "point", legend.lab = "cyl") with(mtcars, plot(hp, qsec, col = fcolor(f, col = res$col), pch = 16, cex = 1.5, main = "Motor Trend Car Road Tests") ) par(res$old.par) # restore graphical parameters# Plot equivalent to fpoints(): f <- as.factor(mtcars$cyl) res <- fplot(levels(f), col = cat.colors(f), type = "point", legend.lab = "cyl") with(mtcars, plot(hp, qsec, col = fcolor(f, col = res$col), pch = 16, cex = 1.5, main = "Motor Trend Car Road Tests") ) par(res$old.par) # restore graphical parameters
Splits the active rgl device into two subscenes (the main plot and a legend) and draws, in the legend subscene, a colored categorical legend together with its corresponding labels.
fplot3d( labels, col = hcld.colors(length(labels)), type = c("s", "c", "p", "l"), legend.zoom = 0.6, legend.width = 0.2, legend.size = 4, legend.dim = 0.2, legend.lab = NULL, lab.dist = 2.5, lab.rev = FALSE, ... )fplot3d( labels, col = hcld.colors(length(labels)), type = c("s", "c", "p", "l"), legend.zoom = 0.6, legend.width = 0.2, legend.size = 4, legend.dim = 0.2, legend.lab = NULL, lab.dist = 2.5, lab.rev = FALSE, ... )
labels |
vector with the legend labels (levels/categories).
Defaults to |
col |
vector of colors associated with each label (defaults to
|
type |
character; symbol/object used to represent each label in the
legend: |
legend.zoom |
zoom factor applied to the legend subscene/panel. |
legend.width |
relative size of the legend symbols (spheres, cubes or line segments), as a fraction of the corresponding dimension of the legend subscene. |
legend.size |
point size, if |
legend.dim |
relative dimension of the legend panel, as a fraction of the full width (or height) of the device. |
legend.lab |
legend title. |
lab.dist |
distance between the legend symbols and their text
labels, as a multiple of the symbol size ( |
lab.rev |
logical; if |
... |
material properties (see |
Mouse rotation is disabled in the legend subscene.
Furthermore, since rgl::layout3d(..., mouseMode = "replace") does not
copy the user's mouse handlers (which are therefore disabled), the first one
is set up for trackball with double click to reset view (via dbltrack3d()),
and the second one (if any) for panning (via pan3d()).
Invisibly returns the identifiers of the created subscenes (see
rgl::layout3d()).
fpoints3d(), fshade3d(), splot3d().
library(rgl) open3d() # Plot equivalent to fpoints(): f <- as.factor(mtcars$cyl) fplot3d(levels(f), legend.lab = "cyl") with( mtcars, plot3d(hp, qsec, mpg, type = "s", col = fcolor(f))) # Using cubes instead of spheres in the legend fplot3d(levels(f), legend.lab = "cyl", type = "c") with( mtcars, plot3d(hp, qsec, mpg, type = "p", col = fcolor(f)))library(rgl) open3d() # Plot equivalent to fpoints(): f <- as.factor(mtcars$cyl) fplot3d(levels(f), legend.lab = "cyl") with( mtcars, plot3d(hp, qsec, mpg, type = "s", col = fcolor(f))) # Using cubes instead of spheres in the legend fplot3d(levels(f), legend.lab = "cyl", type = "c") with( mtcars, plot3d(hp, qsec, mpg, type = "p", col = fcolor(f)))
A generic function that, by default, draws a scatter plot with
points colored according to a factor f and (optionally) adds a categorical
legend (fpoints.default() calls fplot() and plot.default(), or
plot.xy() if add = TRUE).
fpoints(x, ...) ## Default S3 method: fpoints( x, y = NULL, f, col = hcld.colors(f), type = "p", cex = 1.5, pch = 16, legend = TRUE, legend.type = c("point", "box", "line"), legend.pch = pch, legend.cex = 1, legend.lty = 1, legend.lwd = 2, border = col, pt.cex = cex, seg.len = 1.5, horizontal = FALSE, legend.shrink = 1, legend.width = NULL, legend.mar = NULL, legend.lab = NULL, legend.x = "center", bigplot = NULL, smallplot = NULL, add = FALSE, reset = TRUE, xlab = NULL, ylab = NULL, asp = NA, ... )fpoints(x, ...) ## Default S3 method: fpoints( x, y = NULL, f, col = hcld.colors(f), type = "p", cex = 1.5, pch = 16, legend = TRUE, legend.type = c("point", "box", "line"), legend.pch = pch, legend.cex = 1, legend.lty = 1, legend.lwd = 2, border = col, pt.cex = cex, seg.len = 1.5, horizontal = FALSE, legend.shrink = 1, legend.width = NULL, legend.mar = NULL, legend.lab = NULL, legend.x = "center", bigplot = NULL, smallplot = NULL, add = FALSE, reset = TRUE, xlab = NULL, ylab = NULL, asp = NA, ... )
x |
object used to select a method. In the default method, it provides the |
... |
additional graphical parameters (to be passed to the main plot function
or to |
y |
y coordinates. Alternatively, a single argument |
f |
(factor, or vector coercible to factor), with length equal to the number of points, giving the group of each point. |
col |
colors associated with each level of |
type |
character indicating the type of plotting; actually any of the
types as in |
cex |
numerical vector giving the amount by which plotting characters
and symbols should be scaled relative to the default. This works as a multiple
of |
pch |
vector of plotting characters or symbols: see |
legend |
logical; if |
legend.type |
type of symbols shown in the legend: |
legend.pch, legend.cex
|
plotting character and size used in the legend
when |
legend.lty, legend.lwd
|
line type and width used in the legend
when |
border, pt.cex, seg.len
|
additional |
horizontal |
logical; if |
legend.shrink |
amount to shrink the size of legend relative to the full height or width of the plot. |
legend.width |
width in characters of the legend strip. Default is 1.2, a little bigger that the width of a character. |
legend.mar |
width in characters of legend margin that has the axis. Default is 5.1 for a vertical legend and 3.1 for a horizontal legend. |
legend.lab |
label for the axis of the color legend, defaults to a
description of |
legend.x |
legend location relative to the legend panel (argument |
bigplot |
plot coordinates for main plot. If not passed, and |
smallplot |
plot coordinates for legend strip. If not passed, and |
add |
logical; if |
reset |
logical; if |
xlab |
label for the x axis, defaults to a description of |
ylab |
label for the y axis, defaults to a description of |
asp |
the y/x aspect ratio, see |
fplot() invisibly returns a list with components: bigplot, smallplot,
old.par, col and labels (par(old.par) will reset plot
parameters to the values before entering the function).
If reset = FALSE, the plotting region (par("plt")) may be changed
after exiting, to make it possible to add more features to the plot.
They can be restored using the old.par returned values or by calling
function par.reset().
fplot(), fcolor(), hcld.colors(), plot.default(), spoints().
with(mtcars, fpoints(hp, qsec, f = cyl, main = "Motor Trend Car Road Tests") )with(mtcars, fpoints(hp, qsec, f = cyl, main = "Motor Trend Car Road Tests") )
A generic function that, by default, draws a 3D scatter plot (rgl::plot3d())
with points colored according to the levels of a factor f, and (optionally)
adds a categorical legend (via fplot3d()).
fpoints3d(x, ...) ## Default S3 method: fpoints3d( x, y = NULL, z = NULL, f, col = hcld.colors(nlevels(f)), xlab = NULL, ylab = NULL, zlab = NULL, type = "p", legend = TRUE, legend.type = c("s", "c", "p", "l"), legend.zoom = 0.6, legend.width = 0.2, legend.size = 4, legend.dim = 0.2, legend.lab = NULL, lab.dist = 2.5, lab.rev = FALSE, add = FALSE, ... )fpoints3d(x, ...) ## Default S3 method: fpoints3d( x, y = NULL, z = NULL, f, col = hcld.colors(nlevels(f)), xlab = NULL, ylab = NULL, zlab = NULL, type = "p", legend = TRUE, legend.type = c("s", "c", "p", "l"), legend.zoom = 0.6, legend.width = 0.2, legend.size = 4, legend.dim = 0.2, legend.lab = NULL, lab.dist = 2.5, lab.rev = FALSE, add = FALSE, ... )
x |
object used to select a method. In the default method, it provides the |
... |
additional arguments passed to |
y, z
|
|
f |
(factor, or vector coercible to factor), used to color the points. |
col |
vector of colors associated with each level of |
xlab, ylab, zlab
|
labels for the coordinates. |
type |
character indicating the type of item to plot (see
|
legend |
logical; if |
legend.type |
character; symbol/object used to represent each
level in the legend (see |
legend.zoom |
zoom factor applied to the legend subscene/panel. |
legend.width |
relative size of the legend symbols (spheres, cubes or line segments), as a fraction of the corresponding dimension of the legend subscene. |
legend.size |
point size, if |
legend.dim |
relative dimension of the legend panel, as a fraction of the full width (or height) of the device. |
legend.lab |
label for the axis of the color legend, defaults to a
description of |
lab.dist |
distance between the legend symbols and their text
labels, as a multiple of the symbol size ( |
lab.rev |
logical; if |
add |
logical; if |
Called for its side effect (draws the 3D scatter plot and, unless
legend = FALSE, the legend on the active rgl device).
spoints3d(), fplot3d(), fcolor(), fshade3d(), rgl::plot3d().
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one with(mtcars, fpoints3d(hp, qsec, mpg, f = cyl, type = "s"))library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one with(mtcars, fpoints3d(hp, qsec, mpg, f = cyl, type = "s"))
Draws a triangular mesh (mesh3d) colored according to the levels of a
factor f, and (optionally) adds a categorical legend (via
fplot3d()).
fshade3d( x, f, meshColor = c("faces", "vertices"), col = hcld.colors(nlevels(f)), legend = TRUE, legend.type = c("s", "c", "p", "l"), legend.zoom = 0.6, legend.width = 0.2, legend.size = 4, legend.dim = 0.2, legend.lab = NULL, lab.dist = 2.5, lab.rev = FALSE, ... )fshade3d( x, f, meshColor = c("faces", "vertices"), col = hcld.colors(nlevels(f)), legend = TRUE, legend.type = c("s", "c", "p", "l"), legend.zoom = 0.6, legend.width = 0.2, legend.size = 4, legend.dim = 0.2, legend.lab = NULL, lab.dist = 2.5, lab.rev = FALSE, ... )
x |
triangular mesh ( |
f |
factor used to color the mesh. How its values are
interpreted depends on |
meshColor |
determines how color is applied to the mesh: |
col |
vector of colors associated with each level of |
legend |
logical; if |
legend.type |
character; symbol/object used to represent each
level in the legend (see |
legend.zoom |
zoom factor applied to the legend subscene/panel. |
legend.width |
relative size of the legend symbols (spheres, cubes or line segments), as a fraction of the corresponding dimension of the legend subscene. |
legend.size |
point size, if |
legend.dim |
relative dimension of the legend panel, as a fraction of the full width (or height) of the device. |
legend.lab |
label for the axis of the color legend, defaults to a
description of |
lab.dist |
distance between the legend symbols and their text
labels, as a multiple of the symbol size ( |
lab.rev |
logical; if |
... |
additional arguments passed on to |
Called for its side effect (draws the mesh and, unless legend = FALSE,
the legend on the active rgl device); invisibly returns the object identifiers.
fplot3d(), sshade3d(), hcld.colors().
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one z_tri <- vb2tri3d(volcanom, volcanom$vb[3, ]) fz_tri <- cut(z_tri, 5) fshade3d(volcanom, fz_tri, legend.dim = 0.3, lab.rev = TRUE)library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one z_tri <- vb2tri3d(volcanom, volcanom$vb[3, ]) fz_tri <- cut(z_tri, 5) fshade3d(volcanom, fz_tri, legend.dim = 0.3, lab.rev = TRUE)
Functions to set the mouse button actions for an rgl subscene
(the current one on the active device by default).
setmouse3d() sets the 'rgl' built-in mouse button modes (via rgl::par3d()).
pan3d() configures the callback functions of a mouse button so
that dragging it pans the subscene of an (opened) rgl device.
dbltrack3d() installs, on the given mouse button of an rgl (sub)scene,
the standard "trackball" rotation behavior (as that of parameter mouseMode
of rgl::par3d()), extended so that double-clicking resets the
viewpoint to "default" values.
setmouse3d( none = "none", left = "trackball", right = "zoom", middle = "fov", wheel = "pull", dev = cur3d(), subscene = currentSubscene3d(dev) ) pan3d( button, dev = cur3d(), subscene = currentSubscene3d(dev), message = FALSE ) dbltrack3d( button = 1, max.interval = 0.4, capture.now = FALSE, message = FALSE, dev = cur3d(), subscene = currentSubscene3d(dev) )setmouse3d( none = "none", left = "trackball", right = "zoom", middle = "fov", wheel = "pull", dev = cur3d(), subscene = currentSubscene3d(dev) ) pan3d( button, dev = cur3d(), subscene = currentSubscene3d(dev), message = FALSE ) dbltrack3d( button = 1, max.interval = 0.4, capture.now = FALSE, message = FALSE, dev = cur3d(), subscene = currentSubscene3d(dev) )
none, left, right, middle, wheel
|
actions for the corresponding mouse button;
see parameter |
dev |
rgl device on which the mouse actions are configured. Defaults to
the active device (see |
subscene |
subscene on which the mouse actions are configured. Defaults
to the device's active subscene (see |
button |
mouse button on which panning is configured. Use 1 for left, 2 for right, 3 for middle, 4 for wheel, and 0 to set this action when no button is pressed. |
message |
whether to print a message confirming the configured button, device and subscene. |
max.interval |
maximum time, in seconds, between two clicks for them to be treated as a double-click. |
capture.now |
logical; if |
pan3d() is based on the function of the same name included as an example
in the documentation of rgl::rgl.setMouseCallbacks().
dbltrack3d() reimplements the standard trackball rotation (following the
mouseCallbacks demo shipped with rgl, demo(mouseCallbacks, package = "rgl")) so that it can measure the
time elapsed since the previous click; if this is below max.interval,
the click is treated as a double-click and the view is reset instead of
starting a new rotation.
setmouse3d() invisibly returns the resulting mouseMode vector.
pan3d() is called for its side effect (registers the mouse callbacks); it
optionally prints a message confirming the configured button, device and
subscene.
dbltrack3d() is called for its side effect (registers the mouse callbacks); it
optionally prints a message confirming the configured button, device and
subscene.
new3d(), rgl::par3d(), rgl::rgl.setMouseCallbacks().
library(rgl) open3d() setmouse3d(middle = "zoom") # zoom with middle button or wheel pan3d(2) # pan the subscene with right button dbltrack3d(1) # rotate as usual with left button; double-click resets the view shade3d(volcanom, col = "lightgreen")library(rgl) open3d() setmouse3d(middle = "zoom") # zoom with middle button or wheel pan3d(2) # pan the subscene with right button dbltrack3d(1) # rotate as usual with left button; double-click resets the view shade3d(volcanom, col = "lightgreen")
Clear the current rgl device or open a new one (if there are no devices or
if open = TRUE).
new3d(open = FALSE, clear = "all", ...)new3d(open = FALSE, clear = "all", ...)
open |
if |
clear |
rgl stack(s) to remove, see argument |
... |
additional arguments, passed to |
In addition, new3d() changes several of the default mouse actions in rgl,
assigning the middle button to zoom (via setmouse3d()), the right button
to pan (via pan3d()), and enabling a double-click with the left button to
restore the scene's default viewpoint (via dbltrack3d(); keeping the mouse
acting as a virtual trackball, rotating the scene, when this button is held down).
Called for its side effect (opens or clears the rgl device, and configures the mouse mode); invisibly returns the current device.
rgl::open3d(), rgl::clear3d(), setmouse3d(), pan3d(), dbltrack3d().
library(rgl) # New rgl device new3d() shade3d(volcanom, col = "lightgreen") # Use the right mouse button to panning, # the middle button (or wheel) to zoom, # rotate as usual with left button; double-click resets the view # NOTE: these mouse actions currently **do not work with RMarkdown** documents. # ... # Clear the current device new3d() sshade3d(volcanom, s = volcanom$vb[3, ], meshColor = "facesvertices", col = terrain.colors(128))library(rgl) # New rgl device new3d() shade3d(volcanom, col = "lightgreen") # Use the right mouse button to panning, # the middle button (or wheel) to zoom, # rotate as usual with left button; double-click resets the view # NOTE: these mouse actions currently **do not work with RMarkdown** documents. # ... # Clear the current device new3d() sshade3d(volcanom, s = volcanom$vb[3, ], meshColor = "facesvertices", col = terrain.colors(128))
Restores the graphical parameters changed by splot()/fplot() (or by
sxxx()/fxxx() functions with reset = FALSE) or those previously set
as the default ones.
par.reset(default = FALSE, set = FALSE)par.reset(default = FALSE, set = FALSE)
default |
logical; if |
set |
logical; if |
Invisibly returns the graphical parameters as they were before
restoring/saving (see par()).
scale.range <- range(mtcars$mpg) splot(slim = scale.range, legend.lab = "mpg") with(mtcars, plot(hp, qsec, col = scolor(mpg, slim = scale.range), pch = 16, cex = 1.5) ) par.reset() # restores parameters from the last splot()/fplot() call # Set current parameters as the new default par.reset(set = TRUE) # ... later, after several splot()/fplot() calls ... par.reset(default = TRUE) # restores those that were set as defaultsscale.range <- range(mtcars$mpg) splot(slim = scale.range, legend.lab = "mpg") with(mtcars, plot(hp, qsec, col = scolor(mpg, slim = scale.range), pch = 16, cex = 1.5) ) par.reset() # restores parameters from the last splot()/fplot() call # Set current parameters as the new default par.reset(set = TRUE) # ... later, after several splot()/fplot() calls ... par.reset(default = TRUE) # restores those that were set as defaults
simage (generic function) draws an image (a grid of colored rectangles)
and (optionally) adds a legend strip with the color scale
(calls splot and image).
simage(x, ...) ## Default S3 method: simage( x = seq(0, 1, len = nrow(s)), y = seq(0, 1, len = ncol(s)), s, slim = range(s, finite = TRUE), col = jet.colors(128), breaks = NULL, legend = TRUE, horizontal = FALSE, legend.shrink = 0.8, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, reset = TRUE, xlab = NULL, ylab = NULL, asp = NA, ... )simage(x, ...) ## Default S3 method: simage( x = seq(0, 1, len = nrow(s)), y = seq(0, 1, len = ncol(s)), s, slim = range(s, finite = TRUE), col = jet.colors(128), breaks = NULL, legend = TRUE, horizontal = FALSE, legend.shrink = 0.8, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, reset = TRUE, xlab = NULL, ylab = NULL, asp = NA, ... )
x |
grid values for |
... |
additional graphical parameters (to be passed to |
y |
grid values for |
s |
matrix containing the values to be used for coloring the rectangles (NAs are allowed).
Note that |
slim |
limits used to set up the color scale. |
col |
color table used to set up the color scale (see |
breaks |
(optional) numeric vector with the breakpoints for the color scale:
must have one more breakpoint than |
legend |
logical; if |
horizontal |
logical; if |
legend.shrink |
amount to shrink the size of legend relative to the full height or width of the plot. |
legend.width |
width in characters of the legend strip. Default is 1.2, a little bigger that the width of a character. |
legend.mar |
width in characters of legend margin that has the axis. Default is 5.1 for a vertical legend and 3.1 for a horizontal legend. |
legend.lab |
label for the axis of the color legend. Default is no label as this is usual evident from the plot title. |
bigplot |
plot coordinates for main plot. If not passed these will be determined within the function. |
smallplot |
plot coordinates for legend strip. If not passed these will be determined within the function. |
lab.breaks |
if breaks are supplied these are text string labels to put at each break value. This is intended to label axis on a transformed scale such as logs. |
axis.args |
additional arguments for the axis function used to create
the legend axis (see |
legend.args |
arguments for a complete specification of the legend
label. This is in the form of list and is just passed to the |
reset |
logical; if |
xlab |
label for the x axis, defaults to a description of |
ylab |
label for the y axis, defaults to a description of |
asp |
the y/x aspect ratio, see |
Invisibly returns a list with the following 3 components:
bigplot |
plot coordinates of the main plot. These values may be useful for drawing a plot without the legend that is the same size as the plots with legends. |
smallplot |
plot coordinates of the secondary plot (legend strip). |
old.par |
previous graphical parameters ( |
If reset = FALSE, the plotting region (par("plt")) may be changed
after exiting, to make it possible to add more features to the plot.
They can be restored using the old.par returned values or by calling
function par.reset().
Based on image.plot function from package fields:
fields, Tools for spatial data.
Copyright 2004-2013, Institute for Mathematics Applied Geosciences.
University Corporation for Atmospheric Research.
Modified by Ruben Fernandez-Casal [email protected].
splot, spoints, spersp,
image, image.plot.
# Regularly spaced 2D data nx <- c(40, 40) # ndata = prod(nx) x1 <- seq(-1, 1, length.out = nx[1]) x2 <- seq(-1, 1, length.out = nx[2]) trend <- outer(x1, x2, function(x,y) x^2 - y^2) simage( x1, x2, trend, main = 'Trend')# Regularly spaced 2D data nx <- c(40, 40) # ndata = prod(nx) x1 <- seq(-1, 1, length.out = nx[1]) x2 <- seq(-1, 1, length.out = nx[2]) trend <- outer(x1, x2, function(x,y) x^2 - y^2) simage( x1, x2, trend, main = 'Trend')
spersp (generic function) draws a perspective plot of a surface over
the x-y plane with the facets being filled with different colors
and (optionally) adds a legend strip with the color scale
(calls splot and persp).
spersp(x, ...) ## Default S3 method: spersp( x = seq(0, 1, len = nrow(z)), y = seq(0, 1, len = ncol(z)), z, s = z, slim = range(s, finite = TRUE), col = jet.colors(128), breaks = NULL, legend = TRUE, horizontal = FALSE, legend.shrink = 0.8, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, reset = TRUE, xlab = NULL, ylab = NULL, zlab = NULL, theta = 40, phi = 20, ticktype = "detailed", cex.axis = 0.75, ... )spersp(x, ...) ## Default S3 method: spersp( x = seq(0, 1, len = nrow(z)), y = seq(0, 1, len = ncol(z)), z, s = z, slim = range(s, finite = TRUE), col = jet.colors(128), breaks = NULL, legend = TRUE, horizontal = FALSE, legend.shrink = 0.8, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, reset = TRUE, xlab = NULL, ylab = NULL, zlab = NULL, theta = 40, phi = 20, ticktype = "detailed", cex.axis = 0.75, ... )
x |
grid values for |
... |
additional graphical parameters (to be passed to |
y |
grid values for |
z |
matrix containing the values to be plotted (NAs are allowed).
Note that |
s |
matrix containing the values used for coloring the facets. |
slim |
limits used to set up the color scale. |
col |
color table used to set up the color scale (see |
breaks |
(optional) numeric vector with the breakpoints for the color scale:
must have one more breakpoint than |
legend |
logical; if |
horizontal |
logical; if |
legend.shrink |
amount to shrink the size of legend relative to the full height or width of the plot. |
legend.width |
width in characters of the legend strip. Default is 1.2, a little bigger that the width of a character. |
legend.mar |
width in characters of legend margin that has the axis. Default is 5.1 for a vertical legend and 3.1 for a horizontal legend. |
legend.lab |
label for the axis of the color legend. Default is no label as this is usual evident from the plot title. |
bigplot |
plot coordinates for main plot. If not passed these will be determined within the function. |
smallplot |
plot coordinates for legend strip. If not passed these will be determined within the function. |
lab.breaks |
if breaks are supplied these are text string labels to put at each break value. This is intended to label axis on a transformed scale such as logs. |
axis.args |
additional arguments for the axis function used to create
the legend axis (see |
legend.args |
arguments for a complete specification of the legend
label. This is in the form of list and is just passed to the |
reset |
logical; if |
xlab |
label for the x axis, defaults to a description of |
ylab |
label for the y axis, defaults to a description of |
zlab |
label for the z axis, defaults to a description of |
theta |
x-y rotation angle for perspective (azimuthal direction). |
phi |
z-angle for perspective (colatitude). |
ticktype |
character; |
cex.axis |
magnification to be used for axis annotation (relative to the
current setting of |
Invisibly returns a list with the following 4 components:
pm |
the viewing transformation matrix (see |
bigplot |
plot coordinates of the main plot. These values may be useful for drawing a plot without the legend that is the same size as the plots with legends. |
smallplot |
plot coordinates of the secondary plot (legend strip). |
old.par |
previous graphical parameters ( |
If reset = FALSE, the plotting region (par("plt")) may be changed
after exiting, to make it possible to add more features to the plot.
They can be restored using the old.par returned values or by calling
function par.reset().
Based on image.plot function from package fields:
fields, Tools for spatial data.
Copyright 2004-2013, Institute for Mathematics Applied Geosciences.
University Corporation for Atmospheric Research.
Modified by Ruben Fernandez-Casal [email protected].
splot, spoints, simage,
image, image.plot,
persp.
# Regularly spaced 2D data nx <- c(40, 40) # ndata = prod(nx) x1 <- seq(-1, 1, length.out = nx[1]) x2 <- seq(-1, 1, length.out = nx[2]) trend <- outer(x1, x2, function(x,y) x^2 - y^2) spersp( x1, x2, trend, main = 'Trend', zlab = 'y') # Multiple plots set.seed(1) y <- trend + rnorm(prod(nx), 0, 0.1) # 1x2 plot old.par <- par(mfrow = c(1,2)) spersp( x1, x2, trend, main = 'Trend', zlab = 'y', reset = FALSE) spersp( x1, x2, y, main = 'Data', zlab = 'y', reset = FALSE) par(old.par)# Regularly spaced 2D data nx <- c(40, 40) # ndata = prod(nx) x1 <- seq(-1, 1, length.out = nx[1]) x2 <- seq(-1, 1, length.out = nx[2]) trend <- outer(x1, x2, function(x,y) x^2 - y^2) spersp( x1, x2, trend, main = 'Trend', zlab = 'y') # Multiple plots set.seed(1) y <- trend + rnorm(prod(nx), 0, 0.1) # 1x2 plot old.par <- par(mfrow = c(1,2)) spersp( x1, x2, trend, main = 'Trend', zlab = 'y', reset = FALSE) spersp( x1, x2, y, main = 'Data', zlab = 'y', reset = FALSE) par(old.par)
A generic function that draws a 3D surface (rgl::persp3d())
colored according to a continuous scale associated with a vector
of values s, and (optionally) adds a color-bar legend (via splot3d()).
spersp3d(x, ...) ## Default S3 method: spersp3d( x, y = NULL, z = NULL, s = z, slim = range(s, finite = TRUE), col = jet.colors(128), xlab = NULL, ylab = NULL, zlab = NULL, xlim = NULL, ylim = NULL, zlim = NULL, aspect = !add, legend = TRUE, legend.zoom = 0.4, legend.width = 0.1, legend.dim = 0.2, legend.lab = NULL, box = TRUE, lab.breaks = NULL, lab.ticksize = 0.5, lab.dist = 3, add = FALSE, ... )spersp3d(x, ...) ## Default S3 method: spersp3d( x, y = NULL, z = NULL, s = z, slim = range(s, finite = TRUE), col = jet.colors(128), xlab = NULL, ylab = NULL, zlab = NULL, xlim = NULL, ylim = NULL, zlim = NULL, aspect = !add, legend = TRUE, legend.zoom = 0.4, legend.width = 0.1, legend.dim = 0.2, legend.lab = NULL, box = TRUE, lab.breaks = NULL, lab.ticksize = 0.5, lab.dist = 3, add = FALSE, ... )
x |
object used to select a method. In the default method, it typically
provides the grid values for the |
... |
additional arguments passed to |
y |
grid values for the |
z |
matrix with the surface height at each grid point (of dimension
|
s |
matrix with the values used for coloring the surface (one color per
vertex). Defaults to |
slim |
limits (vector of length 2 with the minimum and maximum) used to set up the color scale. |
col |
color table used to set up the color scale. Defaults to
|
xlab, ylab, zlab
|
titles for the axes (character strings; expressions are not accepted) |
xlim, ylim, zlim
|
x-, y- and z-limits. If present, the plot is clipped to this region. |
aspect |
either a logical indicating whether to adjust the aspect ratio, or a new ratio. |
legend |
logical; if |
legend.zoom |
zoom factor applied to the legend subscene (see
|
legend.width |
relative width of the color bar, as a fraction of the corresponding dimension of the legend subscene/panel. |
legend.dim |
relative dimension of the legend panel, as a fraction of the full width (or height) of the device. |
legend.lab |
legend title. |
box |
logical; if |
lab.breaks |
labels for the legend axis breaks; if |
lab.ticksize |
length of the legend axis tick marks, as a fraction of the distance to the center of the legend panel. |
lab.dist |
distance between the tick marks and the labels of the
legend axis, as a multiple of |
add |
logical; if |
Called for its side effect (draws the 3D surface plot and, unless
legend = FALSE, the legend on the active rgl device).
splot3d(), scolor(), sshade3d(), rgl::persp3d().
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one x <- seq(0, 1, length.out = 30) y <- seq(0, 1, length.out = 30) z <- outer(x, y, function(x, y) sin(2*pi*x) + 4*(y-0.5)^2 - 0.5) spersp3d(x, y, z)library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one x <- seq(0, 1, length.out = 30) y <- seq(0, 1, length.out = 30) z <- outer(x, y, function(x, y) sin(2*pi*x) + 4*(y-0.5)^2 - 0.5) spersp3d(x, y, z)
splot() is designed to combine a standard R plot with
a legend representing a (continuous) color scale. This is done by splitting
the plotting region into two parts. Keeping one for the main chart and
putting the legend in the other.
splot( slim = c(0, 1), col = jet.colors(128), breaks = NULL, horizontal = FALSE, legend.shrink = 0.9, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, add = FALSE )splot( slim = c(0, 1), col = jet.colors(128), breaks = NULL, horizontal = FALSE, legend.shrink = 0.9, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, add = FALSE )
slim |
limits used to set up the color scale. |
col |
color table used to set up the color scale (see |
breaks |
(optional) numeric vector with the breakpoints for the color scale:
must have one more breakpoint than |
horizontal |
logical; if |
legend.shrink |
amount to shrink the size of legend relative to the full height or width of the plot. |
legend.width |
width in characters of the legend strip. Default is 1.2, a little bigger that the width of a character. |
legend.mar |
width in characters of legend margin that has the axis. Default is 5.1 for a vertical legend and 3.1 for a horizontal legend. |
legend.lab |
label for the axis of the color legend. Default is no label as this is usual evident from the plot title. |
bigplot |
plot coordinates for main plot. If not passed these will be determined within the function. |
smallplot |
plot coordinates for legend strip. If not passed these will be determined within the function. |
lab.breaks |
if breaks are supplied these are text string labels to put at each break value. This is intended to label axis on a transformed scale such as logs. |
axis.args |
additional arguments for the axis function used to create
the legend axis (see |
legend.args |
arguments for a complete specification of the legend
label. This is in the form of list and is just passed to the |
add |
logical; if |
For instance, sxxxx() functions (spoints(), simage()
and spersp()) draw the corresponding high-level plot (xxxx()),
after calling splot(), to include a legend strip for the color scale.
These functions are based on function image.plot of package
fields, see its documentation for additional information.
Invisibly returns a list with the following 3 components:
bigplot |
plot coordinates of the main plot. These values may be useful for drawing a plot without the legend that is the same size as the plots with legends. |
smallplot |
plot coordinates of the secondary plot (legend strip). |
old.par |
previous graphical parameters ( |
The plotting region (par("plt")) may be changed
after exiting, to make it possible to add more features to the plot.
They can be restored using the old.par returned values or by calling
function par.reset().
Based on image.plot function from package fields:
fields, Tools for spatial data.
Copyright 2004-2013, Institute for Mathematics Applied Geosciences.
University Corporation for Atmospheric Research.
Modified by Ruben Fernandez-Casal [email protected].
jet.colors, hot.colors, scolor,
spoints, simage, spersp,
image, image.plot.
# Plot equivalent to spoints(): scale.range <- range(mtcars$mpg) res <- splot(slim = scale.range, legend.lab = "mpg") with(mtcars, plot(hp, qsec, col = scolor(mpg, slim = scale.range), pch = 16, cex = 1.5, main = "Motor Trend Car Road Tests") ) par(res$old.par) # restore graphical parameters # Multiple plots with a common legend: # regularly spaced 2D data... set.seed(1) nx <- c(40, 40) # ndata = prod(nx) x1 <- seq(-1, 1, length.out = nx[1]) x2 <- seq(-1, 1, length.out = nx[2]) trend <- outer(x1, x2, function(x,y) x^2 - y^2) y <- trend + rnorm(prod(nx), 0, 0.1) scale.range <- c(-1.2, 1.2) scale.color <- jet.colors(256) # 1x2 plot with some room for the legend... old.par <- par(mfrow = c(1,2), omd = c(0.05, 0.85, 0.05, 0.95)) image( x1, x2, trend, zlim = scale.range, main = 'Trend', col = scale.color) image( x1, x2, y, zlim = scale.range, main = 'Data', col = scale.color) par(old.par) # the legend can be added to any plot... splot(slim = scale.range, col = scale.color, legend.shrink = 0.7, add = TRUE) ## note that argument 'zlim' in 'image' corresponds with 'slim' in 'sxxxx' functions.# Plot equivalent to spoints(): scale.range <- range(mtcars$mpg) res <- splot(slim = scale.range, legend.lab = "mpg") with(mtcars, plot(hp, qsec, col = scolor(mpg, slim = scale.range), pch = 16, cex = 1.5, main = "Motor Trend Car Road Tests") ) par(res$old.par) # restore graphical parameters # Multiple plots with a common legend: # regularly spaced 2D data... set.seed(1) nx <- c(40, 40) # ndata = prod(nx) x1 <- seq(-1, 1, length.out = nx[1]) x2 <- seq(-1, 1, length.out = nx[2]) trend <- outer(x1, x2, function(x,y) x^2 - y^2) y <- trend + rnorm(prod(nx), 0, 0.1) scale.range <- c(-1.2, 1.2) scale.color <- jet.colors(256) # 1x2 plot with some room for the legend... old.par <- par(mfrow = c(1,2), omd = c(0.05, 0.85, 0.05, 0.95)) image( x1, x2, trend, zlim = scale.range, main = 'Trend', col = scale.color) image( x1, x2, y, zlim = scale.range, main = 'Data', col = scale.color) par(old.par) # the legend can be added to any plot... splot(slim = scale.range, col = scale.color, legend.shrink = 0.7, add = TRUE) ## note that argument 'zlim' in 'image' corresponds with 'slim' in 'sxxxx' functions.
Splits the active rgl device into two subscenes (the main plot and a color-bar legend) and draws, in the legend subscene, a continuous color scale together with its corresponding values.
splot3d( slim = c(0, 1), col = jet.colors(128), legend.zoom = 0.4, legend.width = 0.1, legend.dim = 0.2, legend.lab = NULL, box = TRUE, lab.breaks = NULL, lab.ticksize = 0.5, lab.dist = 3, ... )splot3d( slim = c(0, 1), col = jet.colors(128), legend.zoom = 0.4, legend.width = 0.1, legend.dim = 0.2, legend.lab = NULL, box = TRUE, lab.breaks = NULL, lab.ticksize = 0.5, lab.dist = 3, ... )
slim |
limits (vector of length 2 with the minimum and maximum) used to set up the color scale. |
col |
color table used to set up the color scale. Defaults to
|
legend.zoom |
zoom factor applied to the legend subscene (see
|
legend.width |
relative width of the color bar, as a fraction of the corresponding dimension of the legend subscene/panel. |
legend.dim |
relative dimension of the legend panel, as a fraction of the full width (or height) of the device. |
legend.lab |
legend title. |
box |
logical; if |
lab.breaks |
labels for the legend axis breaks; if |
lab.ticksize |
length of the legend axis tick marks, as a fraction of the distance to the center of the legend panel. |
lab.dist |
distance between the tick marks and the labels of the
legend axis, as a multiple of |
... |
additional arguments passed to |
Mouse rotation is disabled in the legend subscene.
Furthermore, since rgl::layout3d(..., mouseMode = "replace") does not
copy the user's mouse handlers (which are therefore disabled), the first one
is set up for trackball with double click to reset view (via dbltrack3d()),
and the second one (if any) for panning (via pan3d()).
Invisibly returns the identifiers of the created subscenes (see
rgl::layout3d()).
spoints3d(), spersp3d(), sshade3d(), axis3(), fplot3d()
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one scale.range <- range(mtcars$mpg) splot3d(slim = scale.range, legend.lab = "mpg") with( mtcars, plot3d(hp, qsec, wt, type = "s", col = scolor(mpg, slim = scale.range)))library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one scale.range <- range(mtcars$mpg) splot3d(slim = scale.range, legend.lab = "mpg") with( mtcars, plot3d(hp, qsec, wt, type = "s", col = scolor(mpg, slim = scale.range)))
A generic function that, by default, draws a scatter plot with points filled
with different colors and (optionally) adds a legend strip with the color scale
(spoints.default() calls splot() and plot.default(), or plot.xy()
if add = TRUE).
spoints(x, ...) ## Default S3 method: spoints( x, y = NULL, s, slim = range(s, finite = TRUE), col = jet.colors(128), breaks = NULL, type = "p", legend = TRUE, horizontal = FALSE, legend.shrink = 1, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, add = FALSE, reset = TRUE, pch = 16, cex = 1.5, xlab = NULL, ylab = NULL, asp = NA, ... )spoints(x, ...) ## Default S3 method: spoints( x, y = NULL, s, slim = range(s, finite = TRUE), col = jet.colors(128), breaks = NULL, type = "p", legend = TRUE, horizontal = FALSE, legend.shrink = 1, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, add = FALSE, reset = TRUE, pch = 16, cex = 1.5, xlab = NULL, ylab = NULL, asp = NA, ... )
x |
object used to select a method. In the default method, it provides the |
... |
additional graphical parameters (to be passed to the main plot function
or to |
y |
y coordinates. Alternatively, a single argument |
s |
numerical vector containing the values used for coloring the points. |
slim |
limits used to set up the color scale. |
col |
color table used to set up the color scale (see |
breaks |
(optional) numeric vector with the breakpoints for the color scale:
must have one more breakpoint than |
type |
character indicating the type of plotting; actually any of the
types as in |
legend |
logical; if |
horizontal |
logical; if |
legend.shrink |
amount to shrink the size of legend relative to the full height or width of the plot. |
legend.width |
width in characters of the legend strip. Default is 1.2, a little bigger that the width of a character. |
legend.mar |
width in characters of legend margin that has the axis. Default is 5.1 for a vertical legend and 3.1 for a horizontal legend. |
legend.lab |
label for the axis of the color legend, defaults to a
description of |
bigplot |
plot coordinates for main plot. If not passed, and |
smallplot |
plot coordinates for legend strip. If not passed, and |
lab.breaks |
if breaks are supplied these are text string labels to put at each break value. This is intended to label axis on a transformed scale such as logs. |
axis.args |
additional arguments for the axis function used to create
the legend axis (see |
legend.args |
arguments for a complete specification of the legend
label. This is in the form of list and is just passed to the |
add |
logical; if |
reset |
logical; if |
pch |
vector of plotting characters or symbols: see |
cex |
numerical vector giving the amount by which plotting characters
and symbols should be scaled relative to the default. This works as a multiple
of |
xlab |
label for the x axis, defaults to a description of |
ylab |
label for the y axis, defaults to a description of |
asp |
the y/x aspect ratio, see |
Invisibly returns a list with the following 3 components:
bigplot |
plot coordinates of the main plot. These values may be useful for drawing a plot without the legend that is the same size as the plots with legends. |
smallplot |
plot coordinates of the secondary plot (legend strip). |
old.par |
previous graphical parameters ( |
If reset = FALSE, the plotting region (par("plt")) may be changed after
exiting, to make it possible to add more features to the plot.
The graphical parameters can be restored using the old.par returned values
or by calling function par.reset().
Based on image.plot function from package fields:
fields, Tools for spatial data.
Copyright 2004-2013, Institute for Mathematics Applied Geosciences.
University Corporation for Atmospheric Research.
Modified by Ruben Fernandez-Casal [email protected].
splot(), simage(), spersp(), image(), fields::image.plot(),
plot.default(), fpoints().
with(mtcars, spoints(hp, qsec, mpg, main = "Motor Trend Car Road Tests") )with(mtcars, spoints(hp, qsec, mpg, main = "Motor Trend Car Road Tests") )
A generic function that, by default, draws a 3D scatter plot (rgl::plot3d())
with points colored according to a continuous scale associated with a vector
of values s, and (optionally) adds a color-bar legend (via splot3d()).
spoints3d(x, ...) ## Default S3 method: spoints3d( x, y = NULL, z = NULL, s, slim = range(s, finite = TRUE), col = jet.colors(128), xlab = NULL, ylab = NULL, zlab = NULL, type = "p", legend = TRUE, legend.zoom = 0.4, legend.width = 0.1, legend.dim = 0.2, legend.lab = NULL, box = TRUE, lab.breaks = NULL, lab.ticksize = 0.5, lab.dist = 3, add = FALSE, ... )spoints3d(x, ...) ## Default S3 method: spoints3d( x, y = NULL, z = NULL, s, slim = range(s, finite = TRUE), col = jet.colors(128), xlab = NULL, ylab = NULL, zlab = NULL, type = "p", legend = TRUE, legend.zoom = 0.4, legend.width = 0.1, legend.dim = 0.2, legend.lab = NULL, box = TRUE, lab.breaks = NULL, lab.ticksize = 0.5, lab.dist = 3, add = FALSE, ... )
x |
object used to select a method. In the default method, it provides the |
... |
additional arguments passed to |
y, z
|
|
s |
vector used to color the points. |
slim |
limits (vector of length 2 with the minimum and maximum) used to set up the color scale. |
col |
color table used to set up the color scale. Defaults to
|
xlab, ylab, zlab
|
labels for the coordinates. |
type |
character indicating the type of item to plot (see
|
legend |
logical; if |
legend.zoom |
zoom factor applied to the legend subscene (see
|
legend.width |
relative width of the color bar, as a fraction of the corresponding dimension of the legend subscene/panel. |
legend.dim |
relative dimension of the legend panel, as a fraction of the full width (or height) of the device. |
legend.lab |
legend title. |
box |
logical; if |
lab.breaks |
labels for the legend axis breaks; if |
lab.ticksize |
length of the legend axis tick marks, as a fraction of the distance to the center of the legend panel. |
lab.dist |
distance between the tick marks and the labels of the
legend axis, as a multiple of |
add |
logical; if |
Called for its side effect (draws the 3D scatter plot and, unless
legend = FALSE, the legend on the active rgl device).
fpoints3d(), splot3d(), scolor(), sshade3d(), rgl::plot3d().
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one with(mtcars, spoints3d(hp, qsec, wt, s = mpg, type = "s"))library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one with(mtcars, spoints3d(hp, qsec, wt, s = mpg, type = "s"))
Draws a triangular mesh (mesh3d) colored according to a continuous
scale associated with a vector of values s (via rgl::shade3d()),
and (optionally) adds a color-bar legend (via splot3d()).
sshade3d( x, s, meshColor = c("faces", "facesvertices", "vertices"), slim = range(s, finite = TRUE), col = jet.colors(128), legend = TRUE, legend.zoom = 0.4, legend.width = 0.1, legend.dim = 0.2, legend.lab = NULL, box = TRUE, lab.breaks = NULL, lab.ticksize = 0.5, lab.dist = 3, ... )sshade3d( x, s, meshColor = c("faces", "facesvertices", "vertices"), slim = range(s, finite = TRUE), col = jet.colors(128), legend = TRUE, legend.zoom = 0.4, legend.width = 0.1, legend.dim = 0.2, legend.lab = NULL, box = TRUE, lab.breaks = NULL, lab.ticksize = 0.5, lab.dist = 3, ... )
x |
triangular mesh ( |
s |
values used to color the mesh. How they are interpreted depends on
|
meshColor |
determines how material colours (and textures) are interpreted:
|
slim |
limits (vector of length 2 with the minimum and maximum) used to set up the color scale. |
col |
color table used to set up the color scale. Defaults to
|
legend |
logical; if |
legend.zoom |
zoom factor applied to the legend subscene (see
|
legend.width |
relative width of the color bar, as a fraction of the corresponding dimension of the legend subscene/panel. |
legend.dim |
relative dimension of the legend panel, as a fraction of the full width (or height) of the device. |
legend.lab |
legend title. |
box |
logical; if |
lab.breaks |
labels for the legend axis breaks; if |
lab.ticksize |
length of the legend axis tick marks, as a fraction of the distance to the center of the legend panel. |
lab.dist |
distance between the tick marks and the labels of the
legend axis, as a multiple of |
... |
additional arguments passed to |
Called for its side effect (draws the mesh and, unless add = TRUE,
the legend on the active rgl device); invisibly returns the object identifiers.
splot3d(), scolor(), vb2tri3d(), fshade3d(), rgl::shade3d().
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one sshade3d(volcanom, s = volcanom$vb[3, ], meshColor = "facesvertices")library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one sshade3d(volcanom, s = volcanom$vb[3, ], meshColor = "facesvertices")
For each triangle of a mesh, computes the average of the values
associated with its three vertices. This is useful for going from a
per-vertex value to a per-face value (for example, to use
meshColor = "faces" in rgl::shade3d() starting from a quantity
defined at the vertices).
vb2tri3d(x, s)vb2tri3d(x, s)
x |
triangular mesh ( |
s |
vector of values associated with the vertices of |
Numeric vector with one value per triangle (column of x$it), equal to
the average of the values of s at its vertices.
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one z_tri <- vb2tri3d(volcanom, volcanom$vb[3, ]) shade3d(volcanom, col = scolor(z_tri, col = terrain.colors(128)))library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one z_tri <- vb2tri3d(volcanom, volcanom$vb[3, ]) shade3d(volcanom, col = scolor(z_tri, col = terrain.colors(128)))
Functions to retrieve, save, restore, list and remove rgl viewpoints; see Details for additional information.
addviewpoint3d(name, view = getview3d()) setviewpoint3d(name = "default") lsviewpoints3d(...) rmviewpoints3d(...) getviewpoints3d() getview3d() setview3d(view)addviewpoint3d(name, view = getview3d()) setviewpoint3d(name = "default") lsviewpoints3d(...) rmviewpoints3d(...) getviewpoints3d() getview3d() setview3d(view)
name |
character string giving the name under which a viewpoint is
stored ( |
view |
a list with the viewpoint parameters, typically the value
returned by |
... |
addviewpoint3d() stores view under name,
silently overwriting any viewpoint previously stored under the same name.
By default view is the current viewpoint, as returned by getview3d().
setviewpoint3d() looks up the viewpoint stored under name and applies
it to the current rgl subscene via setview3d().
lsviewpoints3d() returns the names of all the viewpoints currently
stored.
rmviewpoints3d() Deletes one or more saved viewpoints by name.
If called without arguments, it deletes all of them, always retaining
the "default" viewpoint.
getviewpoints3d() returns a named list with all the viewpoints
currently stored, one entry per name.
getview3d() retrieves the parameters that define the current viewpoint
of the current rgl subscene (zoom, user matrix and user projection), so
that they can be saved and restored later with setview3d().
setview3d() applies to the current rgl subscene a viewpoint previously
obtained with getview3d() (this is also what setviewpoint3d() uses
internally to restore a stored viewpoint).
addviewpoint3d() is called for its side effect of storing view under
name; it invisibly returns view.
setviewpoint3d() is called for its side effect of restoring a stored
viewpoint to the current rgl subscene; it invisibly returns the corresponding view.
lsviewpoints3d() returns a character vector with the names of the
stored viewpoints.
rmviewpoints3d() is called for its side effect of removing one or more
stored viewpoints.
getviewpoints3d() returns a named list with all the stored viewpoints.
getview3d() returns a list with the components zoom, userMatrix
and userProjection (see rgl::par3d()).
setview3d() is called mainly for its side effect of setting the
viewpoint of the current rgl subscene (see rgl::par3d()); it returns the
value returned by par3d().
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one. # It also saves the default viewpoint under the name "default" shade3d(volcanom, col = "lightgreen") # ... rotate, zoom or pan the scene interactively ... # Save the current viewpoint under the name "myview" addviewpoint3d("myview") # ... rotate, zoom or pan the scene interactively ... # Restore the default viewpoint setviewpoint3d() # Restore the saved viewpoint setviewpoint3d("myview") # Names of the stored viewpoints lsviewpoints3d() # All stored viewpoints, as a named list views <- getviewpoints3d() # Remove all stored viewpoints rmviewpoints3d() lsviewpoints3d()library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one. # It also saves the default viewpoint under the name "default" shade3d(volcanom, col = "lightgreen") # ... rotate, zoom or pan the scene interactively ... # Save the current viewpoint under the name "myview" addviewpoint3d("myview") # ... rotate, zoom or pan the scene interactively ... # Restore the default viewpoint setviewpoint3d() # Restore the saved viewpoint setviewpoint3d("myview") # Names of the stored viewpoints lsviewpoints3d() # All stored viewpoints, as a named list views <- getviewpoints3d() # Remove all stored viewpoints rmviewpoints3d() lsviewpoints3d()
Surface mesh corresponding to the altitude on a 10m by 10m grid of Auckland's Maunga Whau volcano.
data(volcanom)data(volcanom)
volcanomA rgl::mesh3d-class object with 5307 vertices and 10320 triangles.
datasets::volcano and example taken from rgl::surface3d.
library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one aspect3d(1, 1, 3) # Exaggerate the relief shade3d(volcanom, col = "lightgreen")library(rgl) open3d() # Alternatively, use `new3d()` to clear the current device or open a new one aspect3d(1, 1, 3) # Exaggerate the relief shade3d(volcanom, col = "lightgreen")