Display an age-year table with Annual trends and Age profiles buttons, using the same plots and controls as the dashboard. Each view retains its selected animation frame, axis scale, confidence intervals and legend selections.
Arguments
- data
Data frame containing numeric year and age columns, plus the estimates or observations required by the plotting function.
- plot
Function used to draw each view. Defaults to
plot_trend(); useplot_obs_pred()for observations and predictions. A custom function must acceptdata,x,xlab,frameand additional plotting arguments, and return a Plotly object. Add custom layers inside that function.- x
Formula specifying x variable
- xlab
Label for the x-axis.
- frame
Formula selecting the initial view:
~ agefor Annual trends (the default), or~ yearwithx = ~ agefor Age profiles. Other frame/axis combinations produce a single ordinary plot.- ...
Additional arguments to pass to
plotly::plot_ly()such ascolor,colors, etc.
Value
A browsable HTML container holding two Plotly widgets for age-year
views. Other frame/axis combinations return the supplied plotting function's
Plotly object, as do single-age tables. Modify individual plots through
plot before assembly.
Details
The two views use separate widgets, without refitting or changing the input
table. Projection boundaries appear only on year axes; projection years are
identified in the age-profile selector and default hover text. Multiple
displays can be embedded in the same HTML document independently.
A single-age table instead returns an annual Plotly trend labeled with its
age, without animation or view buttons.
Use plot_trend() or plot_obs_pred() directly for a single view; their
returned Plotly objects remain available for adding layers or changing layout.
Examples
d <- expand.grid(year = 2000:2004, age = 1:3)
d$est <- exp(0.1 * (d$year - 2000) + 0.2 * d$age)
annual <- plot_age_year(d, ylab = "Abundance")
profiles <- plot_age_year(d, x = ~age, xlab = "Age", frame = ~year)
d$pred <- d$est
d$obs <- d$est * 1.1
catch_views <- plot_age_year(d, plot = plot_obs_pred, ylab = "Catch")
# Print a view to display it, or save it with htmltools::save_html().