The sizing behavior will be the following:
When ggiraph object is printed from rstudio, it should be displayed in the viewer or in an external brower.
width
(we will talk about it later) won’t have any effect.When ggiraph object is printed within an Rmd
document, the ggiraph object will scale to an optimum width. Argument width
can be used to control the maximum width of the graph in the web page: width=1
will use the whole available width space and width=.7
will use the 70% of the available width.
When ggiraph object is printed within a shiny application, the ggiraph object will scale to an optimum dimension to make sure the whole graphic can be seen without scrooling. Argument width
can be used to control the maximum size of the graph in the responsive component. Arguments width
and height
of ggiraphOutput
have no effects.
When ggiraph object is printed within a flexdashboard document, argument flexdashboard
will have to be set to TRUE, it will make sure the whole graphic fits the box used as container. If flexdashboard
is set to FALSE, the ggiraph object will not be correctly sized within the box.
If flexdashboard
is set to TRUE accidentally in a non flexdashboard document, the graphic will not be displayed.
library(ggiraph)
gg_point = ggplot(mtcars, aes(x = wt, y = drat, color = disp) ) +
geom_point() + theme_minimal()
ggiraph(code = {print(gg_point)}, zoom_max = 1, width = 0.25)
ggiraph(code = {print(gg_point)}, zoom_max = 1, width = 0.50)
ggiraph(code = {print(gg_point)}, zoom_max = 1, width = 0.75)
An flexdashboard document example can be found in package folder: rmd/flexdashboard/flexdashboard.Rmd
.