diff --git a/NAMESPACE b/NAMESPACE index ad717d87..47dc4318 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -295,6 +295,7 @@ export(free_space) export(free_vp) export(geom_draw) export(geom_pie) +export(geom_rect3d) export(geom_subrect) export(geom_subtile) export(geom_tile3d) diff --git a/R/geom-tile3d.R b/R/geom-tile3d.R index 1ad92de6..5584f483 100644 --- a/R/geom-tile3d.R +++ b/R/geom-tile3d.R @@ -6,9 +6,9 @@ #' @inheritParams ggplot2::layer #' @inheritParams ggplot2::geom_polygon #' @inheritParams ggplot2::geom_path -#' @eval rd_gg_aesthetics("geom", "tile3d") +#' @eval rd_gg_aesthetics("geom", "rect3d") #' @export -geom_tile3d <- function(mapping = NULL, data = NULL, stat = "identity", +geom_rect3d <- function(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { @@ -16,7 +16,7 @@ geom_tile3d <- function(mapping = NULL, data = NULL, stat = "identity", data = data, mapping = mapping, stat = stat, - geom = GeomTile3d, + geom = GeomRect3d, position = position, show.legend = show.legend, inherit.aes = inherit.aes, @@ -30,22 +30,23 @@ geom_tile3d <- function(mapping = NULL, data = NULL, stat = "identity", } #' @importFrom ggplot2 ggproto -GeomTile3d <- ggproto( - "GeomTile3d", - ggplot2::GeomTile, - default_aes = ggplot2::GeomTile$default_aes, - required_aes = c(ggplot2::GeomTile$required_aes, "z"), - non_missing_aes = c(ggplot2::GeomTile$non_missing_aes, "z", "theta"), +GeomRect3d <- ggproto( + "GeomRect3d", + ggplot2::GeomRect, + required_aes = c(ggplot2::GeomRect$required_aes, "z"), + non_missing_aes = c(ggplot2::GeomRect$non_missing_aes, "z", "theta"), setup_data = function(self, data, params) { if (any(data$z %||% .subset2(params, "z") < 0)) { cli_abort("value mapped to {.field z} aesthetic must >= 0") } theta <- data$theta %||% .subset2(params, "theta") %||% 60 if (!is.null(theta) && any(theta <= 0 || theta >= 90)) { - cli_abort("value mapped to {.field theta} aesthetic must > 0 and < 90.") + cli_abort( + "value mapped to {.field theta} aesthetic must > 0 and < 90." + ) } data$theta <- theta - data <- ggproto_parent(ggplot2::GeomTile, self)$setup_data( + data <- ggproto_parent(ggplot2::GeomRect, self)$setup_data( data, params ) data <- vec_slice(data, order( @@ -130,3 +131,47 @@ GeomTile3d <- ggproto( ) } ) + +#' @eval rd_gg_aesthetics("geom", "tile3d") +#' @importFrom rlang list2 +#' @export +#' @rdname geom_rect3d +geom_tile3d <- function(mapping = NULL, data = NULL, stat = "identity", + position = "identity", ..., + lineend = "butt", linejoin = "round", linemitre = 10, + na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { + ggplot2::layer( + data = data, + mapping = mapping, + stat = stat, + geom = GeomTile3d, + position = position, + show.legend = show.legend, + inherit.aes = inherit.aes, + params = list( + lineend = lineend, + linejoin = linejoin, + linemitre = linemitre, + na.rm = na.rm, ... + ) + ) +} + +#' @importFrom ggplot2 ggproto ggproto_parent +GeomTile3d <- ggproto( + "GeomTile3d", + ggplot2::GeomTile, + required_aes = c(ggplot2::GeomTile$required_aes, "z"), + non_missing_aes = c(ggplot2::GeomTile$non_missing_aes, "z", "theta"), + setup_data = function(self, data, params) { + data <- ggproto_parent(ggplot2::GeomTile, self)$setup_data(data, params) + ggproto_parent(GeomRect3d, self)$setup_data(data, params) + }, + draw_panel = function(self, data, panel_params, coord, lineend = "butt", + linejoin = "round", linemitre = 10) { + GeomRect3d$draw_panel( + data = data, panel_params = panel_params, coord = coord, + lineend = lineend, linejoin = linejoin, linemitre = linemitre + ) + } +) diff --git a/man/geom_tile3d.Rd b/man/geom_rect3d.Rd similarity index 85% rename from man/geom_tile3d.Rd rename to man/geom_rect3d.Rd index f0d1338d..11b4347a 100644 --- a/man/geom_tile3d.Rd +++ b/man/geom_rect3d.Rd @@ -1,9 +1,24 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/geom-tile3d.R -\name{geom_tile3d} +\name{geom_rect3d} +\alias{geom_rect3d} \alias{geom_tile3d} \title{Add z-aesthetic for geom_tile} \usage{ +geom_rect3d( + mapping = NULL, + data = NULL, + stat = "identity", + position = "identity", + ..., + lineend = "butt", + linejoin = "round", + linemitre = 10, + na.rm = FALSE, + show.legend = NA, + inherit.aes = TRUE +) + geom_tile3d( mapping = NULL, data = NULL, @@ -126,6 +141,23 @@ Add z-aesthetic for geom_tile \section{Aesthetics}{ +\code{geom_rect3d()} understands the following aesthetics (required aesthetics are in bold): +\itemize{ +\item \strong{\code{\link[ggplot2:aes_position]{xmin}}} +\item \strong{\code{\link[ggplot2:aes_position]{xmax}}} +\item \strong{\code{\link[ggplot2:aes_position]{ymin}}} +\item \strong{\code{\link[ggplot2:aes_position]{ymax}}} +\item \strong{\code{z}} +\item \code{\link[ggplot2:aes_colour_fill_alpha]{alpha}} +\item \code{\link[ggplot2:aes_colour_fill_alpha]{colour}} +\item \code{\link[ggplot2:aes_colour_fill_alpha]{fill}} +\item \code{\link[ggplot2:aes_group_order]{group}} +\item \code{\link[ggplot2:aes_linetype_size_shape]{linetype}} +\item \code{\link[ggplot2:aes_linetype_size_shape]{linewidth}} +} +Learn more about setting these aesthetics in \code{vignette("ggplot2-specs", package = "ggplot2")}. + + \code{geom_tile3d()} understands the following aesthetics (required aesthetics are in bold): \itemize{ \item \strong{\code{\link[ggplot2:aes_position]{x}}}