plotly / plotly/plotly.R

`ggplotly()` function does not respect line width and does not show legend lines of `geom_linearange()`

Open
#2,133 0 comments 1 reaction 0 assignees View on GitHub

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:
2022-05-05 15_21_27-RStudio_ Notebook 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.