plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

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

Open saimonduquet opened this issue 3 years ago • 0 comments


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

saimonduquet avatar May 05 '22 13:05 saimonduquet