add_trace: Add trace(s) to a plotly visualization

Description Usage Arguments Author(s) References See Also Examples

View source: R/add.R

Description

Add trace(s) to a plotly visualization

Usage

 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)

Arguments

p

a plotly object

...

Arguments (i.e., attributes) passed along to the trace type. See schema() for a list of acceptable attributes for a given trace type (by going to traces -> type -> attributes). Note that attributes provided at this level may override other arguments (e.g. plot_ly(x = 1:10, y = 1:10, color = I("red"), marker = list(color = "blue"))).

data

A data frame (optional) or crosstalk::SharedData object.

inherit

inherit attributes from plot_ly()?

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")

Author(s)

Carson Sievert

References

http://plotly-book.cpsievert.me/the-plotly-cookbook.html

https://plot.ly/r

https://plot.ly/r/reference/

See Also

plot_ly()

Examples

 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"))

trafficonese/plotly_mini documentation built on Sept. 14, 2019, 9:51 p.m.