From e217ca8eb76b6d4b5ed865669bfa231e00f0b37a Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 12:17:38 -0500 Subject: [PATCH 01/15] Run tests against dev ggplot2 --- .github/workflows/R-CMD-check.yaml | 2 +- DESCRIPTION | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 3b4c41ce21..66e69dd636 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -46,7 +46,7 @@ jobs: plotly_api_key: ${{ secrets.PLOTLY_API_KEY }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: persist-credentials: false diff --git a/DESCRIPTION b/DESCRIPTION index bc1f9f1d19..318fd9d49b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -82,6 +82,7 @@ RoxygenNote: 7.3.2 Encoding: UTF-8 Roxygen: list(markdown = TRUE) Config/Needs/check: + tidyverse/ggplot2, rcmdcheck, devtools, reshape2, From d1efeade2bedc88260482cd5a5b1f75b3b5e6da1 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 12:26:06 -0500 Subject: [PATCH 02/15] Take changes from #2440 --- R/ggplotly.R | 3 ++- tests/testthat/test-ggplot-labels.R | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index 93d158813c..1ce21265e1 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -784,7 +784,8 @@ gg2list <- function(p, width = NULL, height = NULL, # the logic here is similar to what p$coordinates$aspect() does, # but the ratio is scaled to the data range by plotly.js fixed_coords <- c("CoordSf", "CoordFixed", "CoordMap", "CoordQuickmap") - if (inherits(p$coordinates, fixed_coords)) { + is_fixed <- isFALSE(p$coordinates$is_free()) + if (inherits(p$coordinates, fixed_coords) || is_fixed) { axisObj$scaleanchor <- anchor ratio <- p$coordinates$ratio %||% 1 axisObj$scaleratio <- if (xy == "y") ratio else 1 / ratio diff --git a/tests/testthat/test-ggplot-labels.R b/tests/testthat/test-ggplot-labels.R index 4a4a8cfb34..69ca3b4e22 100644 --- a/tests/testthat/test-ggplot-labels.R +++ b/tests/testthat/test-ggplot-labels.R @@ -51,6 +51,6 @@ test_that("empty labels work", { p <- ggplot(palmerpenguins::penguins, aes(bill_length_mm, bill_depth_mm, color = species)) + geom_point() + - labs(x = element_blank(), y = element_blank()) + labs(x = NULL, y = NULL) b <- expect_doppelganger_built(p, "labs-element-blank") }) From 661b76d12398536f7bf360bf16b752b672e9bd69 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 12:41:47 -0500 Subject: [PATCH 03/15] Approve (a subset of) new snapshots --- tests/testthat/_snaps/ggalluvial/stratum-alluvium-color.svg | 2 +- tests/testthat/_snaps/ggalluvial/stratum-alluvium.svg | 2 +- tests/testthat/_snaps/ggplot-col/col.svg | 2 +- tests/testthat/_snaps/ggplot-contour/contour.svg | 2 +- tests/testthat/_snaps/ggplot-contour/raster-contour-binned.svg | 2 +- tests/testthat/_snaps/ggplot-facets/3-panels.svg | 2 +- tests/testthat/_snaps/ggplot-facets/barley.svg | 2 +- tests/testthat/_snaps/ggplot-heatmap/tile-no-fill.svg | 2 +- tests/testthat/_snaps/ggplot-histogram/histogram-counts.svg | 2 +- tests/testthat/_snaps/ggplot-histogram/histogram-dates.svg | 2 +- tests/testthat/_snaps/ggplot-histogram/histogram-density.svg | 2 +- .../_snaps/ggplot-histogram/histogram-fill-factor-dodge.svg | 2 +- .../_snaps/ggplot-histogram/histogram-fill-factor-facets.svg | 2 +- .../_snaps/ggplot-histogram/histogram-fill-factor-identity.svg | 2 +- .../testthat/_snaps/ggplot-histogram/histogram-fill-factor.svg | 2 +- tests/testthat/_snaps/ggplot-histogram/histogram-fill.svg | 2 +- .../_snaps/ggplot-histogram/histogram-fixed-fill-color.svg | 2 +- tests/testthat/_snaps/ggplot-histogram/histogram-vline.svg | 2 +- tests/testthat/_snaps/ggplot-labels/labs-element-blank.svg | 2 +- tests/testthat/_snaps/ggplot-map/map-facet.svg | 2 +- tests/testthat/_snaps/ggplot-text/text-colour.svg | 2 +- .../testthat/_snaps/ggplot-tooltip/heatmap-discrete-tooltip.svg | 2 +- tests/testthat/_snaps/ggridges/histogram-ridges.svg | 2 +- tests/testthat/_snaps/mean-error-bars/error-rect-alpha.svg | 2 +- tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg | 2 +- .../testthat/_snaps/plotly-subplot/plotly-subplot-ggmatrix.svg | 2 +- .../_snaps/plotly-subplot/plotly-subplot-width-height.svg | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/testthat/_snaps/ggalluvial/stratum-alluvium-color.svg b/tests/testthat/_snaps/ggalluvial/stratum-alluvium-color.svg index a03d36e567..d201562295 100644 --- a/tests/testthat/_snaps/ggalluvial/stratum-alluvium-color.svg +++ b/tests/testthat/_snaps/ggalluvial/stratum-alluvium-color.svg @@ -1 +1 @@ -NoYesMaleFemale1st2nd3rdCrew0500100015002000SurvivedSexClassClass1st2nd3rdCrewTitanic survival by class and sexFreq +NoYesMaleFemale1st2nd3rdCrew0500100015002000SurvivedSexClassClass1st2nd3rdCrewTitanic survival by class and sexFreq diff --git a/tests/testthat/_snaps/ggalluvial/stratum-alluvium.svg b/tests/testthat/_snaps/ggalluvial/stratum-alluvium.svg index 372db14600..f80bf4a8b1 100644 --- a/tests/testthat/_snaps/ggalluvial/stratum-alluvium.svg +++ b/tests/testthat/_snaps/ggalluvial/stratum-alluvium.svg @@ -1 +1 @@ -NoYesMaleFemale1st2nd3rdCrew0500100015002000SurvivedSexClassTitanic survival by class and sexFreq +NoYesMaleFemale1st2nd3rdCrew0500100015002000SurvivedSexClassTitanic survival by class and sexFreq diff --git a/tests/testthat/_snaps/ggplot-col/col.svg b/tests/testthat/_snaps/ggplot-col/col.svg index a3be5dedfa..515c34c421 100644 --- a/tests/testthat/_snaps/ggplot-col/col.svg +++ b/tests/testthat/_snaps/ggplot-col/col.svg @@ -1 +1 @@ -71.4%20.0%48.3%28.6%80.0%51.7%ElementaryHighMiddle0.000.250.500.751.00includedexcludedincludedtypeprop +71.4%20.0%48.3%28.6%80.0%51.7%ElementaryHighMiddle0.000.250.500.751.00includedexcludedincludedtypeprop diff --git a/tests/testthat/_snaps/ggplot-contour/contour.svg b/tests/testthat/_snaps/ggplot-contour/contour.svg index 5c1aae4739..e4777fc4a4 100644 --- a/tests/testthat/_snaps/ggplot-contour/contour.svg +++ b/tests/testthat/_snaps/ggplot-contour/contour.svg @@ -1 +1 @@ -02550750204060xy +02550750204060xy diff --git a/tests/testthat/_snaps/ggplot-contour/raster-contour-binned.svg b/tests/testthat/_snaps/ggplot-contour/raster-contour-binned.svg index 91b992bdd9..43c67fca5a 100644 --- a/tests/testthat/_snaps/ggplot-contour/raster-contour-binned.svg +++ b/tests/testthat/_snaps/ggplot-contour/raster-contour-binned.svg @@ -1 +1 @@ --10123-10123246810ptltrsps +-10123-10123246810ptltrsps diff --git a/tests/testthat/_snaps/ggplot-facets/3-panels.svg b/tests/testthat/_snaps/ggplot-facets/3-panels.svg index 698153e481..00587badec 100644 --- a/tests/testthat/_snaps/ggplot-facets/3-panels.svg +++ b/tests/testthat/_snaps/ggplot-facets/3-panels.svg @@ -1 +1 @@ -0.000.250.500.751.000.000.250.500.751.000.000.250.500.751.000.000.250.500.751.00xyabc +0.000.250.500.751.000.000.250.500.751.000.000.250.500.751.000.000.250.500.751.00xyabc diff --git a/tests/testthat/_snaps/ggplot-facets/barley.svg b/tests/testthat/_snaps/ggplot-facets/barley.svg index 8eb848976d..f302ea46d8 100644 --- a/tests/testthat/_snaps/ggplot-facets/barley.svg +++ b/tests/testthat/_snaps/ggplot-facets/barley.svg @@ -1 +1 @@ -SvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38TrebiSvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38TrebiSvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38TrebiSvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38TrebiSvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38Trebi2030405060SvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38Trebiyear19321931yieldvarietyGrand RapidsDuluthUniversity FarmMorrisCrookstonWaseca +SvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38TrebiSvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38TrebiSvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38TrebiSvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38TrebiSvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38Trebi2030405060SvansotaNo. 462ManchuriaNo. 475VelvetPeatlandGlabronNo. 457Wisconsin No. 38Trebiyear19321931yieldvarietyGrand RapidsDuluthUniversity FarmMorrisCrookstonWaseca diff --git a/tests/testthat/_snaps/ggplot-heatmap/tile-no-fill.svg b/tests/testthat/_snaps/ggplot-heatmap/tile-no-fill.svg index 54fef9c43c..3ffb60481b 100644 --- a/tests/testthat/_snaps/ggplot-heatmap/tile-no-fill.svg +++ b/tests/testthat/_snaps/ggplot-heatmap/tile-no-fill.svg @@ -1 +1 @@ -5100.51.01.52.02.5xy +5100.51.01.52.02.5xy diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-counts.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-counts.svg index 26e14cace2..3f11fee71d 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-counts.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-counts.svg @@ -1 +1 @@ -23450246wtcount +2345012345wtcount diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-dates.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-dates.svg index 3b37e86f83..64339e615d 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-dates.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-dates.svg @@ -1 +1 @@ -Jan 01Jan 15Feb 01Feb 15Mar 010123monthcount +Jan 01Jan 15Feb 01Feb 15Mar 010123monthcount diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-density.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-density.svg index fd604d8a1f..d77a828a4b 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-density.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-density.svg @@ -1 +1 @@ -23450.00.51.01.5wtdensity +23450.00.30.60.91.2wtdensity diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-dodge.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-dodge.svg index 22a9743270..10277ea74f 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-dodge.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-dodge.svg @@ -1 +1 @@ -234501234factor(vs)01wtcount +23450123factor(vs)01wtcount diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-facets.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-facets.svg index b2bd2e86f8..f2513aa43b 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-facets.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-facets.svg @@ -1 +1 @@ -234502462345factor(vs)01wtcount01 +23450123452345factor(vs)01wtcount01 diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-identity.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-identity.svg index 7d8c449852..f8d3559ab4 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-identity.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor-identity.svg @@ -1 +1 @@ -234501234factor(vs)01wtcount +23450123factor(vs)01wtcount diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor.svg index 4a98b85937..289e96ad5a 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-fill-factor.svg @@ -1 +1 @@ -23450246factor(vs)01wtcount +2345012345factor(vs)01wtcount diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-fill.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-fill.svg index de0773ee5a..5f5cc0b318 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-fill.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-fill.svg @@ -1 +1 @@ -234502460246countwtcount +2345012345012345countwtcount diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-fixed-fill-color.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-fixed-fill-color.svg index 7e13b056ba..c27869c9d6 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-fixed-fill-color.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-fixed-fill-color.svg @@ -1 +1 @@ -23450246wtcount +2345012345wtcount diff --git a/tests/testthat/_snaps/ggplot-histogram/histogram-vline.svg b/tests/testthat/_snaps/ggplot-histogram/histogram-vline.svg index 27a445f168..5032a9d799 100644 --- a/tests/testthat/_snaps/ggplot-histogram/histogram-vline.svg +++ b/tests/testthat/_snaps/ggplot-histogram/histogram-vline.svg @@ -1 +1 @@ -23450246wtcount +2345012345wtcount diff --git a/tests/testthat/_snaps/ggplot-labels/labs-element-blank.svg b/tests/testthat/_snaps/ggplot-labels/labs-element-blank.svg index 09547ea0f8..4bf70aa91b 100644 --- a/tests/testthat/_snaps/ggplot-labels/labs-element-blank.svg +++ b/tests/testthat/_snaps/ggplot-labels/labs-element-blank.svg @@ -1 +1 @@ -40506015.017.520.0speciesAdelieChinstrapGentoo +40506015.017.520.0speciesAdelieChinstrapGentoo diff --git a/tests/testthat/_snaps/ggplot-map/map-facet.svg b/tests/testthat/_snaps/ggplot-map/map-facet.svg index 490a40ad79..5f09eb6169 100644 --- a/tests/testthat/_snaps/ggplot-map/map-facet.svg +++ b/tests/testthat/_snaps/ggplot-map/map-facet.svg @@ -1 +1 @@ -253035404550-120-100-80253035404550-120-100-80100200300valuexyAssaultMurderRapeUrbanPop +253035404550-120-100-80253035404550-120-100-80100200300valueAssaultMurderRapeUrbanPop diff --git a/tests/testthat/_snaps/ggplot-text/text-colour.svg b/tests/testthat/_snaps/ggplot-text/text-colour.svg index d0daca0f9c..963ddf31fc 100644 --- a/tests/testthat/_snaps/ggplot-text/text-colour.svg +++ b/tests/testthat/_snaps/ggplot-text/text-colour.svg @@ -1 +1 @@ -HUNTSVILLEMOBILEBIRMINGHAMMONTGOMERYTUCSONPEORIA01020-505DivisionEast South CentralAaMountainAacoord.1coord.2 +HUNTSVILLEMOBILEBIRMINGHAMMONTGOMERYTUCSONPEORIA01020-505DivisionEast South CentralAaMountainAacoord.1coord.2 diff --git a/tests/testthat/_snaps/ggplot-tooltip/heatmap-discrete-tooltip.svg b/tests/testthat/_snaps/ggplot-tooltip/heatmap-discrete-tooltip.svg index 6471d3ab3b..baab83207f 100644 --- a/tests/testthat/_snaps/ggplot-tooltip/heatmap-discrete-tooltip.svg +++ b/tests/testthat/_snaps/ggplot-tooltip/heatmap-discrete-tooltip.svg @@ -1 +1 @@ -1020304680.20.40.6densitympgfactor(cyl) +1020304680.20.40.6densitympgfactor(cyl) diff --git a/tests/testthat/_snaps/ggridges/histogram-ridges.svg b/tests/testthat/_snaps/ggridges/histogram-ridges.svg index 89d17fc9bc..ac26c65566 100644 --- a/tests/testthat/_snaps/ggridges/histogram-ridges.svg +++ b/tests/testthat/_snaps/ggridges/histogram-ridges.svg @@ -1 +1 @@ -45678setosaversicolorvirginicaSepal.LengthSpecies +45678setosaversicolorvirginicaSepal.LengthSpecies diff --git a/tests/testthat/_snaps/mean-error-bars/error-rect-alpha.svg b/tests/testthat/_snaps/mean-error-bars/error-rect-alpha.svg index 993e02173b..1ef4b2a3de 100644 --- a/tests/testthat/_snaps/mean-error-bars/error-rect-alpha.svg +++ b/tests/testthat/_snaps/mean-error-bars/error-rect-alpha.svg @@ -1 +1 @@ -024612345grouponetwoxy +0246-2.50.02.55.07.5grouponetwoxy diff --git a/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg b/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg index 5a72f2d81d..987f28fdbf 100644 --- a/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg +++ b/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg @@ -1 +1 @@ -v1v2v3v4v5012345612345-1.0-0.50.00.51.0 +v1v2v3v4v5012345612345-1.0-0.50.00.51.0 diff --git a/tests/testthat/_snaps/plotly-subplot/plotly-subplot-ggmatrix.svg b/tests/testthat/_snaps/plotly-subplot/plotly-subplot-ggmatrix.svg index cc5b650a26..7c3e107830 100644 --- a/tests/testthat/_snaps/plotly-subplot/plotly-subplot-ggmatrix.svg +++ b/tests/testthat/_snaps/plotly-subplot/plotly-subplot-ggmatrix.svg @@ -1 +1 @@ -0.02.55.07.50.02.55.07.556780.02.55.07.50.00.51.01.52.02.52462.02.53.03.54.04.50.00.10.20.30.42.02.53.03.54.04.5Corr:-0.118246Corr:-0.428***Corr:0.872***0.00.51.01.52.02.5Corr:0.963***Corr:-0.366***Corr:0.818***setosaversicolorvirginicaSepal.LengthSepal.WidthPetal.LengthPetal.WidthSpeciesPetal.WidthPetal.LengthSepal.WidthSepal.Lengthsetosaversicolorvirginicasetosaversicolorvirginicasetosaversicolorvirginicasetosaversicolorvirginica +05101505101556780510150.00.51.01.52.02.52462.02.53.03.54.04.50.00.10.20.30.42.02.53.03.54.04.5Corr:-0.118246Corr:-0.428***Corr:0.872***0.00.51.01.52.02.5Corr:0.963***Corr:-0.366***Corr:0.818***setosaversicolorvirginicaSepal.LengthSepal.WidthPetal.LengthPetal.WidthSpeciesPetal.WidthPetal.LengthSepal.WidthSepal.Lengthsetosaversicolorvirginicasetosaversicolorvirginicasetosaversicolorvirginicasetosaversicolorvirginica diff --git a/tests/testthat/_snaps/plotly-subplot/plotly-subplot-width-height.svg b/tests/testthat/_snaps/plotly-subplot/plotly-subplot-width-height.svg index 627e66e9ae..6d5b52e667 100644 --- a/tests/testthat/_snaps/plotly-subplot/plotly-subplot-width-height.svg +++ b/tests/testthat/_snaps/plotly-subplot/plotly-subplot-width-height.svg @@ -1 +1 @@ -0.02.55.07.5-3-2-1012-2020.02.55.07.510.0xcountcounty +0.02.55.07.510.0-3-2-1012-2020369xcountcounty From 6b5395db45d601433e007968580fbb23f9a5d1fe Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 14:32:10 -0500 Subject: [PATCH 04/15] Ensure ticktext/tickvals is atomic character/numeric vector --- R/ggplotly.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index 1ce21265e1..d54d2f0b8d 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -742,8 +742,8 @@ gg2list <- function(p, width = NULL, height = NULL, # https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809 hasTickText <- !(is.na(ticktext) | is.na(tickvals)) - ticktext <- ticktext[hasTickText] - tickvals <- tickvals[hasTickText] + ticktext <- as.character(unlist(ticktext[hasTickText])) + tickvals <- as.numeric(unlist(tickvals[hasTickText])) axisObj <- list( # TODO: log type? From 44a6355bf97cc779999636f9e02f857895f5fa33 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 14:47:41 -0500 Subject: [PATCH 05/15] Fix geom_sf() break positions --- R/ggplotly.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index d54d2f0b8d..6587ede7cd 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -668,7 +668,11 @@ gg2list <- function(p, width = NULL, height = NULL, "\\*\\s+degree[ ]?[\\*]?", "°", gsub("\"", "", tickData[["degree_label"]]) ) - rng[[paste0(xy, ".major")]] <- tickData[[paste0(xy, "_start")]] + # Downstream logic expects the 'break positions' to be on 0-1 scale + # (which is then rescaled back to the data scale) + rng[[paste0(xy, ".major")]] <- scales::rescale( + tickData[[paste0(xy, "_start")]] + ) # If it doesn't already exist (for this panel), # generate graticule (as done in, CoordSf$render_bg) From 650725ed8ece63a6d106ac783265ab7e98cea3a7 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 15:21:42 -0500 Subject: [PATCH 06/15] Fix for geom_violin() --- R/layers2traces.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/layers2traces.R b/R/layers2traces.R index df78b0c62e..1b889dc3f8 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -197,6 +197,7 @@ to_basic.GeomCol <- function(data, prestats_data, layout, params, p, ...) { #' @export to_basic.GeomViolin <- function(data, prestats_data, layout, params, p, ...) { n <- nrow(data) + data <- data[order(data[["y"]], decreasing = FALSE), ] revData <- data[order(data[["y"]], decreasing = TRUE), ] idx <- !names(data) %in% c("x", "xmin", "xmax") data <- rbind( From 0a180d1d5a2ef443c23cc09f80a65d72d4a96cfa Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 15:21:52 -0500 Subject: [PATCH 07/15] Update news --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 138ad21266..cba599e6a6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,7 +6,7 @@ ## Improvements -* `ggplotly()` now works better with the development version of ggplot2 (> v3.4.4). (#2315, #2368) +* Various updates to updates `ggplotly()` to better support recent versions of ggplot2. (#2315, #2368, #2442, thanks @teunbrand). ## Bug fixes From 63cc32375f91facb499594cc8e38b8005fe53fba Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 15:33:38 -0500 Subject: [PATCH 08/15] Approve good visual changes --- .../testthat/_snaps/cookbook-axes/cookbook-axes-log2-labels.svg | 2 +- .../_snaps/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg | 2 +- tests/testthat/_snaps/ggplot-sf/sf-aspect.svg | 2 +- tests/testthat/_snaps/ggplot-sf/sf-axis-ticks.svg | 2 +- tests/testthat/_snaps/ggplot-sf/sf-fill-text.svg | 2 +- tests/testthat/_snaps/ggplot-sf/sf-geom-collection.svg | 2 +- tests/testthat/_snaps/ggplot-sf/sf-theme-map.svg | 2 +- tests/testthat/_snaps/ggplot-sf/sf.svg | 2 +- tests/testthat/_snaps/ggplot-violin/violin.svg | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/testthat/_snaps/cookbook-axes/cookbook-axes-log2-labels.svg b/tests/testthat/_snaps/cookbook-axes/cookbook-axes-log2-labels.svg index 142897f141..caa5d42f44 100644 --- a/tests/testthat/_snaps/cookbook-axes/cookbook-axes-log2-labels.svg +++ b/tests/testthat/_snaps/cookbook-axes/cookbook-axes-log2-labels.svg @@ -1 +1 @@ -0123455.0010.0015.0020.00xvalyval +0123452^52^102^152^20xvalyval diff --git a/tests/testthat/_snaps/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg b/tests/testthat/_snaps/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg index 0e42df6c1f..d9bc2b0cce 100644 --- a/tests/testthat/_snaps/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg +++ b/tests/testthat/_snaps/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg @@ -1 +1 @@ -0123451.002.003.004.005.006.00xvalyval +01234510^110^210^310^410^510^6xvalyval diff --git a/tests/testthat/_snaps/ggplot-sf/sf-aspect.svg b/tests/testthat/_snaps/ggplot-sf/sf-aspect.svg index 55c95eb7f8..80ed0adb19 100644 --- a/tests/testthat/_snaps/ggplot-sf/sf-aspect.svg +++ b/tests/testthat/_snaps/ggplot-sf/sf-aspect.svg @@ -1 +1 @@ -84 ° W82 ° W80 ° W78 ° W76 ° W34.0 ° N34.5 ° N35.0 ° N35.5 ° N36.0 ° N36.5 ° N +84 ° W82 ° W80 ° W78 ° W76 ° W34.0 ° N34.5 ° N35.0 ° N35.5 ° N36.0 ° N36.5 ° N diff --git a/tests/testthat/_snaps/ggplot-sf/sf-axis-ticks.svg b/tests/testthat/_snaps/ggplot-sf/sf-axis-ticks.svg index 5c77bb8a53..bcf58955aa 100644 --- a/tests/testthat/_snaps/ggplot-sf/sf-axis-ticks.svg +++ b/tests/testthat/_snaps/ggplot-sf/sf-axis-ticks.svg @@ -1 +1 @@ -100 ° W 80 ° W 60 ° W 40 ° W 20 ° W40 ° N50 ° N60 ° N +100 ° W 80 ° W 60 ° W 40 ° W 20 ° W40 ° N50 ° N60 ° N diff --git a/tests/testthat/_snaps/ggplot-sf/sf-fill-text.svg b/tests/testthat/_snaps/ggplot-sf/sf-fill-text.svg index c0dd3f4cae..f08c00b5b4 100644 --- a/tests/testthat/_snaps/ggplot-sf/sf-fill-text.svg +++ b/tests/testthat/_snaps/ggplot-sf/sf-fill-text.svg @@ -1 +1 @@ -84 ° W82 ° W80 ° W78 ° W76 ° W34.0 ° N34.5 ° N35.0 ° N35.5 ° N36.0 ° N36.5 ° N0.050.100.150.20AREA +84 ° W82 ° W80 ° W78 ° W76 ° W34.0 ° N34.5 ° N35.0 ° N35.5 ° N36.0 ° N36.5 ° N0.050.100.150.20AREA diff --git a/tests/testthat/_snaps/ggplot-sf/sf-geom-collection.svg b/tests/testthat/_snaps/ggplot-sf/sf-geom-collection.svg index 64bc029f0a..ee7e5c3fe0 100644 --- a/tests/testthat/_snaps/ggplot-sf/sf-geom-collection.svg +++ b/tests/testthat/_snaps/ggplot-sf/sf-geom-collection.svg @@ -1 +1 @@ -1234567-0.5-0.4-0.3-0.2-0.1 0.0 +1234567-0.5-0.4-0.3-0.2-0.1 0.0 diff --git a/tests/testthat/_snaps/ggplot-sf/sf-theme-map.svg b/tests/testthat/_snaps/ggplot-sf/sf-theme-map.svg index 7a114eb336..0f57f9ef68 100644 --- a/tests/testthat/_snaps/ggplot-sf/sf-theme-map.svg +++ b/tests/testthat/_snaps/ggplot-sf/sf-theme-map.svg @@ -1 +1 @@ - + diff --git a/tests/testthat/_snaps/ggplot-sf/sf.svg b/tests/testthat/_snaps/ggplot-sf/sf.svg index 55c95eb7f8..80ed0adb19 100644 --- a/tests/testthat/_snaps/ggplot-sf/sf.svg +++ b/tests/testthat/_snaps/ggplot-sf/sf.svg @@ -1 +1 @@ -84 ° W82 ° W80 ° W78 ° W76 ° W34.0 ° N34.5 ° N35.0 ° N35.5 ° N36.0 ° N36.5 ° N +84 ° W82 ° W80 ° W78 ° W76 ° W34.0 ° N34.5 ° N35.0 ° N35.5 ° N36.0 ° N36.5 ° N diff --git a/tests/testthat/_snaps/ggplot-violin/violin.svg b/tests/testthat/_snaps/ggplot-violin/violin.svg index c79f57e606..6dda4ede50 100644 --- a/tests/testthat/_snaps/ggplot-violin/violin.svg +++ b/tests/testthat/_snaps/ggplot-violin/violin.svg @@ -1 +1 @@ -468101520253035factor(cyl)mpg +468101520253035factor(cyl)mpg From 601ad894c8ad64e7da86213b5698122d2f7ec780 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 15:44:28 -0500 Subject: [PATCH 09/15] Approve more visual changes; fix test expectation --- tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg | 2 +- .../testthat/_snaps/ggplot-polygons/polygons-canada-borders.svg | 2 +- tests/testthat/_snaps/ggplot-sf/sf-points.svg | 2 +- .../_snaps/ggplot-ticks/ticks-hide-ticks-lines-labels.svg | 2 +- tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg | 2 +- tests/testthat/test-ggplot-ticks.R | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg b/tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg index cd77554974..7085010541 100644 --- a/tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg +++ b/tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg @@ -1 +1 @@ -Jan 02Jan 04Jan 06Jan 08Jan 10-2-1012SeriesMeanQCSeriesASeriesBDateValues +Jan 02Jan 04Jan 06Jan 08Jan 10-2-1012colourMeanQCSeriesASeriesBDateMean diff --git a/tests/testthat/_snaps/ggplot-polygons/polygons-canada-borders.svg b/tests/testthat/_snaps/ggplot-polygons/polygons-canada-borders.svg index afa5dd0510..7766906aef 100644 --- a/tests/testthat/_snaps/ggplot-polygons/polygons-canada-borders.svg +++ b/tests/testthat/_snaps/ggplot-polygons/polygons-canada-borders.svg @@ -1 +1 @@ --125-100-75-504050607080longlat +-125-100-75-504050607080 diff --git a/tests/testthat/_snaps/ggplot-sf/sf-points.svg b/tests/testthat/_snaps/ggplot-sf/sf-points.svg index d67ac10c46..996e36953b 100644 --- a/tests/testthat/_snaps/ggplot-sf/sf-points.svg +++ b/tests/testthat/_snaps/ggplot-sf/sf-points.svg @@ -1 +1 @@ -84 ° W82 ° W80 ° W78 ° W76 ° W34.0 ° N34.5 ° N35.0 ° N35.5 ° N36.0 ° N36.5 ° Nxy +84 ° W82 ° W80 ° W78 ° W76 ° W34.0 ° N34.5 ° N35.0 ° N35.5 ° N36.0 ° N36.5 ° N diff --git a/tests/testthat/_snaps/ggplot-ticks/ticks-hide-ticks-lines-labels.svg b/tests/testthat/_snaps/ggplot-ticks/ticks-hide-ticks-lines-labels.svg index 6926445f0d..b195101b75 100644 --- a/tests/testthat/_snaps/ggplot-ticks/ticks-hide-ticks-lines-labels.svg +++ b/tests/testthat/_snaps/ggplot-ticks/ticks-hide-ticks-lines-labels.svg @@ -1 +1 @@ -1233.54.04.55.05.56.0groupweight +3.54.04.55.05.56.0groupweight diff --git a/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg b/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg index 6926445f0d..fe30a076bd 100644 --- a/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg +++ b/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg @@ -1 +1 @@ -1233.54.04.55.05.56.0groupweight +3.54.04.55.05.56.0groupweight diff --git a/tests/testthat/test-ggplot-ticks.R b/tests/testthat/test-ggplot-ticks.R index 2038aaeb9a..ed2a0281e2 100644 --- a/tests/testthat/test-ggplot-ticks.R +++ b/tests/testthat/test-ggplot-ticks.R @@ -171,7 +171,7 @@ test_that("Set the X tick mark locations", { test_that("The breaks can be spaced unevenly", { boxes.uneven <- boxes + scale_y_continuous(breaks = c(4, 4.25, 4.5, 5, 6, 8)) - info <- expect_traces(no.breaks, 1, "uneven") + info <- expect_traces(boxes.uneven, 1, "uneven") }) test_that("R line breaks are translated to HTML line breaks", { From f0fb1e06e2e6250bad92be2fbe2519c8a16c4772 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 15:49:34 -0500 Subject: [PATCH 10/15] Accept new snapshot --- tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg b/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg index fe30a076bd..4d59ec12f6 100644 --- a/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg +++ b/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg @@ -1 +1 @@ -3.54.04.55.05.56.0groupweight +ctrltrt1trt24.004.254.505.006.00groupweight From 2811e610e48570681795f2fe52eb02c1ac320c24 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 16:03:33 -0500 Subject: [PATCH 11/15] Zero length ticktext/tickvals should remain NULL --- R/ggplotly.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index 6587ede7cd..6b1a868dd8 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -746,8 +746,8 @@ gg2list <- function(p, width = NULL, height = NULL, # https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809 hasTickText <- !(is.na(ticktext) | is.na(tickvals)) - ticktext <- as.character(unlist(ticktext[hasTickText])) - tickvals <- as.numeric(unlist(tickvals[hasTickText])) + ticktext <- as.character(unlist(ticktext[hasTickText])) %||% NULL + tickvals <- as.numeric(unlist(tickvals[hasTickText])) %||% NULL axisObj <- list( # TODO: log type? From fb012d812fd974c0c3cbbbcace3340948b3db9d3 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 16:13:49 -0500 Subject: [PATCH 12/15] Zero length vs NULL can actually be meaningful so just safe guard against error --- R/ggplotly.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index 6b1a868dd8..98eeea83ec 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -746,8 +746,8 @@ gg2list <- function(p, width = NULL, height = NULL, # https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809 hasTickText <- !(is.na(ticktext) | is.na(tickvals)) - ticktext <- as.character(unlist(ticktext[hasTickText])) %||% NULL - tickvals <- as.numeric(unlist(tickvals[hasTickText])) %||% NULL + ticktext <- as.character(unlist(ticktext[hasTickText])) + tickvals <- as.numeric(unlist(tickvals[hasTickText])) axisObj <- list( # TODO: log type? @@ -1441,7 +1441,9 @@ gdef2trace <- function(gdef, theme, gglayout) { } vals <- lapply(gglayout[c("xaxis", "yaxis")], function(ax) { - if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals + res <- if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals + # if zero-length, return NULL to avoid subscript oob errors + res %||% NULL }) list( From 66fb4d84982f24ede6647cc21279fbbfa93d0fcd Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 16:18:15 -0500 Subject: [PATCH 13/15] Approve new snapshot --- tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg b/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg index 987f28fdbf..14f39817be 100644 --- a/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg +++ b/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg @@ -1 +1 @@ -v1v2v3v4v5012345612345-1.0-0.50.00.51.0 +v1v2v3v4v5-1.0-0.50.00.51.0 From 4226314e4cd4d439865a2962804147bccfbb0be8 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 5 Jun 2025 16:26:30 -0500 Subject: [PATCH 14/15] Refactor --- R/ggplotly.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index 98eeea83ec..973a31ebc1 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -668,11 +668,9 @@ gg2list <- function(p, width = NULL, height = NULL, "\\*\\s+degree[ ]?[\\*]?", "°", gsub("\"", "", tickData[["degree_label"]]) ) - # Downstream logic expects the 'break positions' to be on 0-1 scale + # Downstream logic expects these 'break positions' to be on 0-1 scale # (which is then rescaled back to the data scale) - rng[[paste0(xy, ".major")]] <- scales::rescale( - tickData[[paste0(xy, "_start")]] - ) + rng[[paste0(xy, ".major")]] <- scales::rescale(tickData[[paste0(xy, "_start")]]) # If it doesn't already exist (for this panel), # generate graticule (as done in, CoordSf$render_bg) @@ -787,9 +785,11 @@ gg2list <- function(p, width = NULL, height = NULL, # set scaleanchor/scaleratio if these are fixed coordinates # the logic here is similar to what p$coordinates$aspect() does, # but the ratio is scaled to the data range by plotly.js - fixed_coords <- c("CoordSf", "CoordFixed", "CoordMap", "CoordQuickmap") - is_fixed <- isFALSE(p$coordinates$is_free()) - if (inherits(p$coordinates, fixed_coords) || is_fixed) { + is_fixed <- inherits( + p$coordinates, + c("CoordSf", "CoordFixed", "CoordMap", "CoordQuickmap") + ) + if (is_fixed || isFALSE(p$coordinates$is_free())) { axisObj$scaleanchor <- anchor ratio <- p$coordinates$ratio %||% 1 axisObj$scaleratio <- if (xy == "y") ratio else 1 / ratio From a94e95db2d8e98d143c0fe8c5f3bee6d75f6a181 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Thu, 5 Jun 2025 16:27:40 -0500 Subject: [PATCH 15/15] Update NEWS.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index cba599e6a6..ad7e39f553 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,7 +6,7 @@ ## Improvements -* Various updates to updates `ggplotly()` to better support recent versions of ggplot2. (#2315, #2368, #2442, thanks @teunbrand). +* Various updates to `ggplotly()` to better support recent versions of ggplot2. (#2315, #2368, #2442, thanks @teunbrand). ## Bug fixes