plotly / plotly/plotly.R

tooltip=text does not allow for layers with different alpha values

Open
#2,181 0 comments 0 reactions 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

If ggplotly(tooltip=) is used with a ggplot object that includes 2 layers with different alpha values, then the lower alpha will be used for all layers.


Brief description of the problem

# geom_linerange has a lower alpha (0.3) than geom_point (1)
p = mpg %>%
  group_by(model) %>%
  summarize(mean_mpg = mean(hwy),
            sd_mpg = sd(hwy)) %>%
  ggplot(aes(model, mean_mpg)) +
  geom_linerange(aes(ymin=mean_mpg - sd_mpg, 
                     ymax=mean_mpg + sd_mpg), alpha=0.3) +
  geom_point() +
  theme(
    axis.text.x = element_text(angle=45, hjust=1)
  )
ggplotly(p)
# both layers have an alpha of 0.3
p = mpg %>%
  group_by(model) %>%
  summarize(mean_mpg = mean(hwy),
            sd_mpg = sd(hwy)) %>%
  ggplot(aes(model, mean_mpg, text=model)) +
  geom_linerange(aes(ymin=mean_mpg - sd_mpg, 
                     ymax=mean_mpg + sd_mpg), alpha=0.3) +
  geom_point() +
  theme(
    axis.text.x = element_text(angle=45, hjust=1)
  )
ggplotly(p, tooltip='text')

sessionInfo

R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.5.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] heatmaply_1.3.0   viridis_0.6.2     viridisLite_0.4.1 gtsummary_1.6.1   skimr_2.1.4       plotly_4.10.0     ggplot2_3.3.6    
 [8] tidytable_0.8.1   data.table_1.14.2 dplyr_1.0.10     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9          lattice_0.20-45     tidyr_1.2.1         assertthat_0.2.1    digest_0.6.29       foreach_1.5.2      
 [7] utf8_1.2.2          plyr_1.8.7          R6_2.5.1            repr_1.1.4          httr_1.4.4          pillar_1.8.1       
[13] rlang_1.0.5         lazyeval_0.2.2      Matrix_1.4-1        labeling_0.4.2      splines_4.2.1       webshot_0.5.3      
[19] stringr_1.4.1       htmlwidgets_1.5.4   munsell_0.5.0       compiler_4.2.1      xfun_0.32           pkgconfig_2.0.3    
[25] base64enc_0.1-3     mgcv_1.8-40         htmltools_0.5.3     tidyselect_1.1.2    tibble_3.1.8        gridExtra_2.3      
[31] seriation_1.3.6     codetools_0.2-18    dendextend_1.16.0   fansi_1.0.3         crayon_1.5.1        withr_2.5.0        
[37] commonmark_1.8.0    grid_4.2.1          registry_0.5-1      nlme_3.1-157        jsonlite_1.8.0      gtable_0.3.1       
[43] lifecycle_1.0.2     magrittr_2.0.3      scales_1.2.1        cli_3.4.0           stringi_1.7.8       reshape2_1.4.4     
[49] farver_2.1.1        renv_0.15.5         broom.helpers_1.8.0 ellipsis_0.3.2      generics_0.1.3      vctrs_0.4.1        
[55] RColorBrewer_1.1-3  iterators_1.0.14    tools_4.2.1         forcats_0.5.2       glue_1.6.2          purrr_0.3.4        
[61] crosstalk_1.2.0     fastmap_1.1.0       yaml_2.3.5          colorspace_2.0-3    TSP_1.2-1           gt_0.7.0           
[67] knitr_1.40          sass_0.4.2

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 supplied R example with ggplotly(tooltip='text') and compare the rendered alpha values for geom_linerange and geom_point. Trace the ggplotly conversion path for layered plots and verify that each layer preserves its own alpha rather than applying the lowest value to all layers. Done means the two layers render with their specified alpha values.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.