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_oblicubes(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)
}
# \donttest{
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_oblicubes() +
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_oblicubes(yoffset = -0.5, zoffset = -0.5, angle = -45, scale = 0.7) +
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)
}
Run the code above in your browser using DataLab