library(rgl)
library(devout)
library(devoutrgl)
library(ggrgl)
library(ggplot2)
library(dplyr)
library(raymolecule)
geom_sphere_3d
- 3d scatter plot
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a plot with `geom_sphere_3d()`
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p <- ggplot(mtcars) +
geom_sphere_3d(aes(x = mpg, y = wt, z = disp,
size = as.factor(cyl),
colour = as.factor(cyl))) +
geom_segment_3d(aes(x = mpg, xend = mpg, y = wt, yend = wt, zend = disp), z = 0,
alpha = 0.3) +
theme_ggrgl(18) +
labs(
title = "3d scatterplot",
subtitle = "ggrgl::geom_sphere_3d() with {devoutrgl}"
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Render with a 3d backend - 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_sphere_3d
N <- 4
vertex_df <- expand.grid(
x = 1:N,
y = 1:N,
z = 1:N,
type = 'vertex',
stringsAsFactors = FALSE
)
center_df <- expand.grid(
x = (1:(N-1)) + 0.5,
y = (1:(N-1)) + 0.5,
z = (1:(N-1)) + 0.5,
type = 'center',
stringsAsFactors = FALSE
)
crystal_df <- bind_rows(vertex_df, center_df)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a plot with `geom_sphere_3d()`
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p <- ggplot() +
geom_sphere_3d(data = crystal_df, aes(x = x, y = y, z = z, size = type, colour = type),
material = list(lit = TRUE)) +
theme_void() +
coord_equal() +
labs(
title = "Body-centred cubic crystal lattice",
subtitle = "ggrgl::geom_sphere_3d() with {devoutrgl}"
) +
scale_size_manual(values = c(center = 50, vertex = 18)) +
theme(legend.position = 'none')
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Render with a 3d backend - devoutrgl
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
devoutrgl::rgldev(fov = 30, view_angle = -30, zscale = 4)
p
invisible(dev.off())
Use your mouse, mouse buttons and scrollwheel to manipulate the 3d plot