Skip to content

Commit 7a0176d

Browse files
cpsievertCopilot
andauthored
Updates in support of ggplot2 v4.0.0 (#2442)
* Run tests against dev ggplot2 * Take changes from #2440 * Approve (a subset of) new snapshots * Ensure ticktext/tickvals is atomic character/numeric vector * Fix geom_sf() break positions * Fix for geom_violin() * Update news * Approve good visual changes * Approve more visual changes; fix test expectation * Accept new snapshot * Zero length ticktext/tickvals should remain NULL * Zero length vs NULL can actually be meaningful so just safe guard against error * Approve new snapshot * Refactor * Update NEWS.md Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 3b5f6e6 commit 7a0176d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+60
-51
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
plotly_api_key: ${{ secrets.PLOTLY_API_KEY }}
4747

4848
steps:
49-
- uses: actions/checkout@v2
49+
- uses: actions/checkout@v4
5050
with:
5151
persist-credentials: false
5252

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ RoxygenNote: 7.3.2
8282
Encoding: UTF-8
8383
Roxygen: list(markdown = TRUE)
8484
Config/Needs/check:
85+
tidyverse/ggplot2,
8586
rcmdcheck,
8687
devtools,
8788
reshape2,

NEWS.md

Lines changed: 1 addition & 1 deletion

R/ggplotly.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,9 @@ gg2list <- function(p, width = NULL, height = NULL,
668668
"\\*\\s+degree[ ]?[\\*]?", "&#176;",
669669
gsub("\"", "", tickData[["degree_label"]])
670670
)
671-
rng[[paste0(xy, ".major")]] <- tickData[[paste0(xy, "_start")]]
671+
# Downstream logic expects these 'break positions' to be on 0-1 scale
672+
# (which is then rescaled back to the data scale)
673+
rng[[paste0(xy, ".major")]] <- scales::rescale(tickData[[paste0(xy, "_start")]])
672674

673675
# If it doesn't already exist (for this panel),
674676
# generate graticule (as done in, CoordSf$render_bg)
@@ -742,8 +744,8 @@ gg2list <- function(p, width = NULL, height = NULL,
742744

743745
# https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809
744746
hasTickText <- !(is.na(ticktext) | is.na(tickvals))
745-
ticktext <- ticktext[hasTickText]
746-
tickvals <- tickvals[hasTickText]
747+
ticktext <- as.character(unlist(ticktext[hasTickText]))
748+
tickvals <- as.numeric(unlist(tickvals[hasTickText]))
747749

748750
axisObj <- list(
749751
# TODO: log type?
@@ -783,8 +785,11 @@ gg2list <- function(p, width = NULL, height = NULL,
783785
# set scaleanchor/scaleratio if these are fixed coordinates
784786
# the logic here is similar to what p$coordinates$aspect() does,
785787
# but the ratio is scaled to the data range by plotly.js
786-
fixed_coords <- c("CoordSf", "CoordFixed", "CoordMap", "CoordQuickmap")
787-
if (inherits(p$coordinates, fixed_coords)) {
788+
is_fixed <- inherits(
789+
p$coordinates,
790+
c("CoordSf", "CoordFixed", "CoordMap", "CoordQuickmap")
791+
)
792+
if (is_fixed || isFALSE(p$coordinates$is_free())) {
788793
axisObj$scaleanchor <- anchor
789794
ratio <- p$coordinates$ratio %||% 1
790795
axisObj$scaleratio <- if (xy == "y") ratio else 1 / ratio
@@ -1436,7 +1441,9 @@ gdef2trace <- function(gdef, theme, gglayout) {
14361441
}
14371442

14381443
vals <- lapply(gglayout[c("xaxis", "yaxis")], function(ax) {
1439-
if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals
1444+
res <- if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals
1445+
# if zero-length, return NULL to avoid subscript oob errors
1446+
res %||% NULL
14401447
})
14411448

14421449
list(

R/layers2traces.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ to_basic.GeomCol <- function(data, prestats_data, layout, params, p, ...) {
197197
#' @export
198198
to_basic.GeomViolin <- function(data, prestats_data, layout, params, p, ...) {
199199
n <- nrow(data)
200+
data <- data[order(data[["y"]], decreasing = FALSE), ]
200201
revData <- data[order(data[["y"]], decreasing = TRUE), ]
201202
idx <- !names(data) %in% c("x", "xmin", "xmax")
202203
data <- rbind(

tests/testthat/_snaps/cookbook-axes/cookbook-axes-log2-labels.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggalluvial/stratum-alluvium-color.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggalluvial/stratum-alluvium.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-col/col.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-contour/contour.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-contour/raster-contour-binned.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-facets/3-panels.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-facets/barley.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-heatmap/tile-no-fill.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-counts.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-dates.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-density.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-dodge.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-facets.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-identity.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-fill.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-fixed-fill-color.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-histogram/histogram-vline.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-labels/labs-element-blank.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-map/map-facet.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-polygons/polygons-canada-borders.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-sf/sf-aspect.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-sf/sf-axis-ticks.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-sf/sf-fill-text.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-sf/sf-geom-collection.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-sf/sf-points.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-sf/sf-theme-map.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-sf/sf.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-text/text-colour.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-ticks/ticks-hide-ticks-lines-labels.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-tooltip/heatmap-discrete-tooltip.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-violin/violin.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggridges/histogram-ridges.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/mean-error-bars/error-rect-alpha.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/plotly-subplot/plotly-subplot-ggmatrix.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/plotly-subplot/plotly-subplot-width-height.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/test-ggplot-labels.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ test_that("empty labels work", {
5151
p <- ggplot(palmerpenguins::penguins,
5252
aes(bill_length_mm, bill_depth_mm, color = species)) +
5353
geom_point() +
54-
labs(x = element_blank(), y = element_blank())
54+
labs(x = NULL, y = NULL)
5555
b <- expect_doppelganger_built(p, "labs-element-blank")
5656
})

tests/testthat/test-ggplot-ticks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ test_that("Set the X tick mark locations", {
171171
test_that("The breaks can be spaced unevenly", {
172172
boxes.uneven <- boxes +
173173
scale_y_continuous(breaks = c(4, 4.25, 4.5, 5, 6, 8))
174-
info <- expect_traces(no.breaks, 1, "uneven")
174+
info <- expect_traces(boxes.uneven, 1, "uneven")
175175
})
176176

177177
test_that("R line breaks are translated to HTML line breaks", {

0 commit comments

Comments
 (0)