library(rgl)
library(devout)
library(devoutrgl)
library(ggrgl)
library(ggplot2)
library(dplyr)
library(purrr)
library(tibble)
library(tidyr)
library(viridis)
geom_tile_z
to render tiles at different heights
set.seed(1)
N <- 10
x <- LETTERS[1:N]
y <- paste0("var", seq(1,N))
data <- expand.grid(X=x, Y=y)
data$Z <- runif(N*N, 0, 5)
p <- ggplot(data, aes(X, Y, fill= Z, z= Z)) +
geom_tile_z(extrude = TRUE, mapping = aes(extrude_face_fill = Z)) +
coord_equal() +
labs(
title = "ggrgl::geom_tile_z() rendering heights",
subtitle = "with {devoutrgl}"
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Render Plot in 3d with {devoutrgl}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
devoutrgl::rgldev(fov = 30, view_angle = -30)
p
invisible(dev.off())
Use your mouse, mouse buttons and scrollwheel to manipulate the 3d plot
geom_tile_z
to render volcano
data
p <- volcano %>%
# Data wrangling
as_tibble() %>%
rowid_to_column(var="X") %>%
gather(key="Y", value="Z", -1) %>%
# Change Y to numeric
mutate(Y=as.numeric(gsub("V","",Y))) %>%
# Viz
ggplot(aes(X, Y, fill= Z, colour = Z, z = Z)) +
geom_tile_z(extrude = TRUE) +
theme_ggrgl() +
theme(legend.position="none") +
scale_fill_viridis_c(option = 'A') +
scale_colour_viridis_c(option = 'A') +
coord_equal() +
labs(
title = "ggrgl::geom_tile_z() rendering volcano",
subtitle = "with {devoutrgl}"
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Render Plot in 3d with {devoutrgl}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
devoutrgl::rgldev(fov = 30, view_angle = -30)
p
invisible(dev.off())
Use your mouse, mouse buttons and scrollwheel to manipulate the 3d plot