+ All Categories
Home > Documents > Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw...

Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw...

Date post: 07-Jun-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
25
Why Interactivity? Reduce data dimension: allow user to explore large datasets by quickly switching between dimensions Overview first, zoom and filter, details on demand: Provide big picture, let the user explore details as they desire Linked views for high dimensions: There is a limit to the number of aesthetic mappings in a single graphic, make multiple graphics but link data objects between them 1 / 24 Examples Politics: http://www.nytimes.com/interactive/2012/11/02/us/politics/paths- to-the-white-house.html?_r=0 Movies: http://www.nytimes.com/interactive/2013/02/20/movies/among- the-oscar-contenders-a-host-of-connections.html Sports: https://projects.fivethirtyeight.com/2018-march-madness- predictions/ 2 / 24 Web-based interactive visualization Take advantage of HTML document description and the Document Object Model interface to bind data to page elements. Shiny: bind data to controls Data-driven Documents (d3.js): bind data to svg elements directly 3 / 24 Basic idea is to only specify content and structure but not specify directly how to render pages. HTML and DOM Web pages are structured using Hypertext Markup Language <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>Page Title</h1> <p>This is a really interesting paragrap </body> </html> 4 / 24 Structure is provided by page elements. An important element we'll see later is the arbitrary grouping/containment element div. HTML and DOM Web pages are structured using Hypertext Markup Language <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>Page Title</h1> <p>This is a really interesting paragrap </body> </html> 5 / 24 The hierarchical structure of elements in a document are defined by the Document Object Model (DOM). HTML and DOM Web pages are structured using Hypertext Markup Language <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>Page Title</h1> <p>This is a really interesting paragrap </body> </html> 6 / 24 CSS Cascading Style Sheets are used to style elements in the DOM. body { background-color: white; color: black; } 7 / 24 CSS In general: selectorA, selectorB, selectorC { property1: value; property2: value; property3: value; } 8 / 24 SVG Scalable Vector Graphics (SVG) is special element used to create graphics with text. <svg width="50" height="50"> <circle cx="25" cy="25" r="22" fill="blue" stroke="gray" stroke-width="2"/> </svg> 9 / 24 SVG Elements have geometric attributes and style attributes. <circle cx="250" cy="25" r="25"/> cx: x-coordinate of circle center cy: y-coordinate of circle center r: radius of circle 10 / 24 SVG Elements have geometric attributes and style attributes. <rect x="0" y="0" width="500" height="50"/> x: x-coordinate of left-top corner y: y-coordinate of left-top corner width, height: width and height of rectangle 11 / 24 SVG style attributes <circle cx="25" cy="25" r="22" fill="yellow" stroke="orange" stroke-width="5"/> can be styled by class as well svg .pumpkin { fill: yellow; stroke: orange; stroke-width: 5; } <circle cx="25" cy="25" r="22" class="pumpkin"> 12 / 24 Shiny and D3 Shiny: construct DOM and bind data (variables for example) to elements (a slide control for example) http://shiny.rstudio.com D3: bind data to SVG element attributes (position, size, color, transparency, etc.) http://d3js.org 13 / 24 Reactivity Interactivity and binding in Shiny achieved using reactive programming. Where objects react to changes in other objects. 14 / 24 Reactivity Example: 15 / 24 Reactivity With intermediate objects: 16 / 24 Reactivity A standard paradigm for interactive (event-driven) application development A nice review paper: http://dl.acm.org/citation.cfm?id=2501666 17 / 24 Binding data to graphical elements With Shiny we can bind data objects to document elements. More examples: http://shiny.rstudio.com/gallery/ We can also bind data directly to graphical elements since using SVG these are also document elements (D3). 18 / 24 D3 Tutorial Slides 19 / 24 D3 Alternatives If you want to use a toolkit of standard charts based on d3: NVD3 An alternative declarative library: Vega A no-hassle interactive vis library for multiple languages: plotly R plotly python plotly JS 20 / 24 D3 and R We saw previously that D3 can access external data through json That's how we can pass data from R to the Javascript browser 21 / 24 D3 and R rCharts: Most mature. Provides binding between R and a small set of javascript viz libraries. ggvis: Uses grammar of graphics like ggplot2, bindings to Vega to define JS charts. htmlwidgets a formalization of how to bind R to JS libraries. Roll your own 22 / 24 D3 and jupyter In jupyter you can use HTML and javascript directly, and use D3 and other JS libraries through that. For more info: https://blog.thedataincubator.com/2015/08/embedding-d3- in-an-ipython-notebook/ 23 / 24 Interactive visualization Essential tool for exploration Helps manage high-dimensionality of data (don't go 3D, link charts!!) 24 / 24 Introduction to Data Science: Interactive Visualization Héctor Corrada Bravo University of Maryland, College Park, USA CMSC320: 2020-05-03
Transcript
Page 1: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

Why Interactivity?Reduce data dimension: allow user to explore large datasets by quicklyswitching between dimensions

Overview first, zoom and filter, details on demand: Provide big picture, letthe user explore details as they desire

Linked views for high dimensions: There is a limit to the number ofaesthetic mappings in a single graphic, make multiple graphics but linkdata objects between them

1 / 24

ExamplesPolitics: http://www.nytimes.com/interactive/2012/11/02/us/politics/paths-to-the-white-house.html?_r=0

Movies: http://www.nytimes.com/interactive/2013/02/20/movies/among-the-oscar-contenders-a-host-of-connections.html

Sports: https://projects.fivethirtyeight.com/2018-march-madness-predictions/

2 / 24

Web-based interactive visualizationTake advantage of HTML document description and the DocumentObject Model interface to bind data to page elements.

Shiny: bind data to controlsData-driven Documents (d3.js): bind data to svg elements directly

3 / 24

Basic idea is to only specify contentand structure but not specify directlyhow to render pages.

HTML and DOMWeb pages are structured using Hypertext Markup Language

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<h1>Page Title</h1>

<p>This is a really interesting paragrap

</body>

</html> 4 / 24

Structure is provided by pageelements. An important elementwe'll see later is the arbitrarygrouping/containment element div.

HTML and DOMWeb pages are structured using Hypertext Markup Language

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<h1>Page Title</h1>

<p>This is a really interesting paragrap

</body>

</html> 5 / 24

The hierarchical structure ofelements in a document are definedby the Document Object Model(DOM).

HTML and DOMWeb pages are structured using Hypertext Markup Language

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<h1>Page Title</h1>

<p>This is a really interesting paragrap

</body>

</html> 6 / 24

CSSCascading Style Sheets are used to style elements in the DOM.

body {

background-color: white;

color: black;

}

7 / 24

CSSIn general:

selectorA,

selectorB,

selectorC {

property1: value;

property2: value;

property3: value;

}

8 / 24

SVGScalable Vector Graphics (SVG) is special element used to creategraphics with text.

<svg width="50" height="50">

<circle cx="25" cy="25" r="22" fill="blue" stroke="gray" stroke-width="2"/>

</svg>

9 / 24

SVGElements have geometric attributes and style attributes.

<circle cx="250" cy="25" r="25"/>

cx: x-coordinate of circle centercy: y-coordinate of circle centerr: radius of circle

10 / 24

SVGElements have geometric attributes and style attributes.

<rect x="0" y="0" width="500" height="50"/>

x: x-coordinate of left-top cornery: y-coordinate of left-top cornerwidth, height: width and height of rectangle

11 / 24

SVGstyle attributes

<circle cx="25" cy="25" r="22" fill="yellow" stroke="orange" stroke-width="5"/>

can be styled by class as well

svg .pumpkin {

fill: yellow;

stroke: orange;

stroke-width: 5;

}

<circle cx="25" cy="25" r="22" class="pumpkin"> 12 / 24

Shiny and D3Shiny: construct DOM and bind data (variables for example) to elements(a slide control for example) http://shiny.rstudio.com

D3: bind data to SVG element attributes (position, size, color,transparency, etc.) http://d3js.org

13 / 24

ReactivityInteractivity and binding in Shiny achieved using reactive programming.Where objects react to changes in other objects.

14 / 24

ReactivityExample:

15 / 24

ReactivityWith intermediate objects:

16 / 24

ReactivityA standard paradigm for interactive (event-driven) applicationdevelopment

A nice review paper: http://dl.acm.org/citation.cfm?id=2501666

17 / 24

Binding data to graphical elementsWith Shiny we can bind data objects to document elements.More examples: http://shiny.rstudio.com/gallery/

We can also bind data directly to graphical elements since using SVGthese are also document elements (D3).

18 / 24

D3 TutorialSlides

19 / 24

D3 AlternativesIf you want to use a toolkit of standard charts based on d3: NVD3

An alternative declarative library: Vega

A no-hassle interactive vis library for multiple languages:

plotly Rplotly pythonplotly JS

20 / 24

D3 and RWe saw previously that D3 can access external data through jsonThat's how we can pass data from R to the Javascript browser

21 / 24

D3 and RrCharts: Most mature. Provides binding between R and a small set ofjavascript viz libraries.ggvis: Uses grammar of graphics like ggplot2, bindings to Vega todefine JS charts.htmlwidgets a formalization of how to bind R to JS libraries.Roll your own

22 / 24

D3 and jupyterIn jupyter you can use HTML and javascript directly, and use D3 andother JS libraries through that.

For more info: https://blog.thedataincubator.com/2015/08/embedding-d3-in-an-ipython-notebook/

23 / 24

Interactive visualizationEssential tool for exploration

Helps manage high-dimensionality of data (don't go 3D, link charts!!)

24 / 24

Introduction to Data Science:Interactive Visualization

Héctor Corrada Bravo

University of Maryland, College Park, USACMSC320: 2020-05-03

Page 2: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

Why Interactivity?Reduce data dimension: allow user to explore large datasets by quicklyswitching between dimensions

Overview first, zoom and filter, details on demand: Provide big picture, letthe user explore details as they desire

Linked views for high dimensions: There is a limit to the number ofaesthetic mappings in a single graphic, make multiple graphics but linkdata objects between them

1 / 24

Page 3: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

ExamplesPolitics: http://www.nytimes.com/interactive/2012/11/02/us/politics/paths-to-the-white-house.html?_r=0

Movies: http://www.nytimes.com/interactive/2013/02/20/movies/among-the-oscar-contenders-a-host-of-connections.html

Sports: https://projects.fivethirtyeight.com/2018-march-madness-predictions/

2 / 24

Page 4: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

Web-based interactive visualizationTake advantage of HTML document description and the DocumentObject Model interface to bind data to page elements.

Shiny: bind data to controlsData-driven Documents (d3.js): bind data to svg elements directly

3 / 24

Page 5: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

Basic idea is to only specify contentand structure but not specify directlyhow to render pages.

HTML and DOMWeb pages are structured using Hypertext Markup Language

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<h1>Page Title</h1>

<p>This is a really interesting paragrap

</body>

</html> 4 / 24

Page 6: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

Structure is provided by pageelements. An important elementwe'll see later is the arbitrarygrouping/containment element div.

HTML and DOMWeb pages are structured using Hypertext Markup Language

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<h1>Page Title</h1>

<p>This is a really interesting paragrap

</body>

</html> 5 / 24

Page 7: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

The hierarchical structure ofelements in a document are definedby the Document Object Model(DOM).

HTML and DOMWeb pages are structured using Hypertext Markup Language

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<h1>Page Title</h1>

<p>This is a really interesting paragrap

</body>

</html> 6 / 24

Page 8: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

CSSCascading Style Sheets are used to style elements in the DOM.

body {

background-color: white;

color: black;

}

7 / 24

Page 9: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

CSSIn general:

selectorA,

selectorB,

selectorC {

property1: value;

property2: value;

property3: value;

}

8 / 24

Page 10: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

SVGScalable Vector Graphics (SVG) is special element used to creategraphics with text.

<svg width="50" height="50">

<circle cx="25" cy="25" r="22" fill="blue" stroke="gray" stroke-width="2"/>

</svg>

9 / 24

Page 11: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

SVGElements have geometric attributes and style attributes.

<circle cx="250" cy="25" r="25"/>

cx: x-coordinate of circle centercy: y-coordinate of circle centerr: radius of circle

10 / 24

Page 12: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

SVGElements have geometric attributes and style attributes.

<rect x="0" y="0" width="500" height="50"/>

x: x-coordinate of left-top cornery: y-coordinate of left-top cornerwidth, height: width and height of rectangle

11 / 24

Page 13: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

SVGstyle attributes

<circle cx="25" cy="25" r="22" fill="yellow" stroke="orange" stroke-width="5"/>

can be styled by class as well

svg .pumpkin {

fill: yellow;

stroke: orange;

stroke-width: 5;

}

<circle cx="25" cy="25" r="22" class="pumpkin"> 12 / 24

Page 14: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

Shiny and D3Shiny: construct DOM and bind data (variables for example) to elements(a slide control for example) http://shiny.rstudio.com

D3: bind data to SVG element attributes (position, size, color,transparency, etc.) http://d3js.org

13 / 24

Page 15: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

ReactivityInteractivity and binding in Shiny achieved using reactive programming.Where objects react to changes in other objects.

14 / 24

Page 16: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

ReactivityExample:

15 / 24

Page 17: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

ReactivityWith intermediate objects:

16 / 24

Page 18: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

ReactivityA standard paradigm for interactive (event-driven) applicationdevelopment

A nice review paper: http://dl.acm.org/citation.cfm?id=2501666

17 / 24

Page 19: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

Binding data to graphical elementsWith Shiny we can bind data objects to document elements.More examples: http://shiny.rstudio.com/gallery/

We can also bind data directly to graphical elements since using SVGthese are also document elements (D3).

18 / 24

Page 21: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

D3 AlternativesIf you want to use a toolkit of standard charts based on d3: NVD3

An alternative declarative library: Vega

A no-hassle interactive vis library for multiple languages:

plotly Rplotly pythonplotly JS

20 / 24

Page 22: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

D3 and RWe saw previously that D3 can access external data through jsonThat's how we can pass data from R to the Javascript browser

21 / 24

Page 23: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

D3 and RrCharts: Most mature. Provides binding between R and a small set ofjavascript viz libraries.ggvis: Uses grammar of graphics like ggplot2, bindings to Vega todefine JS charts.htmlwidgets a formalization of how to bind R to JS libraries.Roll your own

22 / 24

Page 24: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

D3 and jupyterIn jupyter you can use HTML and javascript directly, and use D3 andother JS libraries through that.

For more info: https://blog.thedataincubator.com/2015/08/embedding-d3-in-an-ipython-notebook/

23 / 24

Page 25: Introduction to Data Science€¦ · plotly R plotly python plotly JS 20 / 24 andR We saw previously that D3 can access external data through json That's how we can pass data from

Interactive visualizationEssential tool for exploration

Helps manage high-dimensionality of data (don't go 3D, link charts!!)

24 / 24


Recommended