Use an interactive graph as a widget, a ggplot or a file
Source:R/graph.R, R/race.R
graph_widget.RdA bar chart race from ggrace(), or a graph built by ggcausal(),
ggnma(), ggmeta(), ggfunnel(),
ggleague(), ggkm(), ggswimmer(), ggnomogram(), ggchoropleth(),
ggdiagnostic(), ggsensitivity(), ggmultiverse(), ggresponder(),
cinema_league(), cinema_contribution(), cinema_clinical(),
cinema_incoherence() or cinema_network()
prints as an interactive widget. These
functions give the other forms it can take. graph_widget() returns the
'htmlwidgets' object, for use in 'shiny' or to save with
htmlwidgets::saveWidget(). graph_plot() returns the underlying
ggplot, which draws as an ordinary static plot. graph_save() writes
either form to a file chosen by its extension.
Arguments
- x
A race from
ggrace(), whose static copy is its last frame, or a graph fromggcausal(),ggnma(),ggmeta(),ggfunnel(),ggleague(),ggkm(),ggswimmer(),ggnomogram(),ggchoropleth(),ggdiagnostic(),ggsensitivity(),ggmultiverse(),ggresponder(),cinema_league(),cinema_contribution(),cinema_clinical(),cinema_incoherence()orcinema_network().- theme
For the widget,
"auto"follows the page it sits on: a dark 'pkgdown' or 'bslib' page (data-bs-theme="dark"), a dark Quarto theme, a page markeddata-theme="dark", or, for a widget saved as its own page, the viewer's system setting."light"and"dark"fix it. Forgraph_plot()and a PNG fromgraph_save(),"light"or"dark"picks the colors of the static copy; a saved.htmldefaults to"auto"and a.pngto"light".- file
Output path.
.htmlwrites the widget as a single file, which needs 'pandoc';.pngwrites a static image with 'ragg'.- res
Resolution of a PNG in pixels per inch.
- ...
Passed to
knitr::knit_print().
Value
graph_widget() returns an htmlwidget and graph_plot() a
ggplot. graph_save() returns file, invisibly.
Details
The graph is laid out at a fixed size, so its boxes always fit their
labels. The widget scales to the width of the page it sits in; a static
copy should be drawn at x$width by x$height inches, which is what
graph_save() does. The widget embeds a web copy of Lato, so it looks the
same on machines without the font.
On a dark page the widget switches to a dark palette of its own: the background, text, lines and neutral fills take their dark counterparts, colors that carry meaning keep their hue, and the hover cards and panels follow. It also follows a page that switches theme while it is open.