User manual forggsubplot

Similar documents
Package ggsubplot. February 15, 2013

Statistical transformations

Plotting with Rcell (Version 1.2-5)

An introduction to ggplot: An implementation of the grammar of graphics in R

Facets and Continuous graphs

Introduction to Graphics with ggplot2

Large data. Hadley Wickham. Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University.

Making Science Graphs and Interpreting Data

Chpt 2. Frequency Distributions and Graphs. 2-4 Pareto chart, time series graph, Pie chart / 35

ggplot2 basics Hadley Wickham Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University September 2011

Stat405. Displaying distributions. Hadley Wickham. Thursday, August 23, 12

Econ 2148, spring 2019 Data visualization

Visualization as an Analysis Tool: Presentation Supplement

The diamonds dataset Visualizing data in R with ggplot2

Lab5A - Intro to GGPLOT2 Z.Sang Sept 24, 2018

Statistical Tables and Graphs

Computing Fundamentals Plotting

Using the Matplotlib Library in Python 3

Plotting - Practice session

Chapter 2: Frequency Distributions

Data Visualization. Andrew Jaffe Instructor

Chapter 5snow year.notebook March 15, 2018

Common Core Vocabulary and Representations

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Overview for Families

Chapter 2 - Graphical Summaries of Data

Introduction to Geospatial Analysis

form are graphed in Cartesian coordinates, and are graphed in Cartesian coordinates.

The following presentation is based on the ggplot2 tutotial written by Prof. Jennifer Bryan.


TDWI strives to provide course books that are contentrich and that serve as useful reference documents after a class has ended.

Big Mathematical Ideas and Understandings

Transformations. Lesson Summary: Students will explore rotations, translations, and reflections in a plane.

University of Florida CISE department Gator Engineering. Visualization

Lecture 4: Data Visualization I

A Summary of the Types of Graphs Compiled by Mr. A. Caruso

Graphical Presentation for Statistical Data (Relevant to AAT Examination Paper 4: Business Economics and Financial Mathematics) Introduction

Name Date Types of Graphs and Creating Graphs Notes

5.2 Functions as Graphs

Math 6, Unit 11Notes: Integers, Graphs, and Functions

TMTH 3360 NOTES ON COMMON GRAPHS AND CHARTS

3D Surface Plots with Groups

An Introduction to Data Analysis, Statistics, and Graphing

Quick. Efficient. Versatile. Graphing Software for Scientists and Engineers.

A set of rules describing how to compose a 'vocabulary' into permissible 'sentences'

Type of graph: Explain why you picked this type of graph. Temperature (C) of product formed per minute)

Lecture Slides. Elementary Statistics Twelfth Edition. by Mario F. Triola. and the Triola Statistics Series. Section 2.1- #

Desktop Studio: Charts. Version: 7.3

INSTRUCTIONS FOR THE USE OF THE SUPER RULE TM

Section 2-2. Histograms, frequency polygons and ogives. Friday, January 25, 13

Excel 2013 Intermediate

Visualizing Data: Customization with ggplot2

Chapter 2: From Graphics to Visualization

Bar Charts and Frequency Distributions

Chapter 4. Part 1 AutoCAD Basics

Microsoft Excel. Charts

Ch. 1.4 Histograms & Stem-&-Leaf Plots

Data and Image Models

% Close all figure windows % Start figure window

Fathom Dynamic Data TM Version 2 Specifications

Introduction to Plot.ly: Customizing a Stacked Bar Chart

Desktop Studio: Charts

Chapter 2: Understanding Data Distributions with Tables and Graphs

Package ggextra. April 4, 2018

The Plot Thickens from PLOT to GPLOT

Creating a Basic Chart in Excel 2007

GRAPHING WORKSHOP. A graph of an equation is an illustration of a set of points whose coordinates satisfy the equation.

Question: What are the origins of the forces of magnetism (how are they produced/ generated)?

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Table of Contents (As covered from textbook)

5th Grade Mathematics Essential Standards

Chapter 2. Frequency Distributions and Graphs. Bluman, Chapter 2

Data Visualization. Module 7

Excel 2. Module 3 Advanced Charts

Data visualization with ggplot2

Getting started with ggplot2

Excel Tutorial 4: Analyzing and Charting Financial Data

Input/Output Machines

Chapters 1.5 and 2.5 Statistics: Collecting and Displaying Data

Content provided in partnership with Que, from the book Show Me Microsoft Office Access 2003 by Steve JohnsonÃÃ

Making Science Graphs and Interpreting Data

Error-Bar Charts from Summary Data

Archdiocese of Washington Catholic Schools Academic Standards Mathematics

Section 2.1 Graphs. The Coordinate Plane

Graphical critique & theory. Hadley Wickham

1.2. Pictorial and Tabular Methods in Descriptive Statistics

Section Graphs and Lines

Lesson 1. Unit 2 Practice Problems. Problem 2. Problem 1. Solution 1, 4, 5. Solution. Problem 3

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Lamella_roof Sketchup plugin. Introduction

A Mini-Manual for GNUPLOT

Microscopic Measurement

Points Lines Connected points X-Y Scatter. X-Y Matrix Star Plot Histogram Box Plot. Bar Group Bar Stacked H-Bar Grouped H-Bar Stacked

NOTES TO CONSIDER BEFORE ATTEMPTING EX 1A TYPES OF DATA

LINEAR PROGRAMMING: A GEOMETRIC APPROACH. Copyright Cengage Learning. All rights reserved.

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6. ) is graphed below:

Web-Friendly Sites. Planning & Design 1

Organizing and Summarizing Data

Second Edition. Concept Builders. Jana Kohout

Transcription:

User manual forggsubplot Garrett Grolemund September 3, 2012 1 Introduction ggsubplot expands the ggplot2 package to help users create multi-level plots, or embedded plots." Embedded plots embed subplots into a larger graph. ggsubplot is built on the observation that a subplot can be a ggplot geom. 2 New geoms ggsubplot introduces two new geoms for making embedded plots: geom_subplot and geom_subplot2d. Both create a layer that uses subplots as a geom. geom_subplot uses a grouping variable to divide data into subplots. geom_subplot2d performs 2d binning on the xy field and represents each bin with a subplot. ggsubplot also providesgeom_star and geom_coxcomb, two new geoms that are helpful for creating polar glyphs in an embedded plot. 2.1 geom_subplot geom_subplot can be used like other geoms in ggplot2 function calls. The syntax of geom_- subplot also parallels ggplot2 syntax, but geom_subplot requires a new aesthetic, subplot, and recognizes additional arguments. The subplot aesthetic should be set to a complete ggplot2 layer call (e.g,layer(...),geom_point(...),stat_bin(...), etc.). The layer call assigned to the subplot aesthetic should not include a data set, as each subplot will inherit part of the data set assigned to thegeom_subset layer. ## geom_point(aes(surftemp, temperature)) makes ## a complete layer ggplot(nasa) + geom_point(aes(surftemp, temperature)) ##...so it can be used as a subplot aesthetic ## geom_subplot requires x, y, group, and subplot aesthetics 1

Figure 1: The nasa data presents meterological data collected at 576 separate sites evenly spaced on a grid. We can compare all the observations together in a single scatterplot (left), or we can group observations into separate scatterplots - one for each measurement site, laid out on the map according to the locations of the measurement sites (right). ggplot(nasa) + map_americas + geom_subplot(aes(long, lat, group = id, subplot = geom_point(aes(surftemp, temperature), size = 1/4))) + geom_subplot attempts to pick a pretty size for the subplots based on the spacing of the subplots in the final graph. This size can be overwriten with the height and width parameters. height andwidth can be set to numbers, which will be interpretted as units along the x and y axes, or to proportions of the original pretty size with the rel() function. For example, width = rel(0.5) would reduce the width of the subplots to approximately half of their original width. 2.2 geom_subplot2d geom_subplot2d is similar togeom_subplot, but it does not take a group aesthetic. Instead it bins the coordinate plane into two dimensional bins and represents each bin with a subplot. The number of bins in the x and y directions can be specified with the bins or binwidth parameters, which expect vector arguments of length two. If a single number is entered for either parameter, it will be recycled to apply to both the x and y axis. Only one of bins or binwidth should be specfied as they create conflicting results. 2

Figure 2: Casualties in the Afghan War Diary by location (left) and the same information displayed by binning the data set according to latitude and longitude and drawing a barchart for each bin (right). ## Afghan War Journal raw data map_afghanistan + geom_point(aes(lon, lat, color = victim)) + ## 2d bin with bar chart subplots displaying data in each region map_afghanistan + geom_subplot2d(aes(lon, lat, subplot = geom_bar(aes(victim,..count.., fill = victim))), bins = c(15,12), ref = NULL, width = rel(0.8)) + Using binwidth 0.905Using binwidth 0.754 subsubsectionscales By default, x and y scales are held constant across subplots in both geom_subplot and geom_subplot2d. However, scales can be allowed to vary across subplots by setting x_scale = free or y_scale = free. This behavior parallels the use of scales while faceting in ggplot2. y_scale = free has the effect of showing conditional distributions,y_scale = identity displays marginal distributions. 3

subsectiongeom_star and geom_coxcomb geom_star and geom_coxcomb provide a way to include polar glyphs in cartesian embedded plots. geom_star creates a star glyph and geom_coxcomb creates a coxcomb glyph akin to the plots popularized by Florence Nightingale. Either geom can be used by itself, similar to geom_boxplot, but for individual glyphs, superior legend and axis details can be had by addingcoord_polar() to a line graph or a histogram. ## A single star one_nasa <- nasa[nasa$id == "1-1", ] ggplot(one_nasa) + geom_star(aes(x = 0, y = 0, r = surftemp, angle = date, fill = mean(temperature)), r.zero = FALSE) ## r.zero determines whether the origin of the star should ## correspond to r = 0? If FALSE, origin corresponds to the ## lowest value of r. ## Stars in an embedded plot ggplot(nasa) + map_americas + geom_subplot(aes(long, lat, group = id, subplot = geom_star(aes(x = 0, y = 0, r = surftemp, angle = date, fill = mean(surftemp)), r.zero = FALSE))) + ## A single coxcomb geom_coxcomb(aes(angle = month, fill = month)) ## Coxcombs in an embedded plot map_afghanistan + geom_subplot2d(aes(lon, lat, subplot = geom_coxcomb(aes(angle = month, fill = month))), bins = c(15, 12), ref = NULL) + Using binwidth 0.905Using binwidth 0.754 4

Figure 3: Figure 4: 5

3 Reference objects ggsubplot does not have the ability to draw a separate axis for each subplot. Moreover, such axes would be hard to read. Instead, subplots can be drawn with reference objects, such as a bounding box, that facilitate comparisons across subplots. Reference objects can be added to subplots by setting the ref parameter in geom_subplot and geom_subplot2d. The ref parameter takes the output of ref_box, which creates bounding boxes, ref_hline, which creates horizontal lines, or ref_vline, which creates vertical lines, see Figure 5. ref can also be set to NULL to omit reference objects from the plot. Reference objects are ggplot2 geoms with aesthetics such as fill, color, and transparency. These aesthetics can be set with the mapping parameter in the ref_... functions. ref_hline and ref_vline also recognize a thickness parameter which determines how thick the lines should be as a fraction of the width or height of the entire subplot. 2.0 ref = ref_box() 2.0 ref = ref_hline() 2.0 ref = ref_vline() 1.5 1.5 1.5 CO 2 (ppm) CO 2 (ppm) CO 2 (ppm) 1.0 1.0 1.0 0.5 M month 0.5 M month 0.5 M month Figure 5: ref = ref_box() creates bounding boxes for each subplot (left). ref = ref_hline() creates horizontal lines (middle). ref = ref_vline() creates vertical lines (right). ## Using reference object aesthetics to display additional information map_afghanistan + geom_subplot2d(aes(lon, lat, subplot = geom_freqpoly(aes(date), binwidth = 13151560)), bins = c(18, 14), ref = ref_box(aes(fill = length(date)), alpha =0.75)) + ## length(date) is a proxy for how many casualties ## occured in each region 6

length(date) 1000 2000 3000 4000 5000 Figure 6: Frequency of casualties by region 2004-2010. Total casualties are indicated by the background fill of each subplot. 4 Using embedded plots The best graphics tell a clear story, and for this reason users should pause before considering an embedded plot. Embedded plots contain more information than a normal plot and more dimensions that must be understood before the graph can be comprehended. Embedded plots also reduce the size at which many details are shown. This makes it easier to perceive overall patterns, but difficult to see precise details. Users should choose a simpler graph over an embedded plot whenever a simpler plot will suffice. Users should also plot subplots by themselves, at full scale, whenever details need to be measured from the graph accurately. However, simple plots sometimes fail to tell a story clearly and many stories cannot be told at all with a simple plot. In these scenarios, embedded plots provide a useful tool. Embedded plots can make patterns clear where simpler plots suffer from overplotting, Figure 2. An embedded plot will not suffer from overplotting even when the data set contains millions, billions, or trillions of points. Embedded plots are also particularly useful for exploring spatio-temporal data, Figure 3. The latitude, longitude, and time dimensions of spatio-temporal data consume three dimensions within a plot, which leaves little graphical power left over to observe variables of interest. The extra axes provided by subplots relieve this problem. These dimensions also make it easier to explore complicated, multi-dimensional relationships, such as interaction effects. Embedded plots have the capacity to display large amounts of information and they or- 7

ganize this information in an admirably intuitive way. When used wisely, embedded plots can reward a thoughtful viewer with insights that cannot not be perceived clearly or at all in simpler plots. 8