devoutrgl
devoutrgl::rgldev()
is a graphics device - like pdf()
or png()
. This device
will render a plot as an interactive 3d opengl document using {rgl}
.
NOTE: Since Github does not allow webgl rendering in README files, all plots on GitHub have been rendered as PNGs or animated gifs. Please visit the package website to interact with the generated output in the vignettes
What’s in the box:
rgldev()
is the rgl device. Use it like you would use thepdf()
device or thepng()
device.
Installation
You can install from GitHub with:
# install.packages("remotes")
remotes::install_github("coolbutuseless/snowcrash") # Store R objects as images
remotes::install_github("coolbutuseless/cryogenic") # Freeze R calls + replay
remotes::install_github("coolbutuseless/triangular") # Polygon Triangulation
remotes::install_github("coolbutuseless/devout") # R device framework
remotes::install_github("coolbutuseless/devoutrgl") # This device
Limitations
- No font selection. Everything will be in the default sans serif!
- Multi-line text in a single string with “” characters does not render well.
- No support for clipping paths.
Examples
Bar Plot
library(ggplot2)
library(devoutrgl)
plot_df <- data.frame(x=c('a', 'b', 'c'), y=4:6)
p <- ggplot(plot_df) +
geom_bar(aes(x, y, fill=x), colour = NA, stat='identity') +
labs(title = "{devoutrgl}") +
scale_fill_brewer(type = 'seq', palette = 'Blues') +
theme_minimal() + theme_rgl()
devoutrgl::rgldev(fov = 30, view_angle = -30)
p
invisible(dev.off())
Use your mouse, mouse buttons and scrollwheel to manipulate the 3d plot
Base plot
devoutrgl::rgldev(fov = 30, view = 'flat', view_angle = 30, zoom = 0.6)
pie(c(cool=1, but = 2, use=3, less = 4))
dev.off()
quartz_off_screen
2
Use your mouse, mouse buttons and scrollwheel to manipulate the 3d plot
Polygon with a hole
Polygon with a hole
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# polygons_df - data.frame of polygon vertices with group/subgroups
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
polygons_df <- df <- data.frame(
x = c(4, 8, 8, 4, 6, 7, 7, 6),
y = c(4, 4, 8, 8, 6, 6, 7, 7),
group = c(1, 1, 1, 1, 1, 1, 1, 1),
subgroup = c(1, 1, 1, 1, 2, 2, 2, 2)
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Plot
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p <- ggplot(polygons_df) +
geom_polygon(aes(x, y, group=group, subgroup=subgroup)) +
geom_path(aes(x, y, group = interaction(group, subgroup)), colour = 'red') +
theme_bw() +
coord_equal() +
labs(title = "{devoutrgl} polygon with a hole")
rgldev(fov = 30, view_angle = -30, zoom = 0.8)
p
invisible(dev.off())
Use your mouse, mouse buttons and scrollwheel to manipulate the 3d plot
Density Plot
library(ggplot2)
library(devoutrgl)
p <- ggplot(mtcars) +
geom_density(aes(mpg, fill=as.factor(cyl)), colour = '#ffffff00') +
theme(legend.position = 'none') +
scale_fill_brewer(palette = 'Set1') +
theme_bw() +
labs(title = "{devoutrgl} geom_density()")
rgldev(fov = 30, view_angle = 30)
p
invisible(dev.off())
Use your mouse, mouse buttons and scrollwheel to manipulate the 3d plot
Generating the logo for this package
library(ggplot2)
library(dplyr)
hex_df <- tibble(
rad = seq(0, 2*pi, pi/3),
x = sin(rad),
y = cos(rad)
)
p <- ggplot(hex_df) +
geom_polygon(aes(x, y), fill = '#002366', colour = '#436B9530') +
annotate('text', x = 0, y = 0, label = "/dev/out/\nrgl", size = 20, color = 'grey90') +
coord_fixed() +
theme_minimal(25) +
theme(panel.grid = element_blank())
devoutrgl::rgldev(
width = 5.5,
fov = 30,
view3d_args = list(-45, 0, zoom = 0.8)
)
p
invisible(dev.off())
Use your mouse, mouse buttons and scrollwheel to manipulate the 3d plot