0% found this document useful (0 votes)
56 views

2.1 Intro To: Plot - Ly

This document provides an overview of using the plotly R package to create interactive graphics. It discusses two main approaches for creating plotly objects - transforming ggplot2 objects or directly initializing plotly objects. Both approaches implement the Grammar of Graphics and are powered by the JavaScript plotly.js library. The subsequent chapters provide specific examples, while this introductory chapter outlines key concepts and terminology related to plotly graphics. It also introduces the infrastructure behind plotly objects. The document then demonstrates using the plot_ly() function to explore the diamonds dataset from ggplot2 and learn how plotly and plotly.js work.

Uploaded by

Seshendra Vemuri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

2.1 Intro To: Plot - Ly

This document provides an overview of using the plotly R package to create interactive graphics. It discusses two main approaches for creating plotly objects - transforming ggplot2 objects or directly initializing plotly objects. Both approaches implement the Grammar of Graphics and are powered by the JavaScript plotly.js library. The subsequent chapters provide specific examples, while this introductory chapter outlines key concepts and terminology related to plotly graphics. It also introduces the infrastructure behind plotly objects. The document then demonstrates using the plot_ly() function to explore the diamonds dataset from ggplot2 and learn how plotly and plotly.js work.

Uploaded by

Seshendra Vemuri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Overview

This part of the book teaches you how to leverage the plotly R package to create
a variety of interactive graphics. There are two main ways to creating
a plotly object: either by transforming a ggplot2 object (via ggplotly()) into
a plotly object or by directly initializing a plotly object
with plot_ly()/plot_geo()/plot_mapbox(). Both approaches have somewhat
complementary strengths and weaknesses, so it can pay off to learn both
approaches. Moreover, both approaches are an implementation of the Grammar of
Graphics and both are powered by the JavaScript graphing library plotly.js, so
many of the same concepts and tools that you learn for one interface can be
reused in the other.
The subsequent chapters within this ‘Creating views’ part dive into specific
examples and use cases, but this introductory chapter outlines some over-arching
concepts related to plotly in general. It also provides definitions for terminology
used throughout the book and introduces some concepts useful for understanding
the infrastructure behind any plotly object. Most of these details aren’t necessarily
required to get started with plotly, but it will inevitably help you get ‘un-stuck’,
write better code, and do more advanced things with plotly.

2.1 Intro to plot_ly()
Any graph made with the plotly R package is powered by the JavaScript
library plotly.js. The plot_ly() function provides a ‘direct’ interface to plotly.js with
some additional abstractions to help reduce typing. These abstractions, inspired
by the Grammar of Graphics and ggplot2, make it much faster to iterate from one
graphic to another, making it easier to discover interesting features in the
data (Wilkinson 2005; Wickham 2009). To demonstrate, we’ll use plot_ly() to
explore the diamonds dataset from ggplot2 and learn a bit how plotly and plotly.js
work along the way.
# load the plotly R package
library(plotly)

# load the diamonds dataset from the ggplot2 package


data(diamonds, package = "ggplot2")
diamonds
#> # A tibble: 53,940 x 10
#> carat cut color clarity depth table price x
#> <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl>
#> 1 0.23 Ideal E SI2 61.5 55 326 3.95
#> 2 0.21 Prem… E SI1 59.8 61 326 3.89
#> 3 0.23 Good E VS1 56.9 65 327 4.05
#> 4 0.290 Prem… I VS2 62.4 58 334 4.2
#> 5 0.31 Good J SI2 63.3 58 335 4.34
#> 6 0.24 Very… J VVS2 62.8 57 336 3.94
#> # … with 5.393e+04 more rows, and 2 more variables:
#> # y <dbl>, z <dbl>

You might also like