MATH/COSC 3570 Introduction to Data Science
plot_ly()
, plot_geo()
, etc.ggplotly()
into a plotly objectThe 1st argument is a plotly object.
Other arguments include legend
, margins
, size
, etc.
add_contour()
, add_boxplot()
, etc.add_markers()
for scatterplots.plotly::ggplotly()
translate ggplot2 to plotly.14-plotly (Present your work!)
In lab.qmd ## Lab 14
section,
Load tidyverse and plotly and the loans.csv
data.
Generate a plot using plotly. An example is shown below. Welcome to create a more fancy one!
mpg |>
group_by(model) |>
summarise(c = mean(cty), h = mean(hwy)) |>
mutate(model = forcats::fct_reorder(model, c)) |>
plot_ly() |>
add_segments(x = ~c, y = ~model,
xend = ~h, yend = ~model,
color = I("gray"), showlegend = FALSE) |>
add_markers(x = ~c, y = ~model,
color = I("blue"),
name = "mpg city") |>
add_markers(x = ~h, y = ~model,
color = I("red"),
name = "mpg highway") |>
plotly::layout(xaxis = list(title = "Miles per gallon"))
pop_den <- datasets::state.x77[, "Population"] / state.x77[, "Area"]
g <- list(scope = 'usa',
projection = list(type = 'albers usa'),
lakecolor = toRGB('white'))
plot_geo() |>
add_trace(z = ~pop_den, text = state.name, span = I(0),
locations = state.abb, locationmode = 'USA-states') |>
plotly::layout(geo = g)
gganimate