Plotting with ggplot2: Part 1

Slides:



Advertisements
Similar presentations
JustinMind: Dynamic Panels
Advertisements

Rich Pugh Andy Nicholls Head to Head: Lattice vs ggplot2 Rich Pugh
Lesson 13 Editing and Formatting Documents
Introduction to R Graphics
Cascading Style Sheets (CSS). Cascading Style Sheets With the explosive growth of the World Wide Web, designers and programmers quickly explored and reached.
Chapter 3 Drawing and Composing an Illustration. Objectives Draw straight lines Draw curved lines Draw elements of an illustration Apply attributes to.
Workshop Sarah Pendergrass, PhD MS Research Associate Center for Systems Genomics.
Chapter 6 Photoshop and ImageReady: Part II The Web Warrior Guide to Web Design Technologies.
Plotting Systems in R Dr. Jieh-Shan George YEH
1 Presented by Jean-Daniel Fekete. 2  Motivation  Mélange [Elmqvist 2008] Multiple Focus Regions.
Automating Tasks With Macros
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
ArcView Documents Francisco Olivera, Ph.D., P.E. Department of Civil Engineering Texas A&M University.
Data Visualization with R (II)
Lesson 21 Getting Started with PowerPoint Essentials
Power Point Presentation - Advanced Julia J. Stahl Distributed System Specialist.
DIGITAL GRAPHICS & ANIMATION
Some Possibly Useful Graphics Functions Lunch presentation.
EnSight analyze, visualize, communicate EnSight 6.x Advanced Training Part 1 Instructors: Mike Krogh, Anders Grimsrud.
SCHOOL OF LIBRARY, ARCHIVE AND INFORMATION STUDIES Andy Dawson LIS1510 Library and Archives Automation Issues Further features of HTML – Stylesheets and.
Tutorial 4: Using CSS for Page Layout. 2 Objectives Session 4.1 Explore CSS layout Compare types of floating layouts Examine code for CSS layouts View.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln
Chapter 2 Developing a Web Page. A web page is composed of two distinct sections: –The head content –The body Creating Head Content and Setting Page Properties.
XP Mohammad Moizuddin Creating Web Pages with HTML Tutorial 1 1 New Perspectives on Creating Web Pages With HTML Tutorial 1: Developing a Basic Web Page.
Examples of different formulas and their uses....
Chapter 3 – Part 1 Word Processing Writer for Linux CMPF 112 : COMPUTING SKILLS.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
Tutorial 1 Introducing Adobe Flash CS3 Professional
Microsoft Office Illustrated Fundamentals Unit I: Working with Charts.
Computer Literacy BASICS: A Comprehensive Guide to IC 3, 5 th Edition Lesson 23 Getting Started with Access Essentials 1 Morrison / Wells / Ruffolo.
1 Lesson 13 Editing and Formatting documents Computer Literacy BASICS: A Comprehensive Guide to IC 3, 4 th Edition Morrison / Wells.
Chapter 1 Review Chapter 2 Whatcha Gonna Do???
Return to Outline Copyright © 2011 by Maribeth H. Price 3-1 Labeling and annotation.
Unit B. Setting preferences and defaults You can use the Preferences dialog box to customize the Quark working environment so it suits your style. With.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Ggplot2 A cool way for creating plots in R Maria Novosolov.
1 Lesson 8 Editing and Formatting Documents Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Outline Research Question: What determines height? Data Input Look at One Variable Compare Two Variables Children’s Height and Parents Height Children’s.
Microsoft FrontPage 2003 Illustrated Complete Working on the Web Site’s Hyperlinks and Appearance.
Positioning Objects with CSS and Tables
Unit Seven: Basic Layout In this unit… ► Display Area: Layout View ► Sizing & Scaling Data ► Adding Map Elements  North Arrow  Title  Legend.
Creating Charts Ms. Hall Spring Using the Insert Tab to Create Charts The Insert tab contains the command groups you’ll use to create charts in.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
R PROGRAMMING FOR SQL DEVELOPERS Kiran Math Developer : Proterra in Greenville SC
Portal Construction 301. Where We Are In Portal Construction 101and 201 we created a Group Profile in the local system and uploaded to our Web Reservation.
Transition from EnSight V9 to V10 Boot strap training Anders Grimsrud, President January 2012.
Working with TextWorking with Text Lesson 3 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft Powerpoint.
Data Visualization.
Ggplot2 Wu Shaohuan.
OVERVIEW Objectives Follow a design document to prepare images for inclusion in a Web page Run a batch process to prepare multiple images in one step Use.
Using R Graphs in R.
Inserting and Working with Images
Digital Text and Data Processing
Learning the Basics – Lesson 1
ggplot2 Merrill Rudd TAs: Brooke Davis and Megsie Siple
Microsoft Official Academic Course, Microsoft Word 2013
Introduction to R Programming with AzureML
Chapter 8: ODS Graphics ODS graphics were not available prior to SAS 9.2 They have been implemented across a wide range of procedures Functionality isn’t.
Summary Statistics in R Commander
Unit Six: Labels In this unit… Review Adding Text to Maps
R Assignment #4: Making Plots with R (Due – by ) BIOL
Data visualization in Python
Tutorial 6 Creating Dynamic Pages
R Programming For Sql Developers ETL USING R
Lesson 20 Getting Started with PowerPoint Essentials
Lecture 7 – Delivering Results with R
Lesson 13 Editing and Formatting documents
Microsoft Office Illustrated Fundamentals
Welcome To Microsoft Word 2016
The Grammar of Graphics
Presentation transcript:

Plotting with ggplot2: Part 1 Computing for Data Analysis

What is ggplot2? An implementation of the Grammar of Graphics by Leland Wilkinson Written by Hadley Wickham (while he was a graduate student at Iowa State) A “third” graphics system for R (along with base and lattice) Available from CRAN via install.packages() Web site: http://ggplot2.org (better documentation)

What is ggplot2? Grammar of graphics represents and abstraction of graphics ideas/objects Think “verb”, “noun”, “adjective” for graphics Allows for a “theory” of graphics on which to build new graphics and graphics objects “Shorten the distance from mind to page”

Grammar of Graphics “In brief, the grammar tells us that a statistical graphic is a mapping from data to aesthetic attributes (colour, shape, size) of geometric objects (points, lines, bars). The plot may also contain statistical transformations of the data and is drawn on a specific coordinate system” from ggplot2 book

Plotting Systems in R: Base “Artist’s palette” model Start with blank canvas and build up from there Start with plot function (or similar) Use annotation functions to add/modify (text, lines, points, axis)

Plotting Systems in R: Base Convenient, mirrors how we think of building plots and analyzing data Can’t go back once plot has started (i.e. to adjust margins); need to plan in advance Difficult to “translate” to others once a new plot has been created (no graphical “language”) Plot is just a series of R commands

Plotting Systems in R: Lattice Plots are created with a single function call (xyplot, bwplot, etc.) Most useful for conditioning types of plots: Looking at how y changes with x across levels of z Thinks like margins/spacing set automatically because entire plot is specified at once Good for putting many many plots on a screen

Plotting Systems in R: Lattice Sometimes awkward to specify an entire plot in a single function call Annotation in plot is not intuitive Use of panel functions and subscripts difficult ot wield and requires intense preparation Cannot “add” to the plot once it’s created

Plotting Systems in R: ggplot2 Split the difference between base and lattice Automatically deals with spacings, text, titles but also allows you to annotate by “adding” Superficial similarity to lattice but generally easier/more intuitive to use Default mode makes many choices for you (but you can customize!)

The Basics: qplot() Works much like the plot function in base graphics system Looks for data in a data frame, similar to lattice, or in the parent environment Plots are made up of aesthetics (size, shape, color) and geoms (points, lines)

The Basics: qplot() Factors are important for indicating subsets of the data (if they are to have different properties); they should be labeled The qplot() hides what goes on underneath, which is okay for most operations ggplot() is the core function and very flexible for doing things qplot() cannot do

Factor label information important for annotation Example Dataset Factor label information important for annotation

ggplot2 “Hello, world!” x coord y coord data frame

Modifying aesthetics auto legend placement color aesthetic qplot(displ, hwy, data = mpg, color = drv)

Adding a geom qplot(displ, hwy, data = mpg, geom = c("point", "smooth"))

Histograms qplot(hwy, data = mpg, fill = drv)

Facets qplot(displ, hwy, data = mpg, facets = . ~ drv) qplot(hwy, data = mpg, facets = drv ~ ., binwidth = 2)

MAACS Cohort Mouse Allergen and Asthma Cohort Study Baltimore children (aged 5—17) Persistent asthma, exacerbation in past year Study indoor environment and its relationship with asthma morbidity Recent publication: http://goo.gl/WqE9j8

Example: MAACS Exhaled nitric oxide Fine particulate matter Sensitized to mouse allergen

Histogram of eNO qplot(log(eno), data = maacs)

Histogram by Group qplot(log(eno), data = maacs, fill = mopos)

Density Smooth qplot(log(eno), data = maacs, geom = "density") qplot(log(eno), data = maacs, geom = "density", color = mopos)

Scatterplots: eNO vs. PM2.5 qplot(log(pm25), log(eno), data = maacs) qplot(log(pm25), log(eno), data = maacs, shape = mopos) qplot(log(pm25), log(eno), data = maacs, color = mopos)

Scatterplots: eNO vs. PM2.5 qplot(log(pm25), log(eno), data = maacs, color = mopos, geom = c("point", "smooth"), method = "lm")

Scatterplots: eNO vs. PM2.5 qplot(log(pm25), log(eno), data = maacs, geom = c("point", "smooth"), method = "lm", facets = . ~ mopos)

Summary of qplot() The qplot() function is the analog to plot() but with many built-in features Syntax somewhere in between base/lattice Produces very nice graphics, essentially publication ready (if you like the design) Difficult to go against the grain/customize (don’t bother; use full ggplot2 power in that case)

Resources The ggplot2 book by Hadley Wickham The R Graphics Cookbook by Winston Chang (examples in base plots and in ggplot2) ggplot2 web site (http://ggplot2.org) ggplot2 mailing list (http://goo.gl/OdW3uB), primarily for developers