Description Usage Arguments Details Author(s) References See Also
This function maps R objects to plotly.js,
an (MIT licensed) web-based interactive charting library. It provides
abstractions for doing common things (e.g. mapping data values to
fill colors (via color
) or creating animations (via frame
)) and sets
some different defaults to make the interface feel more 'R-like'
(i.e., closer to plot()
and ggplot2::qplot()
).
1 2 3 4 5 |
data |
A data frame (optional) or crosstalk::SharedData object. |
... |
Arguments (i.e., attributes) passed along to the trace |
type |
A character string specifying the trace type (e.g. |
name |
Values mapped to the trace's name attribute. Since a trace can
only have one name, this argument acts very much like |
color |
Values mapped to relevant 'fill-color' attribute(s)
(e.g. fillcolor,
marker.color,
textfont.color, etc.).
The mapping from data values to color codes may be controlled using
|
colors |
Either a colorbrewer2.org palette name (e.g. "YlOrRd" or "Blues"),
or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
or a color interpolation function like |
alpha |
A number between 0 and 1 specifying the alpha channel applied to |
stroke |
Similar to |
strokes |
Similar to |
alpha_stroke |
Similar to |
size |
(Numeric) values mapped to relevant 'fill-size' attribute(s)
(e.g., marker.size,
textfont.size,
and error_x.width).
The mapping from data values to symbols may be controlled using
|
sizes |
A numeric vector of length 2 used to scale |
span |
(Numeric) values mapped to relevant 'stroke-size' attribute(s)
(e.g.,
marker.line.width,
line.width for filled polygons,
and error_x.thickness)
The mapping from data values to symbols may be controlled using
|
spans |
A numeric vector of length 2 used to scale |
symbol |
(Discrete) values mapped to marker.symbol.
The mapping from data values to symbols may be controlled using
|
symbols |
A character vector of pch values or symbol names. |
linetype |
(Discrete) values mapped to line.dash.
The mapping from data values to symbols may be controlled using
|
linetypes |
A character vector of |
split |
(Discrete) values used to create multiple traces (one trace per value). |
frame |
(Discrete) values used to create animation frames. |
width |
Width in pixels (optional, defaults to automatic sizing). |
height |
Height in pixels (optional, defaults to automatic sizing). |
source |
a character string of length 1. Match the value of this string
with the source argument in |
Unless type
is specified, this function just initiates a plotly
object with 'global' attributes that are passed onto downstream uses of
add_trace()
(or similar). A formula must always be used when
referencing column name(s) in data
(e.g. plot_ly(mtcars, x = ~wt)
).
Formulas are optional when supplying values directly, but they do
help inform default axis/scale titles
(e.g., plot_ly(x = mtcars$wt)
vs plot_ly(x = ~mtcars$wt)
)
Carson Sievert
https://plotly-book.cpsievert.me/the-plotly-cookbook.html
For initializing a plotly-geo object: plot_geo()
For initializing a plotly-mapbox object: plot_mapbox()
For translating a ggplot2 object to a plotly object: ggplotly()
For modifying any plotly object: layout()
, add_trace()
, style()
For linked brushing: highlight()
For arranging multiple plots: subplot()
, crosstalk::bscols()
For inspecting plotly objects: plotly_json()
For quick, accurate, and searchable plotly.js reference: schema()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.