ggiraph
ggiraph copied to clipboard
ggiraph plot sizing policy (flexdashboard): scaling plot based on changes in either height or width
First off, thanks so much for your work on this package. I'm a huge fan!
tldr Has there been any updates on scaling of ggiraph plots in flexdashboards to make rescaling responsive to vertical changes in browser window and not just horizontal? Last discussion on this topic was #35
full question
I'm working on a flexdashboard and am unsure of how to setup ggiraph plots to auto-rescale when if the user changes height or width.
By default the plots have an aspect ratio they preserve, and shrink only when width of the browser is reduced (totally unaffected when height of browser window is changed).
Q1: is it possible to have a fixed aspect ratio but where the plots would shrink whenever either height or width were shrunk too small to fit plot.
Q2: Also, can you have a non-fixed aspect ratio that just always scales to the dimensions and aspect ratio of its container?
I've recorded a video of what I observed to be the current default behavior
https://user-images.githubusercontent.com/73202525/178777335-c1391ba2-ed3a-4ed7-a15c-a546a2fb7f22.mov
My test RMD: ggiraph_sizing.Rmd.txt
SessionInfo
─ Session info ───────
setting value
version R version 4.2.0 (2022-04-22)
os macOS Monterey 12.0.1
system x86_64, darwin17.0
ui RStudio
language (EN)
collate en_AU.UTF-8
ctype en_AU.UTF-8
tz Australia/Sydney
date 2022-07-14
rstudio 2022.02.3+492 Prairie Trillium (desktop)
pandoc 2.17.1.1 @ /Applications/RStudio.app/Contents/MacOS/quarto/bin/ (via rmarkdown)
─ Packages ───────
package * version date (UTC) lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.2.0)
cli 3.3.0 2022-04-25 [1] CRAN (R 4.2.0)
colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.0)
crayon 1.5.1 2022-03-26 [1] CRAN (R 4.2.0)
DBI 1.1.3 2022-06-18 [1] CRAN (R 4.2.0)
digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0)
dplyr 1.0.9 2022-04-28 [1] CRAN (R 4.2.0)
ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0)
evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0)
fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.0)
fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0)
flexdashboard * 0.5.2 2020-06-24 [1] CRAN (R 4.2.0)
generics 0.1.2 2022-01-31 [1] CRAN (R 4.2.0)
ggiraph * 0.8.2 2022-02-22 [1] CRAN (R 4.2.0)
ggplot2 * 3.3.6 2022-05-03 [1] CRAN (R 4.2.0)
glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0)
gtable 0.3.0 2019-03-25 [1] CRAN (R 4.2.0)
htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.2.0)
htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.2.0)
jsonlite 1.8.0 2022-02-22 [1] CRAN (R 4.2.0)
knitr 1.39 2022-04-26 [1] CRAN (R 4.2.0)
lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.2.0)
magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0)
pillar 1.7.0 2022-02-01 [1] CRAN (R 4.2.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0)
purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0)
Rcpp 1.0.9 2022-07-08 [1] CRAN (R 4.2.0)
rlang 1.0.3 2022-06-27 [1] CRAN (R 4.2.0)
rmarkdown 2.14 2022-04-25 [1] CRAN (R 4.2.0)
rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0)
scales 1.2.0 2022-04-13 [1] CRAN (R 4.2.0)
sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0)
systemfonts 1.0.4 2022-02-11 [1] CRAN (R 4.2.0)
tibble 3.1.7 2022-05-03 [1] CRAN (R 4.2.0)
tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.2.0)
utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0)
uuid 1.1-0 2022-04-19 [1] CRAN (R 4.2.0)
vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.2.0)
withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0)
xfun 0.31 2022-05-10 [1] CRAN (R 4.2.0)
[1] /Users/selkamand/Library/R/x86_64/4.2/library
[2] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
Hello
No change happened on that subject.
You can either make it responsive (with width) or not responsive by using opts_sizing(rescale = FALSE)
.
Q1: is it possible to have a fixed aspect ratio but where the plots would shrink whenever either height or width were shrunk too small to fit plot.
No sorry.
Q2: Also, can you have a non-fixed aspect ratio that just always scales to the dimensions and aspect ratio of its container?
No. There is always a fixed aspect ratio.
Hiya @davidgohel
Thanks for the response.
Followup questions: Q3 is responsive rescaling based on both width and height (with/without fixed aspect ratio) a feature that you would consider adding at some stage? If so I'll leave this open as a feature request unless you'd prefer I open a new issue
Q4 If not, is there an obvious workaround - beyond setting width greater than height?
Basically I'd love to get to functionality similar to plotly (with optional fixed aspect ratio if I want to be super greedy. Video example below (plotly on left, ggiraph on right)
https://user-images.githubusercontent.com/73202525/179382832-cb8a3fce-c687-4687-9d56-1ee5e36d88d5.mov
The rationale of asking these questions is that I'm a huge fan of the ggiraph package and am keen to make it the main interactive graphing library I use for dashboarding. My inability to scaling working is currently the only blocker at present
Q3, no we need an aspect ratio, it is generated by R graphic engine.
Q4, no