oblicubesGrob() / grid.oblicubes() renders cubes using a 3D oblique projection.
oblicubesGrob() returns a grid grob object while
grid.oblicubes() also draws the grob to the graphic device.
As a special case may also render a 2D primary view orthographic projection.
Usage
oblicubesGrob(
x,
y = NULL,
z = NULL,
...,
fill = NULL,
light = darken_face,
scale = 0.5,
angle = 45,
xo = NULL,
yo = NULL,
width = NULL,
default.units = "snpc",
name = NULL,
gp = gpar(),
vp = NULL
)
grid.oblicubes(
x,
y = NULL,
z = NULL,
...,
fill = NULL,
light = darken_face,
scale = 0.5,
angle = 45,
xo = NULL,
yo = NULL,
width = NULL,
default.units = "snpc",
name = NULL,
gp = gpar(),
vp = NULL
)Arguments
- x
Integer vector of x coordinates (if necessary will be rounded to integers). May be a
data.frameof x,y,z coordinates (and maybe fill color).- y
Integer vector of y coordinates (if necessary will be rounded to integers). If
NULLandxis a data frame with aycolumn then we use that instead.- z
Integer vector of z coordinates (if necessary will be rounded to integers). If
NULLandxis a data frame with azcolumn then we use that instead.- ...
Passed to
grid::gpar(). Will override any values set ingp.- fill
Fill color(s) for the cubes. If
NULLandxis a data frame with afillorcolcolumn then we use that column; if no such column butgphas afillvalue we use that; otherwise we fall back to "grey90".- light
If
FALSEdon't perform a "light" effect. Otherwise a function that takes two arguments: the firstfaceof the cube/cuboid face (one of "top", "west", "east", "south", "north"). the secondcolof the fill color. By default we usedarken_face().- scale
Oblique projection foreshortening factor. 0.5 corresponds to the “cabinet projection”. 1.0 corresponds to the “cavalier projection”. 0.0 corresponds to a “primary view orthographic projection”.
- angle
Oblique projection angle.
- xo, yo
The origin of the oblique projection coordinate system in grid units. The default is to try to guess a “good” value.
- width
Width of the cube's (non-foreshortened) sides. The default will be to try to guess a “good” value.
- default.units
Default units for the
xo,yo, andwidtharguments.- name
A character identifier (for grid).
- gp
A ‘grid’ gpar object. See
grid::gpar(). Will be merged with the values in...and the value offill.- vp
A ‘grid’ viewport object. See
grid::viewport().
Examples
if (require("grid")) {
# we support arbitrary oblique projection angles
mat <- matrix(c(1, 2, 1, 2, 3, 2, 1, 2, 1), nrow = 3, ncol = 3, byrow = TRUE)
coords <- xyz_heightmap(mat, col = c("red", "yellow", "green"))
angles <- c(135, 90, 45, 180, 45, 0, -135, -90, -45)
scales <- c(0.5, 0.5, 0.5, 0.5, 0.0, 0.5, 0.5, 0.5, 0.5)
vp_x <- rep(1:3/3 - 1/6, 3)
vp_y <- rep(3:1/3 - 1/6, each = 3)
grid.newpage()
for (i in 1:9) {
pushViewport(viewport(x=vp_x[i], y=vp_y[i], width=1/3, height=1/3))
grid.rect(gp = gpar(lty = "dashed"))
grid.oblicubes(coords, width = 0.15, xo = 0.25, yo = 0.15,
angle = angles[i], scale = scales[i],
gp = gpar(lwd=4))
if(i != 5)
grid.text(paste("angle =", angles[i]), y=0.92, gp = gpar(cex = 1.2))
else
grid.text(paste("scale = 0"), y=0.92, gp = gpar(cex = 1.2))
popViewport()
}
}
#> Loading required package: grid
# volcano example
mat <- datasets::volcano
mat <- 0.3 * (mat - min(mat)) + 1.0
coords <- xyz_heightmap(mat, col = grDevices::terrain.colors)
grid::grid.newpage()
grid.oblicubes(coords)