`ggplotly()` function does not respect line width and does not show legend lines of `geom_linearange()`
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
Trying to apply ggplotly() to the following ggplot + geom_linerange() resulted in a faulted graph: the line width is not respected (or considered) and the legend does not show the lines for each key (what line of what color corresponds to each entry?)
``` r
library(tidyverse)
library(plotly)
df = tibble(
task = c("Job A", "Job B", "Job C", "Job A"),
start = c(0, 5, 10, 6),
end = c(4, 9, 15, 7),
resource=c ('Alex', 'Max', 'Max', 'Alex')
)
p <- ggplot(data = df,
aes(x = start,
y = task
)
) +
geom_linerange(aes(xmin = start,
xmax = end,
color = resource
),
size = 5.5,
alpha = 0.76
) +
labs(x = "Time (s)",
y = "Tasks",
color = "",
title = "Gantt plot (ggplot)")
print(p)
ggplot output:

but ggplotly:
ply <- ggplotly(p)
print(ply)
output:

Session info
sessionInfo()
#> R version 4.1.3 (2022-03-10)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19043)
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] plotly_4.10.0 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.9
#> [5] purrr_0.3.4 readr_2.1.2 tidyr_1.2.0 tibble_3.1.7
#> [9] ggplot2_3.3.6 tidyverse_1.3.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the issue's reproducible R example with ggplotly() and compare it with the ggplot output. Trace how geom_linerange() is converted and how its size and resource colour mapping reach the interactive graph. Done means the converted plot respects the requested line width and the legend displays representative lines for each resource.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100