library(rgl)
library(devout)
library(devoutrgl)
library(ggrgl)
library(ggplot2)
library(dplyr)
library(gapminder)
geom_line_3d()
library(HistData) # for Minard datasets
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Keep only the main group
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
minard <- Minard.troops[Minard.troops$group == 1, ]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a plot with `geom_path_3d`
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p <- ggplot(minard) +
geom_path_3d(
aes(long, lat, z = survivors),
extrude = TRUE, extrude_edge_colour = 'grey20', extrude_face_fill = 'grey80',
extrude_edge_alpha = 0.2) +
geom_text(data = Minard.cities, aes(long, lat, label = city)) +
geom_point(data = Minard.cities, aes(long, lat), colour = 'red') +
theme_ggrgl() +
labs(
title = "Napoleon's 1812 March - Height indicates the size of the army",
subtitle = "ggrgl::geom_path_3d() 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