# NOT RUN {
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,
# but can be overwritten
plot_ly(economics, x = ~date, y = ~uempmed, color = I("red")) %>%
add_lines() %>%
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)
p <- plot_ly(plotly::wind, r = ~r, t = ~t) %>% add_area(color = ~nms)
layout(p, radialaxis = list(ticksuffix = "%"), orientation = 270)
ds <- data.frame(
labels = c("A", "B", "C"),
values = c(10, 40, 60)
)
plot_ly(ds, labels = ~labels, values = ~values) %>%
add_pie() %>%
layout(title = "Basic Pie Chart using Plotly")
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(x = c(0, 0, 1), y = c(0, 1, 0), z = c(0, 0, 0)) %>% add_mesh()
# }
Run the code above in your browser using DataLab