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 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 | add_trace(p, ..., color, symbol, size, linetype, data = NULL)
add_markers(p, x = NULL, y = NULL, z = NULL, ...)
add_text(p, x = NULL, y = NULL, z = NULL, text = NULL, ...)
add_paths(p, x = NULL, y = NULL, z = NULL, ...)
add_lines(p, x = NULL, y = NULL, z = NULL, ...)
add_segments(p, x = NULL, y = NULL, xend = NULL, yend = NULL, ...)
add_polygons(p, x = NULL, y = NULL, ...)
add_ribbons(p, x = NULL, ymin = NULL, ymax = NULL, ...)
add_area(p, x = NULL, ymax = NULL, ...)
add_bars(p, x = NULL, y = NULL, ...)
add_histogram(p, x = NULL, y = NULL, ...)
add_histogram2d(p, x = NULL, y = NULL, z = NULL, ...)
add_histogram2dcontour(p, x = NULL, y = NULL, z = NULL, ...)
add_heatmap(p, z = NULL, ...)
add_contour(p, z = NULL, ...)
add_boxplot(p, x = NULL, y = NULL, ...)
add_surface(p, z = NULL, ...)
add_scattergeo(p, geo = "geo", ...)
add_choropleth(p, z = NULL, ...)
|
p |
a plotly or ggplot object. |
... |
These arguments are documented in the references section below. Note that acceptable arguments depend on the trace type. |
color |
Either a variable name or a vector to use for color mapping. |
symbol |
Either a variable name or a (discrete) vector to use for symbol encoding. |
size |
A variable name or numeric vector to encode the size of markers. |
linetype |
Either a variable name or a (discrete) vector to use for linetype encoding. |
data |
A data frame to associate with this trace (optional). If not
provided, arguments are evaluated using the data frame in |
x |
the x variable. |
y |
the y variable. |
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. |
alpha |
alpha channel applied to color (on 0-1 scale). |
Carson Sievert
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 38 39 40 41 42 43 44 45 46 47 48 49 50 | p <- plot_ly(economics, x = ~date, y = ~uempmed)
p
p %>% add_markers()
p %>% add_lines()
p %>% add_text(text = ".")
# attributes declared in plot_ly() carry over to downstream traces
plot_ly(economics, x = ~date, y = ~uempmed) %>%
add_lines(line = list(color = "red")) %>%
add_markers(color = ~pop) %>%
layout(showlegend = FALSE)
txhousing %>%
group_by(city) %>%
plot_ly(x = ~date, y = ~median) %>%
add_lines(fill = "black")
ggplot2::map_data("world", "canada") %>%
group_by(group) %>%
plot_ly(x = ~long, y = ~lat) %>%
add_polygons(hoverinfo = "none") %>%
add_markers(text = ~paste(name, "<br />", pop), hoverinfo = "text",
data = maps::canada.cities) %>%
layout(showlegend = FALSE)
plot_ly(economics, x = ~date) %>%
add_ribbons(ymin = ~pce - 1e3, ymax = ~pce + 1e3)
huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
plot_ly(huron, x = ~year, ymax = ~level) %>% add_area()
library(dplyr)
mtcars %>%
count(vs) %>%
plot_ly(x = ~vs, y = ~n) %>%
add_bars()
plot_ly(x = ~rnorm(100)) %>% add_histogram()
plot_ly(x = ~LETTERS, y = ~LETTERS) %>% add_histogram2d()
z <- as.matrix(table(LETTERS, LETTERS))
plot_ly(x = ~LETTERS, y = ~LETTERS, z = ~z) %>% add_histogram2d()
plot_ly(MASS::geyser, x = ~waiting, y = ~duration) %>%
add_histogram2dcontour()
plot_ly(z = ~volcano) %>% add_heatmap()
plot_ly(z = ~volcano) %>% add_contour()
plot_ly(mtcars, x = ~factor(vs), y = ~mpg) %>% add_boxplot()
plot_ly(z = ~volcano) %>% add_surface()
plot_ly() %>% add_scattergeo()
density <- state.x77[, "Population"] / state.x77[, "Area"]
plot_ly(z = ~density) %>%
add_choropleth(locations = state.abb, locationmode = 'USA-states') %>%
layout(geo = list(scope = "usa"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.