plotly / plotly/plotly.R

dynamicTicks = TRUE is incompatible with grouped geom_line

Abierto
#2,462 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
R
Estrellas
2.7k
Forks
641
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hi,

I am trying to make an interactive plot using crosstalk where the user selects a variable from a drop down menu and the plot updates to show only data for it.

library(ggplot2)
library(dplyr)
library(plotly)
library(crosstalk)

#### DATA

df <- rbind.data.frame(
  cbind.data.frame(
    gene = "geneA",
    patient = rep(c("patient_A", "patient_B"), each=2),
    time = rep(c("t1","t2"),times=2),
    value = c(1.25, 1.5, 2, 1.75)
  ),
  cbind.data.frame(
    gene = "geneB",
    patient = rep(c("patient_A", "patient_B"), each=2),
    time = rep(c("t1","t2"),times=2),
    value = c(1.25, 0.25, 3, 3.5)
  )
)

df$time <- factor(df$time)
df$gene <- factor(df$gene)
df$patient <- factor(df$patient)
df$gene_x_patient <- factor(paste0(df$gene,"_",df$patient))


#### HIGHLIGHT
df1 <-   highlight_key(df, ~gene, group="Gene name")

#### FILTER SELECT
filter_gene_1 <- filter_select("id_filter_counts", "Selected gene", df1, ~gene, multiple = FALSE)

#### FIGURE
p1 <- ggplot(df1, aes(x=time, y=value)) +
  geom_line(aes(group=interaction(patient,gene))) +
  geom_point(aes(shape=patient, fill=gene), size=5) +
  scale_shape_manual(values=c(21,25)) +
  guides(
        fill = guide_legend(
           override.aes = list(alpha=1, shape=21, size=5))  )

p1_highlight <- ggplotly(p1,
           # dynamicTicks = TRUE,
           width=600,
           height=450,
           tooltip = "text"
           )  %>%
    hide_guides() %>%
    config(displayModeBar = F) %>%
    layout( 
          xaxis = list(fixedrange = TRUE),
          yaxis = list(fixedrange = TRUE)
          ) %>%
  highlight(on = NULL, off=NULL)     

#### PRINT
bscols(
  filter_gene_1,
  p1_highlight,
  widths = c(8,6)
)

This generates a figure like this:

https://github.com/user-attachments/assets/149370ac-fe85-413d-bf6b-67d62b7f6272

If I remove the geom_line call, and uncomment dynamicTicks = TRUE, I get this:

https://github.com/user-attachments/assets/e6898855-8634-4d3b-a6ac-1a66cd4fcc76

However, if I use both geom_line and dynamicTicks = TRUE, then, the ggplotly call returns this error:

Error in ticktext[[which.min(abs(tickvals - val))]] :
attempt to select less than one element in get1index

I haven't seen this reported anywhere. I'd really like to use both options at once.

sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: x86_64-apple-darwin20
Running under: macOS Monterey 12.7.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.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

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

time zone: Europe/Madrid
tzcode source: internal

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

other attached packages:
[1] crosstalk_1.2.1 plotly_4.11.0 dplyr_1.1.4 ggplot2_3.5.2

loaded via a namespace (and not attached):
[1] gtable_0.3.6 jsonlite_2.0.0 compiler_4.4.0
[4] promises_1.3.3 tidyselect_1.2.1 Rcpp_1.1.0
[7] dichromat_2.0-0.1 later_1.4.2 tidyr_1.3.1
[10] scales_1.4.0 yaml_2.3.10 fastmap_1.2.0
[13] mime_0.13 R6_2.6.1 labeling_0.4.3
[16] generics_0.1.4 knitr_1.50 htmlwidgets_1.6.4
[19] tibble_3.3.0 shiny_1.11.1 pillar_1.11.0
[22] RColorBrewer_1.1-3 rlang_1.1.6 httpuv_1.6.16
[25] xfun_0.52 lazyeval_0.2.2 viridisLite_0.4.2
[28] cli_3.6.5 withr_3.0.2 magrittr_2.0.3
[31] digest_0.6.37 grid_4.4.0 xtable_1.8-4
[34] rstudioapi_0.17.1 lifecycle_1.0.4 vctrs_0.6.5
[37] evaluate_1.0.4 glue_1.8.0 data.table_1.17.8
[40] farver_2.1.2 purrr_1.1.0 httr_1.4.7
[43] tools_4.4.0 pkgconfig_2.0.3 htmltools_0.5.8.1

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

El punto de entrada reproducible es la llamada ggplotly(p1, dynamicTicks = TRUE) en el ejemplo proporcionado, con geom_line agrupado por interaction(patient, gene); empieza por aislar esa combinación. Se considera terminado cuando la llamada se completa sin el error de indexación de ticktext informado y se conservan tanto las líneas agrupadas como los ticks dinámicos.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
r
Área
data-visualization
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.