Skip to content

Commit

Permalink
Merge branch 'main' into facet_character_drop
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Apr 29, 2024
2 parents 9b2e5b9 + 09bcda6 commit 6912a49
Show file tree
Hide file tree
Showing 66 changed files with 970 additions and 3,585 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: ggplot2
Version: 3.5.0.9000
Version: 3.5.1.9000
Title: Create Elegant Data Visualisations Using the Grammar of Graphics
Authors@R: c(
person("Hadley", "Wickham", , "hadley@posit.co", role = "aut",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export(get_alt_text)
export(get_element_tree)
export(get_guide_data)
export(gg_dep)
export(ggpar)
export(ggplot)
export(ggplotGrob)
export(ggplot_add)
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NEW FEATURES
`example(position_jitterdodge)` for a potential usage. (@kevinushey, #932)

* Allow specifying only one of the limits in a scale and use the automatic
calculation of the other limit by passing NA to to the limit function,
calculation of the other limit by passing NA to the limit function,
`xlim()` or `ylim()` (@jimhester, #557).

* Allow to use brewer palettes for continuous scales, through the new
Expand Down
50 changes: 37 additions & 13 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@

# ggplot2 (development version)

* Prevented `facet_wrap(..., drop = FALSE)` from throwing spurious errors when
a character facetting variable contained `NA`s (@teunbrand, #5485).
* When facets coerce the faceting variables to factors, the 'ordered' class
is dropped (@teunbrand, #5666).
* `geom_curve()` now appropriately removes missing data instead of throwing
errors (@teunbrand, #5831).
* `update_geom_defaults()` and `update_stat_defaults()` have a reset mechanism
when using `new = NULL` and invisible return the previous defaults (#4993).
* Fixed regression in axes where `breaks = NULL` caused the axes to disappear
instead of just rendering the axis line (@teunbrand, #5816).
* `geom_point()` can be dodged vertically by using
`position_dodge(..., orientation = "y")` (@teunbrand, #5809).
* Fixed bug where `na.value` was incorrectly mapped to non-`NA` values
(@teunbrand, #5756).
* Fixed bug in `guide_custom()` that would throw error with `theme_void()`
(@teunbrand, #5856).
* New helper function `ggpar()` to translate ggplot2's interpretation of
graphical parameters to {grid}'s interpretation (@teunbrand, #5866).

# ggplot2 3.5.1

This is a small release focusing on fixing regressions from 3.5.0 and
documentation updates.

## Bug fixes

* Fixed bug where discrete scales could not map aesthetics only consisting of
`NA`s (#5623)
* Fixed spurious warnings from `sec_axis()` with `breaks = NULL` (#5713).
* Patterns and gradients are now also enabled in `geom_sf()`
(@teunbrand, #5716).
* The default behaviour of `resolution()` has been reverted to pre-3.5.0
behaviour. Whether mapped discrete vectors should be treated as having
resolution of 1 is controlled by the new `discrete` argument.
* Fixed bug in `guide_bins()` and `guide_coloursteps()` where discrete breaks,
such as the levels produced by `cut()`, were ordered incorrectly
(@teunbrand, #5757).

## Improvements

* When facets coerce the faceting variables to factors, the 'ordered' class
is dropped (@teunbrand, #5666).
* `coord_map()` and `coord_polar()` throw informative warnings when used
with the guide system (#5707).
* When passing a function to `stat_contour(breaks)`, that function is used to
Expand All @@ -15,23 +50,12 @@
* `geom_step()` now supports `lineend`, `linejoin` and `linemitre` parameters
(@teunbrand, #5705).
* Fixed performance loss when the `.data` pronoun is used in `aes()` (#5730).
* Fixed bug where discrete scales could not map aesthetics only consisting of
`NA`s (#5623)
* Facet evaluation is better at dealing with inherited errors
(@teunbrand, #5670).
* Fixed spurious warnings from `sec_axis()` with `breaks = NULL` (#5713).
* Patterns and gradients are now also enabled in `geom_sf()`
(@teunbrand, #5716).
* `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665).
* While axes in `coord_radial()` don't neatly fit the top/right/bottom/left
organisation, specifying `position = "top"` or `position = "right"`
in the scale will flip the placement of the radial axis (#5735)
* The default behaviour of `resolution()` has been reverted to pre-3.5.0
behaviour. Whether mapped discrete vectors should be treated as having
resolution of 1 is controlled by the new `discrete` argument.
* Fixed bug in `guide_bins()` and `guide_coloursteps()` where discrete breaks,
such as the levels produced by `cut()`, were ordered incorrectly
(@teunbrand, #5757).
* Theme elements that do not exist now throw warnings instead of errors (#5719).
* Fixed bug in `coord_radial()` where full circles were not treated as such
(@teunbrand, #5750).
Expand Down Expand Up @@ -1472,7 +1496,7 @@ accompanying issue #2890.

We recognise that this is a big change and if you're not already familiar
with rlang, there's a lot to learn. If you are stuck, or need any help,
please reach out on <https://community.rstudio.com>.
please reach out on <https://forum.posit.co/>.

* Error: Column `y` must be a 1d atomic vector or a list

Expand Down
8 changes: 4 additions & 4 deletions R/annotation-logticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
ticks$x_b <- with(data, segmentsGrob(
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
y0 = unit(xticks$start, "cm"), y1 = unit(xticks$end, "cm"),
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
gp = ggpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
))
}
if (grepl("t", sides) && nrow(xticks) > 0) {
ticks$x_t <- with(data, segmentsGrob(
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
y0 = unit(1, "npc") - unit(xticks$start, "cm"), y1 = unit(1, "npc") - unit(xticks$end, "cm"),
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
gp = ggpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
))
}
}
Expand Down Expand Up @@ -213,14 +213,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
ticks$y_l <- with(data, segmentsGrob(
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
x0 = unit(yticks$start, "cm"), x1 = unit(yticks$end, "cm"),
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
gp = ggpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
))
}
if (grepl("r", sides) && nrow(yticks) > 0) {
ticks$y_r <- with(data, segmentsGrob(
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
x0 = unit(1, "npc") - unit(yticks$start, "cm"), x1 = unit(1, "npc") - unit(yticks$end, "cm"),
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
gp = ggpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
))
}
}
Expand Down
4 changes: 2 additions & 2 deletions R/annotation-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ GeomAnnotationMap <- ggproto("GeomAnnotationMap", GeomMap,

polygonGrob(coords$x, coords$y, default.units = "native",
id = grob_id,
gp = gpar(
gp = ggpar(
col = data$colour, fill = alpha(data$fill, data$alpha),
lwd = data$linewidth * .pt)
lwd = data$linewidth)
)
},

Expand Down
4 changes: 2 additions & 2 deletions R/coord-radial.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ CoordRadial <- ggproto("CoordRadial", Coord,
y = c(Inf, -Inf, -Inf, Inf)
)
background <- coord_munch(self, background, panel_params, is_closed = TRUE)
bg_gp <- gpar(
lwd = len0_null(bg_element$linewidth * .pt),
bg_gp <- ggpar(
lwd = bg_element$linewidth,
col = bg_element$colour, fill = bg_element$fill,
lty = bg_element$linetype
)
Expand Down
4 changes: 2 additions & 2 deletions R/coord-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
if (inherits(el, "element_blank")) {
grobs <- list(element_render(theme, "panel.background"))
} else {
line_gp <- gpar(
line_gp <- ggpar(
col = el$colour,
lwd = len0_null(el$linewidth * .pt),
lwd = el$linewidth,
lty = el$linetype
)
grobs <- c(
Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
#' Housing sales in TX
#'
#' Information about the housing market in Texas provided by the TAMU
#' real estate center, \url{https://www.recenter.tamu.edu/}.
#' real estate center, \url{https://trerc.tamu.edu/}.
#'
#' @format A data frame with 8602 observations and 9 variables:
#' \describe{
Expand Down
9 changes: 7 additions & 2 deletions R/geom-curve.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ GeomCurve <- ggproto("GeomCurve", GeomSegment,
if (!coord$is_linear()) {
cli::cli_warn("{.fn geom_curve} is not implemented for non-linear coordinates")
}
data <- remove_missing(
data, na.rm = na.rm,
c("x", "y", "xend", "yend", "linetype", "linewidth"),
name = "geom_curve"
)

trans <- coord$transform(data, panel_params)

Expand All @@ -57,10 +62,10 @@ GeomCurve <- ggproto("GeomCurve", GeomSegment,
default.units = "native",
curvature = curvature, angle = angle, ncp = ncp,
square = FALSE, squareShape = 1, inflect = FALSE, open = TRUE,
gp = gpar(
gp = ggpar(
col = alpha(trans$colour, trans$alpha),
fill = alpha(arrow.fill, trans$alpha),
lwd = trans$linewidth * .pt,
lwd = trans$linewidth,
lty = trans$linetype,
lineend = lineend),
arrow = arrow
Expand Down
4 changes: 2 additions & 2 deletions R/geom-dotplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
dotstackGrob(stackaxis = stackaxis, x = tdata$x, y = tdata$y, dotdia = dotdianpc,
stackposition = tdata$stackpos, stackdir = stackdir, stackratio = stackratio,
default.units = "npc",
gp = gpar(col = alpha(tdata$colour, tdata$alpha),
gp = ggpar(col = alpha(tdata$colour, tdata$alpha),
fill = fill_alpha(tdata$fill, tdata$alpha),
lwd = tdata$stroke, lty = tdata$linetype,
lwd = tdata$stroke / .pt, lty = tdata$linetype,
lineend = lineend))
)
},
Expand Down
4 changes: 2 additions & 2 deletions R/geom-hex.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ GeomHex <- ggproto("GeomHex", Geom,

ggname("geom_hex", polygonGrob(
coords$x, coords$y,
gp = gpar(
gp = ggpar(
col = data$colour,
fill = fill_alpha(data$fill, data$alpha),
lwd = data$linewidth * .pt,
lwd = data$linewidth,
lty = data$linetype,
lineend = lineend,
linejoin = linejoin,
Expand Down
10 changes: 5 additions & 5 deletions R/geom-label.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ GeomLabel <- ggproto("GeomLabel", Geom,
padding = label.padding,
r = label.r,
angle = row$angle,
text.gp = gpar(
text.gp = ggpar(
col = row$colour,
fontsize = row$size * size.unit,
fontfamily = row$family,
fontface = row$fontface,
lineheight = row$lineheight
),
rect.gp = gpar(
rect.gp = ggpar(
col = if (isTRUE(all.equal(label.size, 0))) NA else row$colour,
fill = fill_alpha(row$fill, row$alpha),
lwd = label.size * .pt
lwd = label.size
)
)
})
Expand All @@ -115,7 +115,7 @@ GeomLabel <- ggproto("GeomLabel", Geom,
labelGrob <- function(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"),
just = "center", padding = unit(0.25, "lines"), r = unit(0.1, "snpc"),
angle = NULL, default.units = "npc", name = NULL,
text.gp = gpar(), rect.gp = gpar(fill = "white"), vp = NULL) {
text.gp = gpar(), rect.gp = ggpar(fill = "white"), vp = NULL) {

if (length(label) != 1) {
cli::cli_abort("{.arg label} must be of length 1.")
Expand All @@ -130,7 +130,7 @@ labelGrob <- function(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"),
vp <- viewport(
angle = angle, x = x, y = y,
width = unit(0, "cm"), height = unit(0, "cm"),
gp = gpar(fontsize = text.gp$fontsize)
gp = ggpar(fontsize = text.gp$fontsize)
)
x <- unit(rep(0.5, length(x)), "npc")
y <- unit(rep(0.5, length(y)), "npc")
Expand Down
4 changes: 2 additions & 2 deletions R/geom-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ GeomMap <- ggproto("GeomMap", GeomPolygon,
data <- data[data_rows, , drop = FALSE]

polygonGrob(coords$x, coords$y, default.units = "native", id = grob_id,
gp = gpar(
gp = ggpar(
col = data$colour,
fill = fill_alpha(data$fill, data$alpha),
lwd = data$linewidth * .pt,
lwd = data$linewidth,
lineend = lineend,
linejoin = linejoin,
linemitre = linemitre
Expand Down
8 changes: 4 additions & 4 deletions R/geom-path.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ GeomPath <- ggproto("GeomPath", Geom,
segmentsGrob(
munched$x[!end], munched$y[!end], munched$x[!start], munched$y[!start],
default.units = "native", arrow = arrow,
gp = gpar(
gp = ggpar(
col = alpha(munched$colour, munched$alpha)[!end],
fill = alpha(munched$colour, munched$alpha)[!end],
lwd = munched$linewidth[!end] * .pt,
lwd = munched$linewidth[!end],
lty = munched$linetype[!end],
lineend = lineend,
linejoin = linejoin,
Expand All @@ -215,10 +215,10 @@ GeomPath <- ggproto("GeomPath", Geom,
polylineGrob(
munched$x, munched$y, id = id,
default.units = "native", arrow = arrow,
gp = gpar(
gp = ggpar(
col = alpha(munched$colour, munched$alpha)[start],
fill = alpha(munched$colour, munched$alpha)[start],
lwd = munched$linewidth[start] * .pt,
lwd = munched$linewidth[start],
lty = munched$linetype[start],
lineend = lineend,
linejoin = linejoin,
Expand Down
11 changes: 4 additions & 7 deletions R/geom-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' `geom_point(alpha = 0.05)`) or very small (e.g.
#' `geom_point(shape = ".")`).
#'
#' @eval rd_aesthetics("geom", "point")
#' @eval rd_aesthetics("geom", "point", "The `fill` aesthetic only applies to shapes 21-25.")
#' @inheritParams layer
#' @param na.rm If `FALSE`, the default, missing values are removed with
#' a warning. If `TRUE`, missing values are silently removed.
Expand Down Expand Up @@ -145,18 +145,15 @@ GeomPoint <- ggproto("GeomPoint", Geom,
}

coords <- coord$transform(data, panel_params)
stroke_size <- coords$stroke
stroke_size[is.na(stroke_size)] <- 0
ggname("geom_point",
pointsGrob(
coords$x, coords$y,
pch = coords$shape,
gp = gpar(
gp = ggpar(
col = alpha(coords$colour, coords$alpha),
fill = fill_alpha(coords$fill, coords$alpha),
# Stroke is added around the outside of the point
fontsize = coords$size * .pt + stroke_size * .stroke / 2,
lwd = coords$stroke * .stroke / 2
pointsize = coords$size,
stroke = coords$stroke
)
)
)
Expand Down
8 changes: 4 additions & 4 deletions R/geom-polygon.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ GeomPolygon <- ggproto("GeomPolygon", Geom,
polygonGrob(
munched$x, munched$y, default.units = "native",
id = munched$group,
gp = gpar(
gp = ggpar(
col = first_rows$colour,
fill = fill_alpha(first_rows$fill, first_rows$alpha),
lwd = first_rows$linewidth * .pt,
lwd = first_rows$linewidth,
lty = first_rows$linetype,
lineend = lineend,
linejoin = linejoin,
Expand Down Expand Up @@ -161,10 +161,10 @@ GeomPolygon <- ggproto("GeomPolygon", Geom,
munched$x, munched$y, default.units = "native",
id = id, pathId = munched$group,
rule = rule,
gp = gpar(
gp = ggpar(
col = first_rows$colour,
fill = fill_alpha(first_rows$fill, first_rows$alpha),
lwd = first_rows$linewidth * .pt,
lwd = first_rows$linewidth,
lty = first_rows$linetype,
lineend = lineend,
linejoin = linejoin,
Expand Down
4 changes: 2 additions & 2 deletions R/geom-rect.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ GeomRect <- ggproto("GeomRect", Geom,
height = coords$ymax - coords$ymin,
default.units = "native",
just = c("left", "top"),
gp = gpar(
gp = ggpar(
col = coords$colour,
fill = fill_alpha(coords$fill, coords$alpha),
lwd = coords$linewidth * .pt,
lwd = coords$linewidth,
lty = coords$linetype,
linejoin = linejoin,
lineend = lineend
Expand Down

0 comments on commit 6912a49

Please sign in to comment.