Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggplotly rewrites axis tick labels (specified in scale_x_continuous) incorrectly #1721

Closed
krystian8207 opened this issue Mar 11, 2020 · 1 comment

Comments

@krystian8207
Copy link

krystian8207 commented Mar 11, 2020

Hi! Thank you for the great package!

Last time when trying to convert ggplot object into plotly I met the following bug.

When specifying labels in scale_x_continuous for original ggplot object and then converting it to plotly with ggplotly the tick labels are moved one tick to the right.

Original ggplot:

library(ggplot2)
library(plotly)

p <- ggplot(data = mtcars, aes(x = qsec, y = disp)) + 
  geom_point() + 
  scale_x_continuous(
    breaks = pretty(range(mtcars$qsec), n = 10),
    labels = pretty(range(mtcars$qsec), n = 10)
  )
p

image

Plotly version:

ggplotly(p)

image

SessionInfo:

R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C              LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.9.2  ggplot2_3.3.0
@krystian8207 krystian8207 changed the title ggplotly rewrites axis labels (scpecified in scale_x_continuous) incorrectly ggplotly rewrites axis tick labels (scpecified in scale_x_continuous) incorrectly Mar 11, 2020
@krystian8207 krystian8207 changed the title ggplotly rewrites axis tick labels (scpecified in scale_x_continuous) incorrectly ggplotly rewrites axis tick labels (specified in scale_x_continuous) incorrectly Mar 11, 2020
@ellisp
Copy link

ellisp commented Mar 23, 2020

I think this is new to ggplot2 v 3.3.0. See https://stackoverflow.com/questions/60807523/how-to-show-correct-horizontal-axis-in-ggplotly-when-it-is-a-date/60808558#60808558 for another example, where dates are labelled wrong by several years. That problem went away for me when I reerted to ggplot2 v 3.2.1. So something changed in ggplot2 that is now being mistaken by plotly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants