geom_oblicuboids {oblicubes} | R Documentation |
Draw 2D/3D cuboids with ggplot2
Description
geom_oblicuboids()
creates a ggplot2
geom that draws cuboids
Usage
geom_oblicuboids(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
angle = 45,
scale = 0.5,
xoffset = 0,
yoffset = 0,
zoffset = 0,
light = darken_face,
show.legend = NA,
inherit.aes = TRUE
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Aesthetics, used to set an aesthetic to a fixed value. |
angle |
Oblique projection angle. |
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”. |
xoffset , yoffset , zoffset |
By default the x,y values are assumed to be the center of the cuboid
and the z value is assumed to be the top of the cuboid.
Use |
light |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Details
geom_oblicuboids()
requires a fixed scale coordinate system with an aspect
ratio of 1 as provided by ggplot2::coord_fixed()
.
Value
A ggplot2 geom.
Aesthetics
geom_oblicuboids()
understands the following aesthetics (required aesthetics are in bold).
See oblicuboidsGrob()
for more details.
-
x
-
y
-
z
-
fill
-
colour
-
linetype
-
linewidth
See Also
geom_oblicuboids()
is a wrapper around oblicuboidsGrob()
.
Examples
if (require("ggplot2")) {
data("volcano", package = "datasets")
df <- xyz_heightmap(volcano, scale = 0.3, min = 1)
g <- ggplot(df, aes(x, y, z = z, fill = raw)) +
geom_oblicuboids(light = FALSE) +
coord_fixed() +
scale_fill_gradientn(name = "Height (m)",
colours=terrain.colors(256)) +
labs(x = "East (10m)", y = "North (10m)",
title = "Maungawhau (`datasets::volcano`)")
plot(g)
}
if (require("ggplot2")) {
# Using `scale_fill_identity()` if using `xyz_heightmap()`'s `fill` column
df <- xyz_heightmap(volcano, scale = 0.3, min = 1,
col = grDevices::heat.colors)
g <- ggplot(df, aes(x, y, z = z, fill = fill)) +
geom_oblicuboids() +
coord_fixed() +
scale_fill_identity()
plot(g)
}
if (require("ggplot2") && require("dplyr")) {
# Note you probably should not do 3D bar charts...
df <- as.data.frame(datasets::Titanic) |>
filter(Age == "Child", Freq > 0) |>
group_by(Sex, Survived, Class) |>
summarize(Freq = seq.int(sum(Freq)), .groups = "drop")
g <- ggplot(df, aes(x = Survived, y = Freq, fill = Survived)) +
facet_grid(cols = vars(Class, Sex)) +
coord_fixed() +
geom_oblicuboids(yoffset = -0.5, scale = 0.7, angle = -45) +
scale_fill_manual(values = c("Yes" = "lightblue", "No" = "red")) +
scale_y_continuous(expand = expansion(), name = "") +
scale_x_discrete(name = "", breaks = NULL) +
labs(title = "Children on the Titanic (by ticket class)")
plot(g)
}