A figure holds a list of traces (data) and a layout. Everything is
validated against the plotly.js schema. Printing a figure renders it as an
htmlwidget.
Arguments
- data
A trace (e.g. from
go_scatter()), a list of traces, or a figure (or a list withdataandlayoutelements) to copy. Traces may be graph objects or named lists with atypeelement. Or a data frame: the figure starts without traces, and formula properties of lateradd_<trace>()calls (e.g.add_scatter(x = ~col)) are evaluated in it. The data frame is kept with the figure in R (attribute"plotly_data") but is not sent to the browser; only the values traces use are. A crosstalk::SharedData works the same way, and the traces whose points are its rows are linked to its crosstalk group (seehighlight()).- layout
A
go_layout()object or a named list of layout properties.- frames
Animation frames: a list of named lists with
name,data(a list of traces), and optionallylayout,group,tracesandbaseframeelements (see https://plotly.com/javascript/animations/).- skip_invalid
If
TRUE, silently drop invalid properties instead of raising an error.
Examples
fig <- go_figure(
data = go_scatter(x = 1:3, y = c(2, 1, 3)),
layout = go_layout(title = "A figure")
)
fig <- fig |>
add_scatter(x = 1:3, y = c(3, 2, 1), mode = "markers") |>
update_layout(xaxis_title = "x")
if (interactive()) print(fig)
# pipe in a data frame and refer to its columns with formulas
px_data_iris() |>
go_figure() |>
add_scatter(x = ~sepal_length, y = ~sepal_width, mode = "markers", name = "sepal") |>
add_scatter(x = ~petal_length, y = ~petal_width, mode = "markers", name = "petal")