plotly / plotly.R

An interactive graphing library for R
https://plotly-r.com
Other
2.55k stars 625 forks source link

Range breaks in plotly R #1789

Open rajanprabu opened 4 years ago

rajanprabu commented 4 years ago

Hi,

Recently Plotly introduced breaks on date axes ( plotly v 4.6.0 ). They are pretty handy to remove weekends and missing dates while plotting. So far the fix was to make the Date as type =Category. But this makes the range slider not working. Thats also why this rangebreak was brought up. I dont know if its available in R yet.

A small workable script is given below

library(readr)
library(plotly)

a <- read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")

plot_ly(a[450:500,], x = ~Date, y = ~AAPL.High, type='scatter', mode = 'markers') %>%
  layout(xaxis =  list(
    rangebreaks= list (
      values= c("2016-12-25", "2016-12-24","2016-12-26","2017-01-01"))
  ))

Screenshot of the output:

Screenshot 2020-06-10 at 12 10 56

This doesnt hide the missing dates, but it doesnt give any error either. I was wondering what am I doing wrong here.

Thanks

Additional information: R version 4.0.0 (2020-04-24) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Mojave 10.14.6

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

Random number generation: RNG: Mersenne-Twister Normal: Inversion Sample: Rounding

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages: [1] plotly_4.9.2.1 ggplot2_3.3.0 readr_1.3.1

loaded via a namespace (and not attached): [1] Rcpp_1.0.4.6 rtsdata_0.1.2 pillar_1.4.4 compiler_4.0.0 xts_0.12-0 tools_4.0.0 digest_0.6.25 jsonlite_1.6.1
[9] lifecycle_0.2.0 tibble_3.0.1 gtable_0.3.0 lattice_0.20-41 viridisLite_0.3.0 pkgconfig_2.0.3 rlang_0.4.6 cli_2.0.2
[17] rstudioapi_0.11 crosstalk_1.1.0.1 yaml_2.2.1 curl_4.3 withr_2.2.0 dplyr_0.8.5 httr_1.4.1 vctrs_0.3.1
[25] htmlwidgets_1.5.1 hms_0.5.3 grid_4.0.0 tidyselect_1.1.0 glue_1.4.1 data.table_1.12.8 R6_2.4.1 fansi_0.4.1
[33] purrr_0.3.4 tidyr_1.1.0 magrittr_1.5 scales_1.1.1 ellipsis_0.3.1 htmltools_0.4.0 assertthat_0.2.1 colorspace_1.4-1 [41] lazyeval_0.2.2 munsell_0.5.0 crayon_1.3.4 zoo_1.8-8

janderkran commented 4 years ago

Hi, I think this feature would be very handy. Unfortunately I face the same problem as @rajanprabu and cannot locally reproduce https://plotly.com/r/time-series/ code about rangebreaks.

Thanks,

Jan