Interactive Data Visualizations using R and ggvis

Slides:



Advertisements
Similar presentations
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Advertisements

McGraw-Hill/Irwin The O’Leary Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lab 2 Charting Worksheet Data.
Reading Graphs and Charts are more attractive and easy to understand than tables enable the reader to ‘see’ patterns in the data are easy to use for comparisons.
Elizabeth North UMCES Horn Point Laboratory Using Surfer 8.0 UMCES HPL May 30, 2006.
FIRST COURSE Excel Tutorial 4 Working with Charts and Graphics.
Excel Graphing Tutorial Lauren Ottaviano Fall 2012.
COMPREHENSIVE Excel Tutorial 4 Working with Charts and Graphics.
Plotting data & Regression using the parallelogram method Annika Lohstroh 17 BB 03
19 th Advanced Summer School in Regional Science Overview and more advanced directions with ArcGIS.
Graphing. When to Graph Your Data When "a picture could tell billions of words" To impress people Dramatize a research finding Some people think visually.
NU Data Excel Orientation Graphing of Screening Data and Basic Graphing Functions.
Graphing in Excel Dr. Denise Harlem January 29, 2015.
Charts and Graphs V
Microsoft Excel Part 2 Kin 260 Adapted from Daniel Frankl, Ph.D. Revised by Jackie Kiwata 10/07.
ENGR 1181 College of Engineering Engineering Education Innovation Center Excel 1.
Ranjeet Department of Physics & Astrophysics University of Delhi Working with Origin.
Chapter 5: Charts Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Examples of different formulas and their uses....
Chapter 9 Creating and Designing Graphs. Creating a Graph A graph is a diagram of data that shows relationship among a set of numbers. Data can be represented.
XP Tutorial 1 Introduction to Macromedia Flash MX 2004.
A Picture Is Worth A Thousand Words. DAY 7: EXCEL CHAPTER 4 Tazin Afrin September 10,
Introduction to ArcGIS for Environmental Scientists Module 1 – Data Visualization Chapter 3 – Symbology and Labeling.
Graphing.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
McGraw-Hill Career Education© 2008 by the McGraw-Hill Companies, Inc. All Rights Reserved. Office Excel 2007 Lab 2 Charting Worksheet Data.
Spreadsheets III: Layout and Charts Lecture 10, May 8, 2003 Mr. Greg Vogl Management Information Systems I Uganda Martyrs University.
Introduction to Engineering Microsoft Excel 1 Agenda Tables, Charts, & Graphs.
Ggplot2 A cool way for creating plots in R Maria Novosolov.
Creating a Scatter Plot On a Mac. Data in Excel Spreadsheet Insert the variable you want on the x-axis in the left column Insert the variable you want.
Microsoft® Excel Use the Chart Tools Design tab. 1 Use the Chart Tools Layout and Format tabs. 2 Create chart sheets and chart objects. 3 Edit.
EXCEL GRAPHING *Basic Graphing Steps* by A.B. -NNHS.
Excel Part 4 Working with Charts and Graphics. XP Objectives Create an embedded chart Work with chart titles and legends Create and format a pie chart.
Excel Part 4 Working with Charts and Graphics. XP Objectives Create an embedded chart Work with chart titles and legends Create and format a pie chart.
Data Visualization Data Science in Practice Week 9, 04/18 Jia-Ming Chang CS Dept, National Chengchi University
Graphical Analysis I Graphing Experimental Data. As a barge is loaded with more cargo Weight, the Depth that it sinks into the water changes. The table.
COM: 111 Introduction to Computer Applications Department of Information & Communication Technology Panayiotis Christodoulou.
Copyright © 2015 Varun Varghese
Excel Working with Charts and Graphs
Data Visualization The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing Edward Tufte.
Shiny for RStudio Exploring Web Mapping Technology
Working with Charts © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Year 13 Physics Waimate High School
Microsoft Excel 2007 The L Line The Express Line to Learning L Line
Excel Part 4 Working with Charts and Graphics
How to set up successful graphs
Graphing For Science Class.
Excel Part 4 Working with Charts and Graphics
Training Session A: Introduction to the StatPlanet Interface
Scatterplots A way of displaying numeric data
Graph Types Class A Class B.
Making Science Graphs and Interpreting Data
Microsoft Excel Illustrated
8.04 Spreadsheet Charts 8.04 Spreadsheet Charts.
Making Science Graphs and Interpreting Data
Transformations Example Draw the line Draw 1 at , ,
Reading a CSV file in R.
Microsoft Office Illustrated Introductory, Windows XP Edition
INTRODUCTION TO SGPLOT Zahir Raihan OVERVIEW  ODS Graphics  SGPLOT overview  Plot Content  High value plot statements  High value plot options 
Building Worksheet Charts
Graphing Notes.
Chart Junk.
Topic 7: Visualization Lesson 1 – Creating Charts in Excel
GRAPHING.
Making Science Graphs and Interpreting Data
Line Graphs.
Writing Technical Reports
Excel Part 4 Working with Charts and Graphics
Microsoft Office Illustrated Fundamentals
Microsoft PowerPoint Tutorial Graphs BIS 101 Spring 2018.
Graphs in Science p. 34.
Presentation transcript:

Interactive Data Visualizations using R and ggvis 6 April 2018 McGill Library Research Commons Presented by Zia D. and Mike G.

Outline Loading data into RStudio Introduction and basics of ggvis Lines & Syntax Interactivity and Layers Customizing Axes, Legends, Scales Mapping

Required R Libraries > install.packages("ggvis") > library(ggvis) > library(dplyr)

Loading your data set #set working directory > setwd(“c:/r_data”) #verify working directory > getwd() #load the .csv into a variable named hospital_data > hospital_data <- read.csv(“quebec_hospital_data_subset.csv”) #if problems loading CSV hospital_data <- read.csv(“quebec_hospital_data_subset.csv”, fileEncoding="latin1")

Verify that the data has loaded correctly #view data headers > names(hospital_data) This should reproduce the following:

Convert textual data to numeric This code converts the data in each column from textual to numeric #as.numeric for columns 1, 6, 7, 8 > hospital_data[, 1] <- as.numeric(hospital_data[, 1]) > hospital_data[, 6] <- as.numeric(hospital_data[, 6]) > hospital_data[, 7] <- as.numeric(hospital_data[, 7]) > hospital_data[, 8] <- as.numeric(hospital_data[, 8])

Grammar of Graphics + + + Underlying structure of ggvis Data Coordinate System Marks Properties + + +

Basics #formula <data> %>% ggvis(~x, ~y, properties) %>% layer_<marks>(properties) #pipe operator (from library dpylr) %>%

Lines & Syntax #graph hospitals against proportion of series as a scatterplot > hospital_data %>% ggvis(~Proportion, ~Installation) %>% layer_points() #change mark layer_lines() layer_bars() layer_ribbons() layer_smooths()

Visual Properties #change properties >hospital_data %>% ggvis(~Proportion, ~Installation, fill := “blue”, size := 100, shape := “square”) %>% layer_points() ggvis(~Proportion, ~Installation) %>% layer_points(fill := “red”, size := 50, shape := “diamond”) #some other properties: stroke, strokeWidth, opacity, fillOpacity, strokeOpacity, fill.hover

Visual Properties #map property to a variable >hospital_data %>% ggvis(~Proportion, ~Installation, fill = ~Région) %>% layer_points() ggvis(~Proportion, ~Installation) %>% layer_points(fill = ~Région)

Interactivity #adding sliders >hospital_data %>% ggvis(~Proportion, ~Installation, size := input_slider(10, 100), opacity := input_slider(0, 1)) %>% layer_points()

Layers Two layer types: simple and compound Simple represent basic geometric shapes like lines, points and triangles Compound represent data transformations along with one or more simple layers

Simple layer #scatter plot > hospital_data %>% ggvis(~Proportion, ~Installation, stroke = “red”) %>% layer_points()

Compound layers layer_lines() - order by the x variable layer_smooths() - fits a smooth model to the data, and displays predictions in a line

Layer_smooths example #highlights the trend in noisy data > hospital_data %>% ggvis(~Région, ~Nombre.de.visites.totales) %>% layer_smooths() #interactive version > span <- input_slider(1, 5, value=1) hospital_data %>% layer_smooths(span = span)

Customizing axes #create a simple scatter plot and rename x-axis >hospital_data %>% ggvis(~Installation, ~Proportion) %>% layer_points() %>% add_axis("x", title = "Hospital names")

Other axis options > add_axis("x", title = "Hospital Names", ticks = 40, properties = axis_props(ticks = list(stroke = "red"), majorTicks = list(strokeWidth = 2), grid = list(stroke = "red"), labels = list(fill = "steelblue", angle = 50, fontSize = 14, align = "left"), title = list(fontSize = 16))) > add_axis “x”, title = “Title Name”, title_offset = 50

Customizing legends #add_legend > add_legend(vis, scales = NULL, orient = "right", title = NULL, format = NULL, values = NULL, properties = NULL) hide_legend(vis, scales) #legend_props > legend_props(title = NULL, labels = NULL, symbols = NULL, gradient = NULL, legend = NULL)

add_legend examples #add_legend one variable > hospital_data %>% ggvis(~Nombre.de.visites.totales, ~Proportion, fill = ~Installation) %>% layer_points() %>% add_legend("fill", title="Custom name") #add_legend two variables >hospital_data %>% ggvis(~Nombre.de.visites.totales, ~Proportion, fill = ~Installation, size = “Nombre.de.visites.P4.et.P5) %>% add_legend(c( "fill", "size"))

Further legend customization >hospital_data %>% ggvis(~Nombre.de.visites.totales, ~Proportion, fill = ~Installation) %>% layer_points() %>% add_legend("fill", title = "Cylinders", properties = legend_props(title = list(fontSize = 16), labels = list(fontSize = 12, fill = "#00F"), gradient = list(stroke = "red", strokeWidth = 2), legend = list(x = 500, y = 50)))

Mapping data - Quebec Admin Boundaries Shapefile Libraries: rgdal, rgeos > montreal_map <- readOGR("c:/r_data", "DistrictElect") > montreal_wgs84 <- spTransform(montreal_map, CRS ("+proj=longlat +datum=WGS84")) > plot(montreal_wgs84, axes=TRUE)

Plot data onto shapefile >plot(montreal_wgs84) >points(hospital_data$Longitude, hospital_data$Latitude, col="blue", pch=19)

Further documentation RStudio ggvis 0.4 overview CPAN documentation