Skip to content

Commit 4be6198

Browse files
cpsievertclaude
andcommitted
Fix #2462: dynamicTicks now works with grouped geom_line
NA values in trace data (e.g., from geom_line gaps between groups) now correctly remain as NA when mapping categorical data back to ticktext labels. Previously, which.min() on NA values returned an empty vector which caused an indexing error. Fixes #2462 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6a47185 commit 4be6198

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

R/ggplotly.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,12 @@ gg2list <- function(p, width = NULL, height = NULL,
843843

844844
# inverse transform categorical data based on tickvals/ticktext
845845
if (isDiscreteType) {
846-
traces <- lapply(traces, function(tr) {
846+
traces <- lapply(traces, function(tr) {
847847
# map x/y trace data back to the 'closest' ticktext label
848848
# http://r.789695.n4.nabble.com/check-for-nearest-value-in-a-vector-td4369339.html
849849
tr[[xy]]<- vapply(tr[[xy]], function(val) {
850+
# NA values (e.g., geom_line gaps) should remain NA
851+
if (is.na(val)) return(NA_character_)
850852
with(axisObj, ticktext[[which.min(abs(tickvals - val))]])
851853
}, character(1))
852854
tr

0 commit comments

Comments
 (0)