dynamicTicks = TRUE is incompatible with grouped geom_line
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
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.6Matrix 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.0locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8time zone: Europe/Madrid
tzcode source: internalattached base packages:
[1] stats graphics grDevices utils datasets methods baseother attached packages:
[1] crosstalk_1.2.1 plotly_4.11.0 dplyr_1.1.4 ggplot2_3.5.2loaded 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
可复现的入口点是所提供示例中的 ggplotly(p1, dynamicTicks = TRUE) 调用,其中 geom_line 按 interaction(patient, gene) 分组;首先隔离这个组合。完成的标准是该调用能够完成且不会出现报告的 ticktext 索引错误,同时保留两条分组线和动态刻度。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100