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,
diff --git a/NEWS.md b/NEWS.md
index 138ad21266..ad7e39f553 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 `ggplotly()` to better support recent versions of ggplot2. (#2315, #2368, #2442, thanks @teunbrand).
## Bug fixes
diff --git a/R/ggplotly.R b/R/ggplotly.R
index 93d158813c..973a31ebc1 100644
--- a/R/ggplotly.R
+++ b/R/ggplotly.R
@@ -668,7 +668,9 @@ gg2list <- function(p, width = NULL, height = NULL,
"\\*\\s+degree[ ]?[\\*]?", "°",
gsub("\"", "", tickData[["degree_label"]])
)
- rng[[paste0(xy, ".major")]] <- tickData[[paste0(xy, "_start")]]
+ # 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")]])
# If it doesn't already exist (for this panel),
# generate graticule (as done in, CoordSf$render_bg)
@@ -742,8 +744,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?
@@ -783,8 +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")
- if (inherits(p$coordinates, fixed_coords)) {
+ 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
@@ -1436,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(
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(
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
diff --git a/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg b/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg
index 6926445f0d..4d59ec12f6 100644
--- a/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg
+++ b/tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg
@@ -1 +1 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
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 @@
-
+
diff --git a/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg b/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg
index 5a72f2d81d..14f39817be 100644
--- a/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg
+++ b/tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg
@@ -1 +1 @@
-
+
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 @@
-
+
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 @@
-
+
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")
})
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", {