Description Usage Arguments Author(s) References See Also Examples
Add trace(s) to a plotly visualization
1 2 3 4 5 6 7 8 9 10 11 12 | add_trace(p, ..., data = NULL, inherit = TRUE)
add_markers(p, x = NULL, y = NULL, z = NULL, ..., data = NULL,
inherit = TRUE)
add_text(p, x = NULL, y = NULL, z = NULL, text = NULL, ...,
data = NULL, inherit = TRUE)
add_bars(p, x = NULL, y = NULL, ..., data = NULL, inherit = TRUE)
add_ribbons(p, x = NULL, ymin = NULL, ymax = NULL, ...,
data = NULL, inherit = TRUE)
|
p |
a plotly object |
... |
Arguments (i.e., attributes) passed along to the trace |
data |
A data frame (optional) or crosstalk::SharedData object. |
inherit |
inherit attributes from |
x |
the x variable. |
y |
the y variable. |
z |
a numeric matrix |
text |
textual labels. |
ymin |
a variable used to define the lower boundary of a polygon. |
ymax |
a variable used to define the upper boundary of a polygon. |
xend |
"final" x position (in this context, x represents "start") |
yend |
"final" y position (in this context, y represents "start") |
Carson Sievert
http://plotly-book.cpsievert.me/the-plotly-cookbook.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # the `plot_ly()` function initiates an object, and if no trace type
# is specified, it sets a sensible default
p <- plot_ly(economics, x = ~date, y = ~uempmed)
p
# some `add_*()` functions are a specific case of a trace type
# for example, `add_markers()` is a scatter trace with mode of markers
add_markers(p)
# scatter trace with mode of text
add_text(p, text = "%")
# scatter trace with mode of lines
add_paths(p)
# like `add_paths()`, but ensures points are connected according to `x`
add_lines(p)
# if you prefer to work with plotly.js more directly, can always
# use `add_trace()` and specify the type yourself
add_trace(p, type = "scatter", mode = "markers+lines")
# mappings provided to `plot_ly()` are "global", but can be overwritten
plot_ly(economics, x = ~date, y = ~uempmed, color = I("red"), showlegend = FALSE) %>%
add_lines() %>%
add_markers(color = ~pop)
# a number of `add_*()` functions are special cases of the scatter trace
plot_ly(economics, x = ~date) %>%
add_ribbons(ymin = ~pce - 1e3, ymax = ~pce + 1e3)
# use `group_by()` (or `group2NA()`) to apply visual mapping
# once per group (e.g. one line per group)
txhousing %>%
group_by(city) %>%
plot_ly(x = ~date, y = ~median) %>%
add_lines(color = I("black"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.