diff --git a/R/annotation-logticks.R b/R/annotation-logticks.R index 600bd6ce7c..8ff3a73056 100644 --- a/R/annotation-logticks.R +++ b/R/annotation-logticks.R @@ -93,6 +93,8 @@ annotation_logticks <- function(base = 10, sides = "bl", outside = FALSE, scaled if (!is.null(color)) colour <- color + lifecycle::signal_stage("superseded", "annotation_logticks()", "guide_axis_logticks()") + if (lifecycle::is_present(size)) { deprecate_soft0("3.5.0", I("Using the `size` aesthetic in this geom"), I("`linewidth`")) linewidth <- linewidth %||% size diff --git a/R/coord-flip.R b/R/coord-flip.R index 502ff56f88..df4cad8faf 100644 --- a/R/coord-flip.R +++ b/R/coord-flip.R @@ -57,6 +57,7 @@ #' geom_area() + #' coord_flip() coord_flip <- function(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") { + lifecycle::signal_stage("superseded", "coord_flip()") check_coord_limits(xlim) check_coord_limits(ylim) ggproto(NULL, CoordFlip, diff --git a/R/coord-map.R b/R/coord-map.R index 3ba9260206..0b18b5ce7a 100644 --- a/R/coord-map.R +++ b/R/coord-map.R @@ -136,7 +136,7 @@ coord_map <- function(projection="mercator", ..., parameters = NULL, orientation } else { params <- parameters } - + lifecycle::signal_stage("superseded", "coord_map()", "coord_sf()") check_coord_limits(xlim) check_coord_limits(ylim) diff --git a/R/coord-polar.R b/R/coord-polar.R index b8855f52b9..81fd137c6d 100644 --- a/R/coord-polar.R +++ b/R/coord-polar.R @@ -1,69 +1,9 @@ -#' Polar coordinates -#' -#' The polar coordinate system is most commonly used for pie charts, which -#' are a stacked bar chart in polar coordinates. `coord_radial()` has extended -#' options. -#' -#' @param theta variable to map angle to (`x` or `y`) -#' @param start Offset of starting point from 12 o'clock in radians. Offset -#' is applied clockwise or anticlockwise depending on value of `direction`. -#' @param direction 1, clockwise; -1, anticlockwise -#' @param clip Should drawing be clipped to the extent of the plot panel? A -#' setting of `"on"` (the default) means yes, and a setting of `"off"` -#' means no. For details, please see [`coord_cartesian()`]. +#' @rdname coord_radial #' @export -#' @seealso -#' The `r link_book("polar coordinates section", "coord#polar-coordinates-with-coord_polar")` -#' @examples -#' # NOTE: Use these plots with caution - polar coordinates has -#' # major perceptual problems. The main point of these examples is -#' # to demonstrate how these common plots can be described in the -#' # grammar. Use with EXTREME caution. -#' -#' # A pie chart = stacked bar chart + polar coordinates -#' pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) + -#' geom_bar(width = 1) -#' pie + coord_polar(theta = "y") -#' -#' \donttest{ -#' -#' # A coxcomb plot = bar chart + polar coordinates -#' cxc <- ggplot(mtcars, aes(x = factor(cyl))) + -#' geom_bar(width = 1, colour = "black") -#' cxc + coord_polar() -#' # A new type of plot? -#' cxc + coord_polar(theta = "y") -#' -#' # The bullseye chart -#' pie + coord_polar() -#' -#' # Hadley's favourite pie chart -#' df <- data.frame( -#' variable = c("does not resemble", "resembles"), -#' value = c(20, 80) -#' ) -#' ggplot(df, aes(x = "", y = value, fill = variable)) + -#' geom_col(width = 1) + -#' scale_fill_manual(values = c("red", "yellow")) + -#' coord_polar("y", start = pi / 3) + -#' labs(title = "Pac man") -#' -#' # Windrose + doughnut plot -#' if (require("ggplot2movies")) { -#' movies$rrating <- cut_interval(movies$rating, length = 1) -#' movies$budgetq <- cut_number(movies$budget, 4) -#' -#' doh <- ggplot(movies, aes(x = rrating, fill = budgetq)) -#' -#' # Wind rose -#' doh + geom_bar(width = 1) + coord_polar() -#' # Race track plot -#' doh + geom_bar(width = 0.9, position = "fill") + coord_polar(theta = "y") -#' } -#' } coord_polar <- function(theta = "x", start = 0, direction = 1, clip = "on") { theta <- arg_match0(theta, c("x", "y")) r <- if (theta == "x") "y" else "x" + lifecycle::signal_stage("superseded", "coord_polar()", "coord_radial()") ggproto(NULL, CoordPolar, theta = theta, diff --git a/R/coord-radial.R b/R/coord-radial.R index 3cef9c2b5b..dc3b1abf21 100644 --- a/R/coord-radial.R +++ b/R/coord-radial.R @@ -1,6 +1,17 @@ - -#' @rdname coord_polar +#' Polar coordinates +#' +#' The polar coordinate system is most commonly used for pie charts, which +#' are a stacked bar chart in polar coordinates. \cr +#' `r lifecycle::badge("superseded")`: `coord_polar()` has been in favour of +#' `coord_radial()`. #' +#' @param theta variable to map angle to (`x` or `y`) +#' @param start Offset of starting point from 12 o'clock in radians. Offset +#' is applied clockwise or anticlockwise depending on value of `direction`. +#' @param direction 1, clockwise; -1, anticlockwise +#' @param clip Should drawing be clipped to the extent of the plot panel? A +#' setting of `"on"` (the default) means yes, and a setting of `"off"` +#' means no. For details, please see [`coord_cartesian()`]. #' @param end Position from 12 o'clock in radians where plot ends, to allow #' for partial polar coordinates. The default, `NULL`, is set to #' `start + 2 * pi`. @@ -26,7 +37,7 @@ #' (default) keep directions as is. `"theta"` reverses the angle and `"r"` #' reverses the radius. `"thetar"` reverses both the angle and the radius. #' @param r_axis_inside,rotate_angle `r lifecycle::badge("deprecated")` -#' +#' @export #' @note #' In `coord_radial()`, position guides can be defined by using #' `guides(r = ..., theta = ..., r.sec = ..., theta.sec = ...)`. Note that @@ -35,8 +46,56 @@ #' be used for the `theta` positions. Using the `theta.sec` position is only #' sensible when `inner.radius > 0`. #' -#' @export +#' @seealso +#' The `r link_book("polar coordinates section", "coord#polar-coordinates-with-coord_polar")` #' @examples +#' # NOTE: Use these plots with caution - polar coordinates has +#' # major perceptual problems. The main point of these examples is +#' # to demonstrate how these common plots can be described in the +#' # grammar. Use with EXTREME caution. +#' +#' # A pie chart = stacked bar chart + polar coordinates +#' pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) + +#' geom_bar(width = 1) +#' pie + coord_radial(theta = "y", expand = FALSE) +#' +#' \donttest{ +#' +#' # A coxcomb plot = bar chart + polar coordinates +#' cxc <- ggplot(mtcars, aes(x = factor(cyl))) + +#' geom_bar(width = 1, colour = "black") +#' cxc + coord_radial(expand = FALSE) +#' # A new type of plot? +#' cxc + coord_radial(theta = "y", expand = FALSE) +#' +#' # The bullseye chart +#' pie + coord_radial(expand = FALSE) +#' +#' # Hadley's favourite pie chart +#' df <- data.frame( +#' variable = c("does not resemble", "resembles"), +#' value = c(20, 80) +#' ) +#' ggplot(df, aes(x = "", y = value, fill = variable)) + +#' geom_col(width = 1) + +#' scale_fill_manual(values = c("red", "yellow")) + +#' coord_radial("y", start = pi / 3, expand = FALSE) + +#' labs(title = "Pac man") +#' +#' # Windrose + doughnut plot +#' if (require("ggplot2movies")) { +#' movies$rrating <- cut_interval(movies$rating, length = 1) +#' movies$budgetq <- cut_number(movies$budget, 4) +#' +#' doh <- ggplot(movies, aes(x = rrating, fill = budgetq)) +#' +#' # Wind rose +#' doh + geom_bar(width = 1) + coord_radial(expand = FALSE) +#' # Race track plot +#' doh + geom_bar(width = 0.9, position = "fill") + +#' coord_radial(theta = "y", expand = FALSE) +#' } +#' } #' # A partial polar plot #' ggplot(mtcars, aes(disp, mpg)) + #' geom_point() + @@ -475,7 +534,7 @@ CoordRadial <- ggproto("CoordRadial", Coord, } ) -view_scales_polar <- function(scale, theta = "x", coord_limits = NULL, +view_scales_polar <- function(scale, theta = "x", coord_limits = NULL, expand = TRUE) { aesthetic <- scale$aesthetics[1] diff --git a/R/facet-wrap.R b/R/facet-wrap.R index e1eda21cdb..2c8fcbc2de 100644 --- a/R/facet-wrap.R +++ b/R/facet-wrap.R @@ -45,6 +45,11 @@ NULL #' the exterior axes get labels, and the interior axes get none. When #' `"all_x"` or `"all_y"`, only draws the labels at the interior axes in the #' x- or y-direction respectively. +#' @param as.table `r lifecycle::badge("superseded")` The `as.table` argument +#' is now absorbed into the `dir` argument via the two letter options. +#' If `TRUE`, the facets are laid out like a table with highest values at the +#' bottom-right. If `FALSE`, the facets are laid out like a plot with the +#' highest value at the top-right. #' #' @section Layer layout: #' The [`layer(layout)`][layer()] argument in context of `facet_wrap()` can take diff --git a/R/labels.R b/R/labels.R index 27c1e96de6..7b113ee694 100644 --- a/R/labels.R +++ b/R/labels.R @@ -200,19 +200,26 @@ labs <- function(..., title = waiver(), subtitle = waiver(), caption = waiver(), #' @rdname labs #' @export +#' @description +#' `r lifecycle::badge("superseded")`: `xlab()`, `ylab()` and `ggtitle()` are +#' superseded. It is recommended to use the `labs(x, y, title, subtitle)` +#' arguments instead. xlab <- function(label) { + lifecycle::signal_stage("superseded", "xlab()", "labs(x)") labs(x = label) } #' @rdname labs #' @export ylab <- function(label) { + lifecycle::signal_stage("superseded", "ylab()", "labs(y)") labs(y = label) } #' @rdname labs #' @export ggtitle <- function(label, subtitle = waiver()) { + lifecycle::signal_stage("superseded", "ggtitle()", I("labs(title, subtitle)")) labs(title = label, subtitle = subtitle) } diff --git a/R/limits.R b/R/limits.R index 57f2465018..976307a467 100644 --- a/R/limits.R +++ b/R/limits.R @@ -159,6 +159,9 @@ limits.POSIXlt <- function(lims, var, call = caller_env()) { #' Expand the plot limits, using data #' +#' `r lifecycle::badge("superseded")`: It is recommended to pass a function to +#' the `limits` argument in scales instead. For example: +#' `scale_x_continuous(limits = ~range(.x, 0))` to include zero.\cr\cr #' Sometimes you may want to ensure limits include a single value, for all #' panels or all plots. This function is a thin wrapper around #' [geom_blank()] that makes it easy to add such values. @@ -181,6 +184,8 @@ limits.POSIXlt <- function(lims, var, call = caller_env()) { expand_limits <- function(...) { data <- list2(...) + lifecycle::signal_stage("superseded", "expand_limits()") + # unpack data frame columns data_dfs <- vapply(data, is.data.frame, logical(1)) data <- unlist(c(list(data[!data_dfs]), data[data_dfs]), recursive = FALSE) diff --git a/R/scale-colour.R b/R/scale-colour.R index c8c468559f..2580e57211 100644 --- a/R/scale-colour.R +++ b/R/scale-colour.R @@ -7,21 +7,13 @@ #' functions that assign discrete color bins to the continuous values #' instead of using a continuous color spectrum. #' -#' All these colour scales use the [options()] mechanism to determine -#' default settings. Continuous colour scales default to the values of the -#' `ggplot2.continuous.colour` and `ggplot2.continuous.fill` options, and -#' binned colour scales default to the values of the `ggplot2.binned.colour` -#' and `ggplot2.binned.fill` options. These option values default to -#' `"gradient"`, which means that the scale functions actually used are -#' [scale_colour_gradient()]/[scale_fill_gradient()] for continuous scales and -#' [scale_colour_steps()]/[scale_fill_steps()] for binned scales. -#' Alternative option values are `"viridis"` or a different scale function. -#' See description of the `type` argument for details. -#' -#' Note that the binned colour scales will use the settings of -#' `ggplot2.continuous.colour` and `ggplot2.continuous.fill` as fallback, -#' respectively, if `ggplot2.binned.colour` or `ggplot2.binned.fill` are -#' not set. +#' `r lifecycle::badge("superseded")`: The mechanism of setting defaults via +#' [options()] is superseded by theme settings. The preferred method to change +#' the default palette of scales is via the theme, for example: +#' `theme(palette.colour.continuous = scales::pal_viridis())`. The +#' `ggplot2.continuous.colour` and `ggplot2.continuous.fill` options could be +#' used to set default continuous scales and `ggplot2.binned.colour` and +#' `ggplot2.binned.fill` options to set default binned scales. #' #' These scale functions are meant to provide simple defaults. If #' you want to manually set the colors of a scale, consider using @@ -35,7 +27,7 @@ #' * a palette function that when called with a numeric vector with values #' between 0 and 1 returns the corresponding output values. #' @param ... Additional parameters passed on to the scale type -#' @param type One of the following: +#' @param type `r lifecycle::badge("superseded")` One of the following: #' * "gradient" (the default) #' * "viridis" #' * A function that returns a continuous colour scale. @@ -173,9 +165,7 @@ scale_fill_binned <- function(..., palette = NULL, aesthetics = "fill", guide = #' Discrete colour scales #' -#' The default discrete colour scale. Defaults to [scale_fill_hue()]/[scale_fill_brewer()] -#' unless `type` (which defaults to the `ggplot2.discrete.fill`/`ggplot2.discrete.colour` options) -#' is specified. +#' The default discrete colour scale. #' #' @param palette One of the following: #' * `NULL` for the default palette stored in the theme. @@ -185,7 +175,9 @@ scale_fill_binned <- function(..., palette = NULL, aesthetics = "fill", guide = #' number of levels in the scale) returns the values that they should take. #' @param ... Additional parameters passed on to the scale type, #' @inheritParams discrete_scale -#' @param type One of the following: +#' @param type `r lifecycle::badge("superseded")` The preferred mechanism for +#' setting the default palette is by using the theme. For example: +#' `theme(palette.colour.discrete = "Okabe-Ito")`. One of the following: #' * A character vector of color codes. The codes are used for a 'manual' color #' scale as long as the number of codes exceeds the number of data levels #' (if there are more levels than codes, [scale_colour_hue()]/[scale_fill_hue()] diff --git a/man/coord_polar.Rd b/man/coord_radial.Rd similarity index 88% rename from man/coord_polar.Rd rename to man/coord_radial.Rd index 3bc579bcbc..a3678cc13f 100644 --- a/man/coord_polar.Rd +++ b/man/coord_radial.Rd @@ -73,8 +73,9 @@ reverses the radius. \code{"thetar"} reverses both the angle and the radius.} } \description{ The polar coordinate system is most commonly used for pie charts, which -are a stacked bar chart in polar coordinates. \code{coord_radial()} has extended -options. +are a stacked bar chart in polar coordinates. \cr +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}: \code{coord_polar()} has been in favour of +\code{coord_radial()}. } \note{ In \code{coord_radial()}, position guides can be defined by using @@ -93,19 +94,19 @@ sensible when \code{inner.radius > 0}. # A pie chart = stacked bar chart + polar coordinates pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) + geom_bar(width = 1) -pie + coord_polar(theta = "y") +pie + coord_radial(theta = "y", expand = FALSE) \donttest{ # A coxcomb plot = bar chart + polar coordinates cxc <- ggplot(mtcars, aes(x = factor(cyl))) + geom_bar(width = 1, colour = "black") -cxc + coord_polar() +cxc + coord_radial(expand = FALSE) # A new type of plot? -cxc + coord_polar(theta = "y") +cxc + coord_radial(theta = "y", expand = FALSE) # The bullseye chart -pie + coord_polar() +pie + coord_radial(expand = FALSE) # Hadley's favourite pie chart df <- data.frame( @@ -115,7 +116,7 @@ df <- data.frame( ggplot(df, aes(x = "", y = value, fill = variable)) + geom_col(width = 1) + scale_fill_manual(values = c("red", "yellow")) + - coord_polar("y", start = pi / 3) + + coord_radial("y", start = pi / 3, expand = FALSE) + labs(title = "Pac man") # Windrose + doughnut plot @@ -126,9 +127,10 @@ movies$budgetq <- cut_number(movies$budget, 4) doh <- ggplot(movies, aes(x = rrating, fill = budgetq)) # Wind rose -doh + geom_bar(width = 1) + coord_polar() +doh + geom_bar(width = 1) + coord_radial(expand = FALSE) # Race track plot -doh + geom_bar(width = 0.9, position = "fill") + coord_polar(theta = "y") +doh + geom_bar(width = 0.9, position = "fill") + + coord_radial(theta = "y", expand = FALSE) } } # A partial polar plot diff --git a/man/expand_limits.Rd b/man/expand_limits.Rd index 5ee0b35141..6248c3c2e4 100644 --- a/man/expand_limits.Rd +++ b/man/expand_limits.Rd @@ -11,6 +11,9 @@ expand_limits(...) should be included in each scale.} } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}: It is recommended to pass a function to +the \code{limits} argument in scales instead. For example: +\code{scale_x_continuous(limits = ~range(.x, 0))} to include zero.\cr\cr Sometimes you may want to ensure limits include a single value, for all panels or all plots. This function is a thin wrapper around \code{\link[=geom_blank]{geom_blank()}} that makes it easy to add such values. diff --git a/man/facet_wrap.Rd b/man/facet_wrap.Rd index 4cfcf1284e..10302c35f4 100644 --- a/man/facet_wrap.Rd +++ b/man/facet_wrap.Rd @@ -58,9 +58,11 @@ functions for different kind of labels, for example use \code{\link[=label_parse formatting facet labels. \code{\link[=label_value]{label_value()}} is used by default, check it for more details and pointers to other options.} -\item{as.table}{If \code{TRUE}, the default, the facets are laid out like -a table with highest values at the bottom-right. If \code{FALSE}, the -facets are laid out like a plot with the highest value at the top-right.} +\item{as.table}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{as.table} argument +is now absorbed into the \code{dir} argument via the two letter options. +If \code{TRUE}, the facets are laid out like a table with highest values at the +bottom-right. If \code{FALSE}, the facets are laid out like a plot with the +highest value at the top-right.} \item{switch}{By default, the labels are displayed on the top and right of the plot. If \code{"x"}, the top labels will be diff --git a/man/labs.Rd b/man/labs.Rd index 18cd7690f6..3b97fa9c52 100644 --- a/man/labs.Rd +++ b/man/labs.Rd @@ -64,6 +64,10 @@ main findings. It's common to use the \code{caption} to provide information about the data source. \code{tag} can be used for adding identification tags to differentiate between multiple plots. +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}: \code{xlab()}, \code{ylab()} and \code{ggtitle()} are +superseded. It is recommended to use the \code{labs(x, y, title, subtitle)} +arguments instead. + \code{get_labs()} retrieves completed labels from a plot. } \details{ diff --git a/man/scale_colour_continuous.Rd b/man/scale_colour_continuous.Rd index b7b482cb92..d9ab49b684 100644 --- a/man/scale_colour_continuous.Rd +++ b/man/scale_colour_continuous.Rd @@ -64,7 +64,7 @@ between 0 and 1 returns the corresponding output values. \item{na.value}{Missing values will be replaced with this value.} -\item{type}{One of the following: +\item{type}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} One of the following: \itemize{ \item "gradient" (the default) \item "viridis" @@ -80,21 +80,13 @@ functions that assign discrete color bins to the continuous values instead of using a continuous color spectrum. } \details{ -All these colour scales use the \code{\link[=options]{options()}} mechanism to determine -default settings. Continuous colour scales default to the values of the -\code{ggplot2.continuous.colour} and \code{ggplot2.continuous.fill} options, and -binned colour scales default to the values of the \code{ggplot2.binned.colour} -and \code{ggplot2.binned.fill} options. These option values default to -\code{"gradient"}, which means that the scale functions actually used are -\code{\link[=scale_colour_gradient]{scale_colour_gradient()}}/\code{\link[=scale_fill_gradient]{scale_fill_gradient()}} for continuous scales and -\code{\link[=scale_colour_steps]{scale_colour_steps()}}/\code{\link[=scale_fill_steps]{scale_fill_steps()}} for binned scales. -Alternative option values are \code{"viridis"} or a different scale function. -See description of the \code{type} argument for details. - -Note that the binned colour scales will use the settings of -\code{ggplot2.continuous.colour} and \code{ggplot2.continuous.fill} as fallback, -respectively, if \code{ggplot2.binned.colour} or \code{ggplot2.binned.fill} are -not set. +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}: The mechanism of setting defaults via +\code{\link[=options]{options()}} is superseded by theme settings. The preferred method to change +the default palette of scales is via the theme, for example: +\code{theme(palette.colour.continuous = scales::pal_viridis())}. The +\code{ggplot2.continuous.colour} and \code{ggplot2.continuous.fill} options could be +used to set default continuous scales and \code{ggplot2.binned.colour} and +\code{ggplot2.binned.fill} options to set default binned scales. These scale functions are meant to provide simple defaults. If you want to manually set the colors of a scale, consider using diff --git a/man/scale_colour_discrete.Rd b/man/scale_colour_discrete.Rd index c86fd7b33c..87c8ad6f1c 100644 --- a/man/scale_colour_discrete.Rd +++ b/man/scale_colour_discrete.Rd @@ -40,7 +40,9 @@ number of levels in the scale) returns the values that they should take. missing values be displayed as? Does not apply to position scales where \code{NA} is always placed at the far right.} -\item{type}{One of the following: +\item{type}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The preferred mechanism for +setting the default palette is by using the theme. For example: +\code{theme(palette.colour.discrete = "Okabe-Ito")}. One of the following: \itemize{ \item A character vector of color codes. The codes are used for a 'manual' color scale as long as the number of codes exceeds the number of data levels @@ -56,9 +58,7 @@ want to change the color palette based on the number of levels. }} } \description{ -The default discrete colour scale. Defaults to \code{\link[=scale_fill_hue]{scale_fill_hue()}}/\code{\link[=scale_fill_brewer]{scale_fill_brewer()}} -unless \code{type} (which defaults to the \code{ggplot2.discrete.fill}/\code{ggplot2.discrete.colour} options) -is specified. +The default discrete colour scale. } \examples{ # A standard plot