19 December 2016

What is Plotly?

Plotly is a web application for creating and sharing data visualizations. Plotly can work with several programming languages and applications including R, Python, and Microsoft Excel. We're going to concentrate on creating different graphs with Plotly and sharing those graphs.

load the plotly

library(ggplot2)
library(plotly)

Quakes data set

head(quakes)
     lat   long depth mag stations
1 -20.42 181.62   562 4.8       41
2 -20.62 181.03   650 4.2       15
3 -26.00 184.10    42 5.4       43
4 -17.97 181.66   626 4.1       19
5 -20.42 181.96   649 4.0       11
6 -19.68 184.31   195 4.0       12

A data frame with 1000 observations on 5 variables.

  • lat numeric Latitude of event
  • long numeric Longitude
  • depth numeric Depth (km)
  • mag numeric Richter Magnitude
  • stations numeric Number of stations reporting

3D Scatter Plot

You can create a three-dimensional scatterplot with the type = "scatter3d" argument. If you click and drag these scatterplots you can view them from different angles.

3D Scatter plot of Quakes data set

plot_ly(x = quakes$lat, y = quakes$long, 
        z = quakes$depth,type = "scatter3d", mode = "markers", 
        color =quakes$depth)