Skip to content

Commit 78e671b

Browse files
committed
don't include tick info if _either_ text or value is missing, closes #1725, closes #1721
1 parent b0a4add commit 78e671b

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This is minor patch release with a few minor bug fixes and updates test expectat
55
## BUG FIXES
66

77
* Fixes rendering issues non-HTML **rmarkdown** output formats, which was introduced in the 4.9.2 release (#1702).
8+
* Fixes a `ggplotly()` bug in axis tick translation (#1725, #1721).
89
* `plot_mapbox()` now correctly defaults to a scattermapbox trace (unless z is present, then it defaults to choroplethmapbox) (#1707).
910
* `ggplotly()` now correctly resolves overlapping axis tick text in `coord_sf()` (#1673).
1011
* A false-positive warning is no longer thrown when attempting to cast `toWebGL()` (#1569).

R/ggplotly.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,9 @@ gg2list <- function(p, width = NULL, height = NULL,
693693
tickvals <- rng[[xy]]$break_positions %()% rng[[paste0(xy, ".major")]]
694694

695695
# https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809
696-
ticktext <- ticktext[!is.na(ticktext)]
697-
tickvals <- tickvals[!is.na(tickvals)]
696+
hasTickText <- !(is.na(ticktext) | is.na(tickvals))
697+
ticktext <- ticktext[hasTickText]
698+
tickvals <- tickvals[hasTickText]
698699

699700
axisObj <- list(
700701
# TODO: log type?
Lines changed: 1 addition & 0 deletions
Loading

tests/testthat/test-ggplot-ticks.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,13 @@ test_that("R line breaks are translated to HTML line breaks", {
190190
)
191191
})
192192

193-
193+
test_that("Missing axis ticks are treated correctly", {
194+
# https://github.com/ropensci/plotly/issues/1721
195+
p <- ggplot(data = mtcars, aes(x = qsec, y = disp)) +
196+
geom_point() +
197+
scale_x_continuous(
198+
breaks = pretty(range(mtcars$qsec), n = 10),
199+
labels = pretty(range(mtcars$qsec), n = 10)
200+
)
201+
expect_doppelganger_built(p, "continuous-x-missing")
202+
})

0 commit comments

Comments
 (0)