Skip to content

Commit

Permalink
Merge branch 'main' into minor_ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand authored Oct 24, 2023
2 parents f7e8afc + 1b2c312 commit 9676012
Show file tree
Hide file tree
Showing 106 changed files with 4,771 additions and 2,018 deletions.
8 changes: 3 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: ggplot2
Version: 3.4.3.9000
Version: 3.4.4.9000
Title: Create Elegant Data Visualisations Using the Grammar of Graphics
Authors@R: c(
person("Hadley", "Wickham", , "[email protected]", role = "aut",
Expand Down Expand Up @@ -28,7 +28,7 @@ License: MIT + file LICENSE
URL: https://ggplot2.tidyverse.org, https://github.com/tidyverse/ggplot2
BugReports: https://github.com/tidyverse/ggplot2/issues
Depends:
R (>= 3.3)
R (>= 3.5)
Imports:
cli,
glue,
Expand All @@ -54,7 +54,6 @@ Suggests:
knitr,
mapproj,
maps,
maptools,
multcomp,
munsell,
nlme,
Expand All @@ -67,7 +66,7 @@ Suggests:
sf (>= 0.7-3),
svglite (>= 1.2.0.9001),
testthat (>= 3.1.2),
vdiffr (>= 1.0.0),
vdiffr (>= 1.0.6),
xml2
Enhances:
sp
Expand Down Expand Up @@ -272,7 +271,6 @@ Collate:
'utilities-help.R'
'utilities-matrix.R'
'utilities-resolution.R'
'utilities-table.R'
'utilities-tidy-eval.R'
'zxx.R'
'zzz.R'
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export(benchplot)
export(binned_scale)
export(borders)
export(calc_element)
export(check_device)
export(combine_vars)
export(continuous_scale)
export(coord_cartesian)
Expand Down
41 changes: 41 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# ggplot2 (development version)

* Legend titles no longer take up space if they've been removed by setting
`legend.title = element_blank()` (@teunbrand, #3587).

* New function `check_device()` for testing the availability of advanced
graphics features introduced in R 4.1.0 onwards (@teunbrand, #5332).

* Failing to fit or predict in `stat_smooth()` now gives a warning and omits
the failed group, instead of throwing an error (@teunbrand, #5352).

* `resolution()` has a small tolerance, preventing spuriously small resolutions
due to rounding errors (@teunbrand, #2516).

* `stage()` now works correctly, even with aesthetics that do not have scales
(#5408)

* `labeller()` now handles unspecified entries from lookup tables
(@92amartins, #4599).

* `fortify.default()` now accepts a data-frame-like object granted the object
exhibits healthy `dim()`, `colnames()`, and `as.data.frame()` behaviors
(@hpages, #5390).

* `ScaleContinuous$get_breaks()` now only calls `scales::zero_range()` on limits
in transformed space, rather than in data space (#5304).

* Scales throw more informative messages (@teunbrand, #4185, #4258)

* The `scale_name` argument in `continuous_scale()`, `discrete_scale()` and
`binned_scale()` is soft-deprecated (@teunbrand, #1312).

* In `theme()`, some elements can be specified with `rel()` to inherit from
`unit`-class objects in a relative fashion (@teunbrand, #3951).

Expand Down Expand Up @@ -126,6 +156,17 @@
duplicated coordinates (@teunbrand, #5215).
* Improve performance of layers without positional scales (@zeehio, #4990)

# ggplot2 3.4.4

This hotfix release adapts to a change in r-devel's `base::is.atomic()` and
the upcoming retirement of maptools.

* `fortify()` for sp objects (e.g., `SpatialPolygonsDataFrame`) is now deprecated
and will be removed soon in support of [the upcoming retirement of rgdal, rgeos,
and maptools](https://r-spatial.org/r/2023/05/15/evolution4.html). In advance
of the whole removal, `fortify(<SpatialPolygonsDataFrame>, region = ...)`
no longer works as of this version (@yutannihilation, #5244).

# ggplot2 3.4.3
This hotfix release addresses a version comparison change in r-devel. There are
no user-facing or breaking changes.
Expand Down
9 changes: 5 additions & 4 deletions R/aes-evaluation.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ is_calculated <- function(x, warn = FALSE) {
return(TRUE)
}
# Support of old recursive behaviour
if (is.atomic(x)) {
if (is.null(x) || is.atomic(x)) {
FALSE
} else if (is.symbol(x)) {
res <- is_dotted_var(as.character(x))
Expand Down Expand Up @@ -266,7 +266,7 @@ is_staged <- function(x) {

# Strip dots from expressions
strip_dots <- function(expr, env, strip_pronoun = FALSE) {
if (is.atomic(expr)) {
if (is.null(expr) || is.atomic(expr)) {
expr
} else if (is.name(expr)) {
expr_ch <- as.character(expr)
Expand Down Expand Up @@ -311,9 +311,10 @@ strip_stage <- function(expr) {
if (is_call(uq_expr, c("after_stat", "after_scale"))) {
uq_expr[[2]]
} else if (is_call(uq_expr, "stage")) {
uq_expr <- call_match(uq_expr, stage)
# Prefer stat mapping if present, otherwise original mapping (fallback to
# scale mapping) but there should always be two arguments to stage()
uq_expr$after_stat %||% uq_expr$start %||% (if (is.null(uq_expr$after_scale)) uq_expr[[3]]) %||% uq_expr[[2]]
uq_expr$after_stat %||% uq_expr$start %||% uq_expr$after_scale
} else {
expr
}
Expand All @@ -323,7 +324,7 @@ strip_stage <- function(expr) {
make_labels <- function(mapping) {
default_label <- function(aesthetic, mapping) {
# e.g., geom_smooth(aes(colour = "loess")) or aes(y = NULL)
if (is.atomic(mapping)) {
if (is.null(mapping) || is.atomic(mapping)) {
return(aesthetic)
}
mapping <- strip_stage(mapping)
Expand Down
4 changes: 2 additions & 2 deletions R/aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ aes_ <- function(x, y, ...) {
as_quosure_aes <- function(x) {
if (is.formula(x) && length(x) == 2) {
as_quosure(x)
} else if (is.call(x) || is.name(x) || is.atomic(x)) {
} else if (is.null(x) || is.call(x) || is.name(x) || is.atomic(x)) {
new_aesthetic(x, caller_env)
} else {
cli::cli_abort("Aesthetic must be a one-sided formula, call, name, or constant.")
Expand Down Expand Up @@ -436,7 +436,7 @@ extract_target_is_likely_data <- function(x, data, env) {

tryCatch({
data_eval <- eval_tidy(x[[2]], data, env)
identical(data_eval, data)
identical(unrowname(data_eval), unrowname(data))
}, error = function(err) FALSE)
}

Expand Down
2 changes: 1 addition & 1 deletion R/annotation.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @section Unsupported geoms:
#' Due to their special nature, reference line geoms [geom_abline()],
#' [geom_hline()], and [geom_vline()] can't be used with [annotate()].
#' You can use these geoms directory for annotations.
#' You can use these geoms directly for annotations.
#' @param geom name of geom to use for annotation
#' @param x,y,xmin,ymin,xmax,ymax,xend,yend positioning aesthetics -
#' you must specify at least one of these.
Expand Down
3 changes: 2 additions & 1 deletion R/backports.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ if (getRversion() < "3.3") {

on_load(backport_unit_methods())

# isFALSE() is available on R (>=3.5)
# isFALSE() and isTRUE() are available on R (>=3.5)
if (getRversion() < "3.5") {
isFALSE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && !x
isTRUE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && x
}
5 changes: 3 additions & 2 deletions R/coord-.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,18 @@ Coord <- ggproto("Coord",
aesthetics <- c("x", "y", "x.sec", "y.sec")
names(aesthetics) <- aesthetics
is_sec <- grepl("sec$", aesthetics)
scales <- panel_params[aesthetics]

# Do guide setup
guides <- guides$setup(
panel_params, aesthetics,
scales, aesthetics,
default = params$guide_default %||% guide_axis(),
missing = params$guide_missing %||% guide_none()
)
guide_params <- guides$get_params(aesthetics)

# Resolve positions
scale_position <- lapply(panel_params[aesthetics], `[[`, "position")
scale_position <- lapply(scales, `[[`, "position")
guide_position <- lapply(guide_params, `[[`, "position")
guide_position[!is_sec] <- Map(
function(guide, scale) guide %|W|% scale,
Expand Down
2 changes: 1 addition & 1 deletion R/coord-cartesian-.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#'
#' # You can see the same thing with this 2d histogram
#' d <- ggplot(diamonds, aes(carat, price)) +
#' stat_bin2d(bins = 25, colour = "white")
#' stat_bin_2d(bins = 25, colour = "white")
#' d
#'
#' # When zooming the scale, the we get 25 new bins that are the same
Expand Down
15 changes: 10 additions & 5 deletions R/coord-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,24 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
graticule$y_start <- sf_rescale01_x(graticule$y_start, y_range)
graticule$y_end <- sf_rescale01_x(graticule$y_end, y_range)

list(
list2(
x_range = x_range,
y_range = y_range,
graticule = graticule,
crs = params$crs,
default_crs = params$default_crs,
viewscales = viewscales
!!!viewscales
)
},

setup_panel_guides = function(self, panel_params, guides, params = list()) {
params <- Coord$setup_panel_guides(panel_params$viewscales, guides, params)
c(params, panel_params)
train_panel_guides = function(self, panel_params, layers, params = list()) {
# The guide positions are already in the target CRS, so we mask the default
# CRS to prevent a double transformation.
panel_params$guides <- ggproto_parent(Coord, self)$train_panel_guides(
vec_assign(panel_params, "default_crs", panel_params["crs"]),
layers, params
)$guides
panel_params
},

backtransform_range = function(self, panel_params) {
Expand Down
62 changes: 47 additions & 15 deletions R/fortify-spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,31 @@
#' @param ... not used by this method
#' @keywords internal
#' @name fortify.sp
#' @examples
#' if (require("maptools")) {
#' sids <- system.file("shapes/sids.shp", package="maptools")
#' nc1 <- readShapePoly(sids,
#' proj4string = CRS("+proj=longlat +datum=NAD27"))
#' nc1_df <- fortify(nc1)
#' }
NULL

#' @rdname fortify.sp
#' @export
#' @method fortify SpatialPolygonsDataFrame
fortify.SpatialPolygonsDataFrame <- function(model, data, region = NULL, ...) {
deprecate_warn0("3.4.4",
I("`fortify(<SpatialPolygonsDataFrame>)`"),
details = "Please migrate to sf."
)

attr <- as.data.frame(model)
# If not specified, split into regions based on polygons
if (is.null(region)) {
coords <- lapply(model@polygons,fortify)
# Suppress duplicated warnings
withr::with_options(list(lifecycle_verbosity = "quiet"), {
coords <- lapply(model@polygons,fortify)
})
coords <- vec_rbind0(!!!coords)
cli::cli_inform("Regions defined for each Polygons")
} else {
cp <- sp::polygons(model)

# Union together all polygons that make up a region
unioned <- maptools::unionSpatialPolygons(cp, attr[, region])
coords <- fortify(unioned)
coords$order <- 1:nrow(coords)
lifecycle::deprecate_stop("3.4.4",
I("`fortify(<SpatialPolygonsDataFrame>, region = ...)` is defunct'"),
details = "Please migrate to sf."
)
}
coords
}
Expand All @@ -43,14 +42,27 @@ fortify.SpatialPolygonsDataFrame <- function(model, data, region = NULL, ...) {
#' @export
#' @method fortify SpatialPolygons
fortify.SpatialPolygons <- function(model, data, ...) {
polys <- lapply(model@polygons, fortify)
deprecate_warn0("3.4.4",
I("`fortify(<SpatialPolygons>)`"),
details = "Please migrate to sf."
)

# Suppress duplicated warnings
withr::with_options(list(lifecycle_verbosity = "quiet"), {
polys <- lapply(model@polygons, fortify)
})
vec_rbind0(!!!polys)
}

#' @rdname fortify.sp
#' @export
#' @method fortify Polygons
fortify.Polygons <- function(model, data, ...) {
deprecate_warn0("3.4.4",
I("`fortify(<Polygons>)`"),
details = "Please migrate to sf."
)

subpolys <- model@Polygons
pieces <- lapply(seq_along(subpolys), function(i) {
df <- fortify(subpolys[[model@plotOrder[i]]])
Expand All @@ -70,6 +82,11 @@ fortify.Polygons <- function(model, data, ...) {
#' @export
#' @method fortify Polygon
fortify.Polygon <- function(model, data, ...) {
deprecate_warn0("3.4.4",
I("`fortify(<Polygon>)`"),
details = "Please migrate to sf."
)

df <- as.data.frame(model@coords)
names(df) <- c("long", "lat")
df$order <- 1:nrow(df)
Expand All @@ -81,6 +98,11 @@ fortify.Polygon <- function(model, data, ...) {
#' @export
#' @method fortify SpatialLinesDataFrame
fortify.SpatialLinesDataFrame <- function(model, data, ...) {
deprecate_warn0("3.4.4",
I("`fortify(<SpatialLinesDataFrame>)`"),
details = "Please migrate to sf."
)

lines <- lapply(model@lines, fortify)
vec_rbind0(!!!lines)
}
Expand All @@ -89,6 +111,11 @@ fortify.SpatialLinesDataFrame <- function(model, data, ...) {
#' @export
#' @method fortify Lines
fortify.Lines <- function(model, data, ...) {
deprecate_warn0("3.4.4",
I("`fortify(<Lines>)`"),
details = "Please migrate to sf."
)

lines <- model@Lines
pieces <- lapply(seq_along(lines), function(i) {
df <- fortify(lines[[i]])
Expand All @@ -108,6 +135,11 @@ fortify.Lines <- function(model, data, ...) {
#' @export
#' @method fortify Line
fortify.Line <- function(model, data, ...) {
deprecate_warn0("3.4.4",
I("`fortify(<Line>)`"),
details = "Please migrate to sf."
)

df <- as.data.frame(model@coords)
names(df) <- c("long", "lat")
df$order <- 1:nrow(df)
Expand Down
Loading

0 comments on commit 9676012

Please sign in to comment.