Skip to content

Commit

Permalink
Merge branch 'main' into tile_panel_resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed May 20, 2024
2 parents 966f89d + f8dac9d commit 80382d9
Show file tree
Hide file tree
Showing 214 changed files with 3,410 additions and 4,096 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

Expand Down Expand Up @@ -64,7 +62,7 @@ jobs:
extra-packages: >
any::rcmdcheck,
Hmisc=?ignore-before-r=4.1.0,
quantreg=?ignore-before-r=3.6.0,
quantreg=?ignore-before-r=4.3.0,
needs: check

- uses: r-lib/actions/check-r-package@v2
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -45,7 +45,7 @@ Imports:
scales (>= 1.3.0),
stats,
tibble,
vctrs (>= 0.5.0),
vctrs (>= 0.6.0),
withr (>= 2.5.0)
Suggests:
covr,
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
89 changes: 82 additions & 7 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,92 @@

# ggplot2 (development version)

* Fixed performance loss when the `.data` pronoun is used in `aes()` (#5730).
* The bounded density option in `stat_density()` uses a wider range to
prevent discontinuities (#5641).
* `geom_raster()` now falls back to rendering as `geom_rect()` when coordinates
are not Cartesian (#5503).
* `stat_ecdf()` now has an optional `weight` aesthetic (@teunbrand, #5058).
* Position scales combined with `coord_sf()` can now use functions in the
`breaks` argument. In addition, `n.breaks` works as intended and
`breaks = NULL` removes grid lines and axes (@teunbrand, #4622).
* (Internal) Applying defaults in `geom_sf()` has moved from the internal
`sf_grob()` to `GeomSf$use_defaults()` (@teunbrand).
* `facet_wrap()` has new options for the `dir` argument to more precisely
control panel directions (@teunbrand, #5212)
* 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).
* `scale_{x/y}_discrete()` can now accept a `sec.axis`. It is recommended to
only use `dup_axis()` to set custom breaks or labels, as discrete variables
cannot be transformed (@teunbrand, #3171).
* `stat_density()` has the new computed variable: `wdensity`, which is
calculated as the density times the sum of weights (@teunbrand, #4176).
* `theme()` gets new `spacing` and `margins` arguments that all other spacings
and (non-text) margins inherit from (@teunbrand, #5622).
* `geom_ribbon()` can have varying `fill` or `alpha` in linear coordinate
systems (@teunbrand, #4690).
* `geom_tile()` computes default widths and heights per panel instead of
per layer (@teunbrand, #5740).

# 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)
* 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).
* 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
calculate the breaks even if `bins` and `binwidth` are missing
(@teunbrand, #5686).
* `geom_step()` now supports `lineend`, `linejoin` and `linemitre` parameters
(@teunbrand, #5705).
* Fixed performance loss when the `.data` pronoun is used in `aes()` (#5730).
* Facet evaluation is better at dealing with inherited errors
(@teunbrand, #5670).
* `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665).
* `geom_tile()` computes default widths and heights per panel instead of
per layer (@teunbrand, #5740).
* 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)
* 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).
* When legends detect the presence of values in a layer, `NA` is now detected
if the data contains values outside the given breaks (@teunbrand, #5749).
* `annotate()` now warns about `stat` or `position` arguments (@teunbrand, #5151)
* `guide_coloursteps(even.steps = FALSE)` now works with discrete data that has
been formatted by `cut()` (@teunbrand, #3877).

# ggplot2 3.5.0

Expand Down Expand Up @@ -1444,7 +1519,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
15 changes: 11 additions & 4 deletions R/annotation.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@ annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
}

data <- data_frame0(!!!position, .size = n)

params <- list2(na.rm = na.rm, ...)
reject <- intersect(names(params), c("position", "stat"))
if (length(reject) > 0) {
cli::cli_warn(
"{.fn annotate} can't accept {.or {.arg {reject}}} argument{?s}."
)
params <- params[setdiff(names(params), reject)]
}

layer(
geom = geom,
params = list(
na.rm = na.rm,
...
),
params = params,
stat = StatIdentity,
position = PositionIdentity,
data = data,
Expand Down
2 changes: 1 addition & 1 deletion R/autolayer.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param ... other arguments passed to specific methods
#' @return a ggplot layer
#' @export
#' @seealso [autoplot()], [ggplot()] and [fortify()]
#' @family plotting automation topics
autolayer <- function(object, ...) {
UseMethod("autolayer")
}
Expand Down
114 changes: 113 additions & 1 deletion R/autoplot.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,115 @@
#' Tailoring plots to particular data types
#'
#' @description
#' There are three functions to make plotting particular data types easier:
#' `autoplot()`, `autolayer()` and `fortify()`. These are S3 generics for which
#' other packages can write methods to display classes of data. The three
#' functions are complementary and allow different levels of customisation.
#' Below we'll explore implementing this series of methods to automate plotting
#' of some class.
#'
#' Let's suppose we are writing a packages that has a class called 'my_heatmap',
#' that wraps a matrix and we'd like users to easily plot this heatmap.
#'
#' ```r
#' my_heatmap <- function(...) {
#' m <- matrix(...)
#' class(m) <- c("my_heatmap", class(m))
#' m
#' }
#'
#' my_data <- my_heatmap(volcano)
#' ```
#'
#' # Automatic data shaping
#'
#' One of the things we have to do is ensure that the data is shaped in the long
#' format so that it is compatible with ggplot2. This is the job of the
#' `fortify()` function. Because 'my_heatmap' wraps a matrix, we can let the
#' fortify method 'melt' the matrix to a long format. If your data is already
#' based on a long-format `<data.frame>`, you can skip implementing a
#' `fortify()` method.
#'
#' ```r
#' fortify.my_heatmap <- function(model, ...) {
#' data.frame(
#' row = as.vector(row(model)),
#' col = as.vector(col(model)),
#' value = as.vector(model)
#' )
#' }
#'
#' fortify(my_data)
#' ```
#'
#' When you have implemented the `fortify()` method, it should be easier to
#' construct a plot with the data than with the matrix.
#'
#' ```r
#' ggplot(my_data, aes(x = col, y = row, fill = value)) +
#' geom_raster()
#' ```
#'
#' # Automatic layers
#'
#' A next step in automating plotting of your data type is to write an
#' `autolayer()` method. These are typically wrappers around geoms or stats
#' that automatically set aesthetics or other parameters. If you haven't
#' implemented a `fortify()` method for your data type, you might have to
#' reshape the data in `autolayer()`.
#'
#' If you require multiple layers to display your data type, you can use an
#' `autolayer()` method that constructs a list of layers, which can be added
#' to a plot.
#'
#' ```r
#' autolayer.my_heatmap <- function(object, ...) {
#' geom_raster(
#' mapping = aes(x = col, y = row, fill = value),
#' data = object,
#' ...,
#' inherit.aes = FALSE
#' )
#' }
#'
#' ggplot() + autolayer(my_data)
#' ```
#'
#' As a quick tip: if you define a mapping in `autolayer()`, you might want
#' to set `inherit.aes = FALSE` to not have aesthetics set in other layers
#' interfere with your layer.
#'
#' # Automatic plots
#'
#' The last step in automating plotting is to write an `autoplot()` method
#' for your data type. The expectation is that these return a complete plot.
#' In the example below, we're exploiting the `autolayer()` method that we
#' have already written to make a complete plot.
#'
#' ```r
#' autoplot.my_heatmap <- function(object, ..., option = "magma") {
#' ggplot() +
#' autolayer(my_data) +
#' scale_fill_viridis_c(option = option) +
#' theme_void()
#' }
#'
#' autoplot(my_data)
#' ```
#'
#' If you don't have a wish to implement a base R plotting method, you
#' can set the plot method for your class to the autoplot method.
#'
#' ```r
#' plot.my_heatmap <- autoplot.my_heatmap
#' plot(my_data)
#' ```
#'
#' @family plotting automation topics
#'
#' @name automatic_plotting
NULL

#' Create a complete ggplot appropriate to a particular data type
#'
#' `autoplot()` uses ggplot2 to draw a particular plot for an object of a
Expand All @@ -8,7 +120,7 @@
#' @param ... other arguments passed to specific methods
#' @return a ggplot object
#' @export
#' @seealso [autolayer()], [ggplot()] and [fortify()]
#' @family plotting automation topics
autoplot <- function(object, ...) {
UseMethod("autoplot")
}
Expand Down
Loading

0 comments on commit 80382d9

Please sign in to comment.