Foreword
Let’s get started
Plotly provides online graphing, analytics, and statistics tools to make beautiful, interactive web-based graphs.
Plotly for R runs locally in a web browser or in a RStudio viewer. We can publish our charts to the web with Plotly’s web service. Let’s get started by loading the plotly package.
The .gif file:
Diamonds are forever
Plotly graphs are interactive. Click-drag to zoom, shift-click to pan out, double-click to autoscale…
The result resembles the interactive graphic above (~volcano). The .png file:
The .png file:
The .png file:
The interactive bar chart
Turn those dull, basic bar charts into interactive masterpieces!
The .png file:
From the bar to the box: the box plot
Create box plots that are grouped, colored, and that display the underlying data distribution.
The .png file:
The .png file:
The .png file:
Visualizing volcano data
Mount Eden is a volcano in the Auckland volcanic field. The volcano dataset gives topographic information for Mount Eden on a 10m by 10m grid.
One way to look at the topographic data is via a heatmap. The heatmap’s color pattern visualizes how the height of the volcano’s surface fluctuates within this 10m by 10m grid.
Alternatively, we could visualize the data by making a 3D surface plot.
The .gif file:
ggplot2, the interactive dimension
Convert the ggplot2 plots into interactive, web-based versions. See examples.
The .gif file:
An interactive airport map
A map provides an easy way to visualize how a measurement varies across a geographic area or the level of variability within a region. Run the first part of the code to display a map of the USA showing the most trafficked airports. Hover over each block to see the name of the airport, city, state and number of arrivals.
What we would see in a browser (.gif):
What we would see in a browser (.gif):
Let’s highlight the most important pieces of the code:
lat and lon arguments, we provide information regarding the latitude and longitude of the airport’s locations.add_markers(), we can add trace(s) to a Plotly visualization.geo, we set the reference between the provided geospatial coordinates and a geographic map (e.g. usa)layout(), we modify the layout of a plotly visualization. For example, with title, we tell Plotly what title we want to appear above our plot.Sliding into the final example
Visualize the decease on the US roads.
The .gif file:
Implement a range slider to a stock graph.
The .gif file: