Draw 3D Geoms for ggplot2
stat_3D.RdThis function adds 3D geoms such as points and paths to a ggplot2 plot.
Usage
stat_3D(
mapping = NULL,
data = NULL,
geom = "point",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)Arguments
- mapping
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot.
- data
Default dataset to use for plot. If not already a data.frame, will be converted to one by
fortify(). If not specified, must be supplied in each layer added to the plot.- geom
The geometric object to use to display the data for this layer. When using a
stat_*()function to construct a layer, thegeomargument can be used to override the default coupling between stats and geoms. Thegeomargument accepts the following:A
Geomggproto subclass, for exampleGeomPoint.A string naming the geom. To give the geom as a string, strip the function name of the
geom_prefix. For example, to usegeom_point(), give the geom as"point".For more information and other ways to specify the geom, see the layer geom documentation.
- position
Set position information. Find more details in
ggplot2function.- na.rm
Boolean if na data should be removed.
- show.legend
logical. Should this layer be included in the legends?
NA, the default, includes if any aesthetics are mapped.FALSEnever includes, andTRUEalways includes. It can also be a named logical vector to finely select the aesthetics to display. To include legend keys for all levels, even when no data exists, useTRUE. IfNA, all levels are shown in legend, but unobserved levels are omitted.- inherit.aes
If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification.
- ...
Arguments passed on to layer. Often the aesthetics like
color = "red"orsize = 3. Two important ones aretheta(azimuthal rotation) andphi(colatitude rotation) to define angle in degrees of viewing data.
Value
No direct return value, called to be used with ggplot2::ggplot()
in designing the plot.
Examples
dat <- electricity
data_lines <- cbind(data.frame("Time" = dat$fparam), dat$data) %>%
tidyr::pivot_longer(cols = 1 + 1:ncol(dat$data))
colors_plot <- RColorBrewer::brewer.pal(11, "Spectral")
colors_plot <- grDevices::colorRampPalette(colors_plot)(ncol(dat$data))
data_lines$color <- rep(colors_plot, nrow(dat$data))
data_lines$name <- as.numeric(data_lines$name)
result <- ggplot2::ggplot(
data_lines,
ggplot2::aes(y = Time, x = name, z = value, color = color)
) +
ggplot2::theme_void() +
stat_3D(theta = 0, phi = 15, geom = "path") +
ggplot2::scale_color_manual(
breaks = data_lines$color,
values = data_lines$color
) +
ggplot2::guides(color = "none")