Draws a joinpoint figure as an interactive graphic: an htmlwidget made
with the ggiraph package that looks like the static figure and adds
tooltips, linked highlighting and zoom. Hovering a fitted segment shows
its period and APC with confidence interval and p value, and highlights
the segment with its label and band while dimming the rest; hovering an
observation shows its value, confidence interval and fitted trend; hovering
a joinpoint shows its location and confidence interval. The toolbar zooms
and saves the graphic as a PNG image.
Usage
jp_interactive(
x,
plot = c("trend", "apc", "aapc", "selection"),
...,
width = 7.5,
height = 5,
zoom = 5,
embed_fonts = FALSE
)Arguments
- x
A
joinpointobject, or a ggplot made by one of the plot functions of the package withinteractive = TRUE(and possibly modified, for example with further labels or theme settings).- plot
The figure drawn from a
joinpointobject:"trend"(autoplot()),"apc"(plot_apc()),"aapc"(plot_aapc()) or"selection"(plot_selection()).- ...
Further arguments to the plot function, for example
color_by = "trend"orlog_y = TRUE.- width, height
Size of the graphic in inches; the widget scales to the width of its container, keeping this aspect ratio.
- zoom
Maximum zoom factor (
1for no zoom).- embed_fonts
Embed the font files in the widget, so that it looks exactly the same on every computer. By default the text uses fonts found on the system (Arial, Helvetica or DejaVu Sans, for example), which keeps the widget small: about 0.2 MB instead of several MB.
Details
The widget works in the RStudio viewer, R Markdown and Quarto HTML
documents, pkgdown sites and Shiny applications (with
ggiraph::girafeOutput() and ggiraph::renderGirafe()). jp_save()
writes it to a standalone HTML file. Documents rendered to Word or PDF
need the static figures (autoplot() and the other
plot functions).
Examples
tb <- subset(us_mortality, cause == "Tuberculosis")
fit <- joinpoint(tb, year, rate, kmax = 3, ci_method = "parametric")
jp_interactive(fit, log_y = TRUE)
jp_interactive(fit, plot = "apc")
# A modified figure.
g <- ggplot2::autoplot(fit, interactive = TRUE) +
ggplot2::labs(title = "Tuberculosis mortality")
jp_interactive(g)