Articles - R packages

Plotly: Create Interactive Plots in R

  |   969  |  Post a comment  |  R packages  |  ggplot2, plotly, Interactive plots


Plotly R package makes interactive, publication-quality graphs online. Examples of how to make line plots, scatter plots, area charts, bar charts, error bars, box plots, histograms, heatmaps, subplots, multiple-axes, and 3D (WebGL based) charts.

You can read more at: Plotly R Library.

In this document, we’ll show how to create an interactive ggplot2-based graphics using plotly.

Install required packages

install.packages("ggplot2")
install.packages("plotly")

Usage

library(ggplot2)
library(plotly)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
p <- ggplot(data = d, aes(x = carat, y = price)) +
  geom_point(aes(text = paste("Clarity:", clarity)), size = .5) +
  geom_smooth(aes(colour = cut, fill = cut)) + facet_wrap(~ cut)
ggplotly(p)

The plots look like this:

Plotly: create interactive plots in R