Introduction
Plotly creates interactive plots that work in R Markdown and Shiny. It produces web-based visualizations.
Basic Plotly
library(plotly)
# Scatter plot
plot_ly(data, x = ~x, y = ~y, type = "scatter", mode = "markers")
# Line plot
plot_ly(data, x = ~x, y = ~y, type = "scatter", mode = "lines")
Plot Types
# Bar chart
plot_ly(data, x = ~category, y = ~value, type = "bar")
# Box plot
plot_ly(data, x = ~category, y = ~value, type = "box")
# Histogram
plot_ly(data, x = ~value, type = "histogram")
Customization
plot_ly(data, x = ~x, y = ~y) %>%
add_markers(marker = list(size = 10, color = "blue")) %>%
layout(title = "My Plot",
xaxis = list(title = "X"),
yaxis = list(title = "Y"))
Using with ggplot2
library(ggplot2)
ggplotly(ggplot(data, aes(x, y)) + geom_point())
Summary
Plotly creates interactive visualizations. Use it for web-ready plots.