Rstudio GGPLOT2. Preparations. The first plot: Hello world! W2018 RENR690 Zihaohan Sang

Size: px
Start display at page:

Download "Rstudio GGPLOT2. Preparations. The first plot: Hello world! W2018 RENR690 Zihaohan Sang"

Transcription

1 Rstudio GGPLOT2 Preparations There are several different systems for creating data visualizations in R. We will introduce ggplot2, which is based on Leland Wilkinson s Grammar of Graphics. The learning curve is a bit steep, but ultimately you ll be able to produce complex graphs more quickly and easily. You first need to install the ggplot2 and other packages from CRAN: install.packages( ggplot2, gapminder, devtools ) library(ggplot2) ##this is the ggplot2 library(gapminder) ##the example data is from this package Also, to make graphs with ggplot2, the data must be in a data frame, and in long (as opposed to wide) format. The first plot: Hello world! An initial bit of code, to make a scatterplot by gapminder data set: excerpt of the Gapminder data on life expectancy, GDP per capita, and population by country. require(ggplot2) require(gapminder) str(gapminder) ##check data ## Classes 'tbl_df', 'tbl' and 'data.frame': 1704 obs. of 6 variables: ## $ country : Factor w/ 142 levels "Afghanistan",..: ## $ continent: Factor w/ 5 levels "Africa","Americas",..: ## $ year : int ## $ lifeexp : num ## $ pop : int ## $ gdppercap: num ggplot(data = gapminder, mapping = aes(x=gdppercap, y=lifeexp)) + geom_point() 1

2 It s not ideal, but not bad as the very first plot. ggplot() function creates a graphics object(like plot() function in base R plotting); then, another two key concepts in the grammar of graphics: aesthetics map features of the data (for example, the lifeexp variable) to features of the visualization (for example, the y-axis coordinate), and geoms concern what actually gets plotted (here, each data point becomes a point in the plot). You could also save the output as one object, like this: a = ggplot(data = gapminder, mapping = aes(x = gdppercap, y = lifeexp)) + geom_point() ##output is saved as a object, and no graph will show ##if you want to check/edit it, just print it out print(a) Why don t we color the points by location (continents)? maybe we could also change the size of points based on the population size? Of course we CAN. ggplot(data = gapminder, mapping = aes(x = gdppercap, y = lifeexp, col = continent, size = pop)) + geom_point() It s best to do the x-axis on a log scale. b <- ggplot(gapminder, aes(x=gdppercap, y=lifeexp, col = continent, size = pop)) + geom_point() + scale_x_log10() print(b) Looks much better! But there are too much points in the plot, why don t we seperate the dataset into several smaller ones(based on certain variable) and plots them one by one. Faceting A particularly valuable feature of ggplot2 is faceting: the ability to make a series of plots, conditional on the values of some selected variables. 2

3 For example, rather than coloring points by continent, one might separate the continents into separate panels. There are two functions for this, facet_grid() and facet_wrap(). The facet_wrap function is particularly useful if you have a lot of facets, for example, plotting by year. b + facet_wrap(~ year) Other geoms We ve focused so far on scatterplots, but one can also create one-dimensional summaries, such as histograms or boxplots. For a histogram, you want only the x aesthetic, and then use geom_histogram(), with binwidth to define the width of the bins. Here s a histogram of lifeexp for gm_2007 <- gapminder[gapminder$year==2007,] ggplot(gm_2007, aes(x=lifeexp)) + geom_histogram(binwidth=2) 3

4 Alternatively, we can look at boxplots, for which you need to define a continuous variable for y and a categorical variable for x. ggplot(gm_2007, aes(y=lifeexp, x=continent)) + geom_boxplot() Change theme The default of ggplots has gray background. If you don t like it, we can also change it by adding theme_... functions. b + theme_bw() b + theme_classic() b + theme_gray() bonus GGplot2 is fun! Not only can make plots, ggplot2 can also make simple animation. require(gganimate) devtools::install_github( dgrtwo/gganimate ) ## Loading required package: gganimate c = ggplot(gapminder, aes(x=gdppercap, y=lifeexp, col = continent, size = pop, frame = year)) + geom_point() + scale_x_log10() gganimate(c, "output.html") Intermediate ggplot2 Plotting means and error bars The example below is generated from ToothGrowth dataset: the response of the length of odontoblasts (cells responsible for tooth growth) in 60 guinea pigs. Each animal received one of 4

5 three dose levels of vitamin C (0.5, 1, and 2 mg/day) by one of two delivery methods, (orange juice or ascorbic acid (a form of vitamin C and coded as VC). Len represents mean tooth length(mm) of certain treatment, and standard deviation (sd), standard error (se) and 95% confident interval (ci) can be found in example.csv. dat <- read.csv("example2.csv") str(dat) ## 'data.frame': 6 obs. of 7 variables: ## $ supp: Factor w/ 2 levels "OJ","VC": ## $ dose: num ## $ N : int ## $ len : num ## $ sd : num ## $ se : num ## $ ci : num ##once we load the data, we can make the graph ##basic line plot with different color for each supplement type (VC or OJ) ggplot(dat, aes(x=dose, y=len, colour=supp, linetype = supp)) + geom_line() + geom_point() # add errorbar(standard error of the mean) ggplot(dat, aes(x=dose, y=len, colour=supp, linetpe = supp)) + geom_errorbar(aes(ymin=len-se, ymax=len+se), width=.1) + geom_line() + geom_point() # The errorbars overlapped, so use position_dodge to move them horizontally pd <- position_dodge(0.1) # move them.05 to the left and right ggplot(dat, aes(x=dose, y=len, colour=supp, linetype = supp)) + geom_errorbar(aes(ymin=len-se, ymax=len+se), width=.1, position=pd) + geom_line(position=pd) + geom_point(position=pd) 5

6 ggplot(dat, aes(x=dose, y=len, colour=supp, linetype = supp, group=supp)) + geom_errorbar(aes(ymin=len-se, ymax=len+se), colour="black", width=.1, position=pd) + geom_line(position=pd) + geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle xlab("dose (mg)") + #label on x axis ylab("tooth length(mm)") + #label on y axis scale_colour_hue(name="supplement type", # Legend label, use darker colors breaks=c("oj", "VC"), labels=c("orange juice", "Ascorbic acid"), l=40) + # Use darker colors, lightness=40 ggtitle("the Effect of Vitamin C on\ntooth Growth in Guinea Pigs") + expand_limits(y=0) + # Expand y range scale_y_continuous(breaks=0:20*4) + # Set tick every 4 theme_bw() + theme(legend.justification=c(1,0), legend.position=c(1,0)) # Position legend in bottom right A finished graph with error bars representing the standard error of the mean might look like this. Bar graphs The procedure can also be used to plot bar graphs, but bar plots only work for factors. # Use dose as a factor rather than numeric dat$dose <- factor(dat$dose) str(dat) # Error bars represent standard error of the mean ggplot(dat, aes(x=dose, y=len, fill=supp)) + geom_bar(position=position_dodge(), stat="identity") + geom_errorbar(aes(ymin=len-se, ymax=len+se), width=.2, # Width of the error bars position=position_dodge(.9)) + scale_fill_gray() 6

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

The following presentation is based on the ggplot2 tutotial written by Prof. Jennifer Bryan. Graphics Agenda Grammer of Graphics Using ggplot2 The following presentation is based on the ggplot2 tutotial written by Prof. Jennifer Bryan. ggplot2 (wiki) ggplot2 is a data visualization package Created

More information

Econ 2148, spring 2019 Data visualization

Econ 2148, spring 2019 Data visualization Econ 2148, spring 2019 Maximilian Kasy Department of Economics, Harvard University 1 / 43 Agenda One way to think about statistics: Mapping data-sets into numerical summaries that are interpretable by

More information

Facets and Continuous graphs

Facets and Continuous graphs Facets and Continuous graphs One way to add additional variables is with aesthetics. Another way, particularly useful for categorical variables, is to split your plot into facets, subplots that each display

More information

Introduction to Graphics with ggplot2

Introduction to Graphics with ggplot2 Introduction to Graphics with ggplot2 Reaction 2017 Flavio Santi Sept. 6, 2017 Flavio Santi Introduction to Graphics with ggplot2 Sept. 6, 2017 1 / 28 Graphics with ggplot2 ggplot2 [... ] allows you to

More information

Getting started with ggplot2

Getting started with ggplot2 Getting started with ggplot2 STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat/stat133 Course web: gastonsanchez.com/stat133 ggplot2 2 Resources for

More information

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

Lab5A - Intro to GGPLOT2 Z.Sang Sept 24, 2018 LabA - Intro to GGPLOT2 Z.Sang Sept 24, 218 In this lab you will learn to visualize raw data by plotting exploratory graphics with ggplot2 package. Unlike final graphs for publication or thesis, exploratory

More information

The diamonds dataset Visualizing data in R with ggplot2

The diamonds dataset Visualizing data in R with ggplot2 Lecture 2 STATS/CME 195 Matteo Sesia Stanford University Spring 2018 Contents The diamonds dataset Visualizing data in R with ggplot2 The diamonds dataset The tibble package The tibble package is part

More information

Data visualization with ggplot2

Data visualization with ggplot2 Data visualization with ggplot2 Visualizing data in R with the ggplot2 package Authors: Mateusz Kuzak, Diana Marek, Hedi Peterson, Dmytro Fishman Disclaimer We will be using the functions in the ggplot2

More information

Ggplot2 QMMA. Emanuele Taufer. 2/19/2018 Ggplot2 (1)

Ggplot2 QMMA. Emanuele Taufer. 2/19/2018 Ggplot2 (1) Ggplot2 QMMA Emanuele Taufer file:///c:/users/emanuele.taufer/google%20drive/2%20corsi/5%20qmma%20-%20mim/0%20classes/1-4_ggplot2.html#(1) 1/27 Ggplot2 ggplot2 is a plotting system for R, based on the

More information

Introduction to R and the tidyverse. Paolo Crosetto

Introduction to R and the tidyverse. Paolo Crosetto Introduction to R and the tidyverse Paolo Crosetto Lecture 1: plotting Before we start: Rstudio Interactive console Object explorer Script window Plot window Before we start: R concatenate: c() assign:

More information

Importing and visualizing data in R. Day 3

Importing and visualizing data in R. Day 3 Importing and visualizing data in R Day 3 R data.frames Like pandas in python, R uses data frame (data.frame) object to support tabular data. These provide: Data input Row- and column-wise manipulation

More information

Package ggextra. April 4, 2018

Package ggextra. April 4, 2018 Package ggextra April 4, 2018 Title Add Marginal Histograms to 'ggplot2', and More 'ggplot2' Enhancements Version 0.8 Collection of functions and layers to enhance 'ggplot2'. The flagship function is 'ggmarginal()',

More information

Creating elegant graphics in R with ggplot2

Creating elegant graphics in R with ggplot2 Creating elegant graphics in R with ggplot2 Lauren Steely Bren School of Environmental Science and Management University of California, Santa Barbara What is ggplot2, and why is it so great? ggplot2 is

More information

data visualization Show the Data Snow Month skimming deep waters

data visualization Show the Data Snow Month skimming deep waters data visualization skimming deep waters Show the Data Snow 2 4 6 8 12 Minimize Distraction Minimize Distraction Snow 2 4 6 8 12 2 4 6 8 12 Make Big Data Coherent Reveal Several Levels of Detail 1974 1975

More information

Package beanplot. R topics documented: February 19, Type Package

Package beanplot. R topics documented: February 19, Type Package Type Package Package beanplot February 19, 2015 Title Visualization via Beanplots (like Boxplot/Stripchart/Violin Plot) Version 1.2 Date 2014-09-15 Author Peter Kampstra Maintainer Peter Kampstra

More information

Data Visualization Using R & ggplot2. Karthik Ram October 6, 2013

Data Visualization Using R & ggplot2. Karthik Ram October 6, 2013 Data Visualization Using R & ggplot2 Karthik Ram October 6, 2013 Some housekeeping Install some packages install.packages("ggplot2", dependencies = TRUE) install.packages("plyr") install.packages("ggthemes")

More information

Plotting with Rcell (Version 1.2-5)

Plotting with Rcell (Version 1.2-5) Plotting with Rcell (Version 1.2-) Alan Bush October 7, 13 1 Introduction Rcell uses the functions of the ggplots2 package to create the plots. This package created by Wickham implements the ideas of Wilkinson

More information

03 - Intro to graphics (with ggplot2)

03 - Intro to graphics (with ggplot2) 3 - Intro to graphics (with ggplot2) ST 597 Spring 217 University of Alabama 3-dataviz.pdf Contents 1 Intro to R Graphics 2 1.1 Graphics Packages................................ 2 1.2 Base Graphics...................................

More information

Introduction to ggvis. Aimee Gott R Consultant

Introduction to ggvis. Aimee Gott R Consultant Introduction to ggvis Overview Recap of the basics of ggplot2 Getting started with ggvis The %>% operator Changing aesthetics Layers Interactivity Resources for the Workshop R (version 3.1.2) RStudio ggvis

More information

Intro to R for Epidemiologists

Intro to R for Epidemiologists Lab 9 (3/19/15) Intro to R for Epidemiologists Part 1. MPG vs. Weight in mtcars dataset The mtcars dataset in the datasets package contains fuel consumption and 10 aspects of automobile design and performance

More information

Advanced Plotting with ggplot2. Algorithm Design & Software Engineering November 13, 2016 Stefan Feuerriegel

Advanced Plotting with ggplot2. Algorithm Design & Software Engineering November 13, 2016 Stefan Feuerriegel Advanced Plotting with ggplot2 Algorithm Design & Software Engineering November 13, 2016 Stefan Feuerriegel Today s Lecture Objectives 1 Distinguishing different types of plots and their purpose 2 Learning

More information

BIOSTATS 640 Spring 2018 Introduction to R Data Description. 1. Start of Session. a. Preliminaries... b. Install Packages c. Attach Packages...

BIOSTATS 640 Spring 2018 Introduction to R Data Description. 1. Start of Session. a. Preliminaries... b. Install Packages c. Attach Packages... BIOSTATS 640 Spring 2018 Introduction to R and R-Studio Data Description Page 1. Start of Session. a. Preliminaries... b. Install Packages c. Attach Packages... 2. Load R Data.. a. Load R data frames...

More information

ggplot2 for Epi Studies Leah McGrath, PhD November 13, 2017

ggplot2 for Epi Studies Leah McGrath, PhD November 13, 2017 ggplot2 for Epi Studies Leah McGrath, PhD November 13, 2017 Introduction Know your data: data exploration is an important part of research Data visualization is an excellent way to explore data ggplot2

More information

Plotting with ggplot2: Part 2. Biostatistics

Plotting with ggplot2: Part 2. Biostatistics Plotting with ggplot2: Part 2 Biostatistics 14.776 Building Plots with ggplot2 When building plots in ggplot2 (rather than using qplot) the artist s palette model may be the closest analogy Plots are built

More information

Week 4. Big Data Analytics - data.frame manipulation with dplyr

Week 4. Big Data Analytics - data.frame manipulation with dplyr Week 4. Big Data Analytics - data.frame manipulation with dplyr Hyeonsu B. Kang hyk149@eng.ucsd.edu April 2016 1 Dplyr In the last lecture we have seen how to index an individual cell in a data frame,

More information

An Introduction to R Graphics

An Introduction to R Graphics An Introduction to R Graphics PnP Group Seminar 25 th April 2012 Why use R for graphics? Fast data exploration Easy automation and reproducibility Create publication quality figures Customisation of almost

More information

Lecture 4: Data Visualization I

Lecture 4: Data Visualization I Lecture 4: Data Visualization I Data Science for Business Analytics Thibault Vatter Department of Statistics, Columbia University and HEC Lausanne, UNIL 11.03.2018 Outline 1 Overview

More information

EXST 7014, Lab 1: Review of R Programming Basics and Simple Linear Regression

EXST 7014, Lab 1: Review of R Programming Basics and Simple Linear Regression EXST 7014, Lab 1: Review of R Programming Basics and Simple Linear Regression OBJECTIVES 1. Prepare a scatter plot of the dependent variable on the independent variable 2. Do a simple linear regression

More information

Statistical transformations

Statistical transformations Statistical transformations Next, let s take a look at a bar chart. Bar charts seem simple, but they are interesting because they reveal something subtle about plots. Consider a basic bar chart, as drawn

More information

Introduction to R and R-Studio Toy Program #2 Excel to R & Basic Descriptives

Introduction to R and R-Studio Toy Program #2 Excel to R & Basic Descriptives Introduction to R and R-Studio 2018-19 Toy Program #2 Basic Descriptives Summary The goal of this toy program is to give you a boiler for working with your own excel data. So, I m hoping you ll try!. In

More information

LondonR: Introduction to ggplot2. Nick Howlett Data Scientist

LondonR: Introduction to ggplot2. Nick Howlett Data Scientist LondonR: Introduction to ggplot2 Nick Howlett Data Scientist Email: nhowlett@mango-solutions.com Agenda Catie Gamble, M&S - Using R to Understand Revenue Opportunities for your Online Business Andrie de

More information

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

A set of rules describing how to compose a 'vocabulary' into permissible 'sentences' Lecture 8: The grammar of graphics STAT598z: Intro. to computing for statistics Vinayak Rao Department of Statistics, Purdue University Grammar? A set of rules describing how to compose a 'vocabulary'

More information

Stat 849: Plotting responses and covariates

Stat 849: Plotting responses and covariates Stat 849: Plotting responses and covariates Douglas Bates 10-09-03 Outline Contents 1 R Graphics Systems Graphics systems in R ˆ R provides three dierent high-level graphics systems base graphics The system

More information

ggplot in 3 easy steps (maybe 2 easy steps)

ggplot in 3 easy steps (maybe 2 easy steps) 1 ggplot in 3 easy steps (maybe 2 easy steps) 1.1 aesthetic: what you want to graph (e.g. x, y, z). 1.2 geom: how you want to graph it. 1.3 options: optional titles, themes, etc. 2 Background R has a number

More information

ggplot2 for beginners Maria Novosolov 1 December, 2014

ggplot2 for beginners Maria Novosolov 1 December, 2014 ggplot2 for beginners Maria Novosolov 1 December, 214 For this tutorial we will use the data of reproductive traits in lizards on different islands (found in the website) First thing is to set the working

More information

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

An introduction to ggplot: An implementation of the grammar of graphics in R An introduction to ggplot: An implementation of the grammar of graphics in R Hadley Wickham 00-0-7 1 Introduction Currently, R has two major systems for plotting data, base graphics and lattice graphics

More information

The Average and SD in R

The Average and SD in R The Average and SD in R The Basics: mean() and sd() Calculating an average and standard deviation in R is straightforward. The mean() function calculates the average and the sd() function calculates the

More information

Data Visualization in R

Data Visualization in R Data Visualization in R L. Torgo ltorgo@fc.up.pt Faculdade de Ciências / LIAAD-INESC TEC, LA Universidade do Porto Aug, 2017 Introduction Motivation for Data Visualization Humans are outstanding at detecting

More information

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

Large data. Hadley Wickham. Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University. Large data Hadley Wickham Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University November 2010 1. The diamonds data 2. Histograms and bar charts 3. Frequency polygons

More information

A Quick and focused overview of R data types and ggplot2 syntax MAHENDRA MARIADASSOU, MARIA BERNARD, GERALDINE PASCAL, LAURENT CAUQUIL

A Quick and focused overview of R data types and ggplot2 syntax MAHENDRA MARIADASSOU, MARIA BERNARD, GERALDINE PASCAL, LAURENT CAUQUIL A Quick and focused overview of R data types and ggplot2 syntax MAHENDRA MARIADASSOU, MARIA BERNARD, GERALDINE PASCAL, LAURENT CAUQUIL 1 R and RStudio OVERVIEW 2 R and RStudio R is a free and open environment

More information

Data Visualization in R

Data Visualization in R Data Visualization in R L. Torgo ltorgo@fc.up.pt Faculdade de Ciências / LIAAD-INESC TEC, LA Universidade do Porto Oct, 216 Introduction Motivation for Data Visualization Humans are outstanding at detecting

More information

Install RStudio from - use the standard installation.

Install RStudio from   - use the standard installation. Session 1: Reading in Data Before you begin: Install RStudio from http://www.rstudio.com/ide/download/ - use the standard installation. Go to the course website; http://faculty.washington.edu/kenrice/rintro/

More information

Introduction to R for Beginners, Level II. Jeon Lee Bio-Informatics Core Facility (BICF), UTSW

Introduction to R for Beginners, Level II. Jeon Lee Bio-Informatics Core Facility (BICF), UTSW Introduction to R for Beginners, Level II Jeon Lee Bio-Informatics Core Facility (BICF), UTSW Basics of R Powerful programming language and environment for statistical computing Useful for very basic analysis

More information

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

ggplot2 basics Hadley Wickham Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University September 2011 ggplot2 basics Hadley Wickham Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University September 2011 1. Diving in: scatterplots & aesthetics 2. Facetting 3. Geoms

More information

Package ggdark. R topics documented: January 11, Type Package Title Dark Mode for 'ggplot2' Themes Version Author Neal Grantham

Package ggdark. R topics documented: January 11, Type Package Title Dark Mode for 'ggplot2' Themes Version Author Neal Grantham Type Package Title Dark Mode for 'ggplot2' Themes Version 0.2.1 Author Neal Grantham Package ggdark January 11, 2019 Maintainer Neal Grantham Activate dark mode on your favorite 'ggplot2'

More information

INTRODUCTION TO DATA. Welcome to the course!

INTRODUCTION TO DATA. Welcome to the course! INTRODUCTION TO DATA Welcome to the course! High School and Beyond id gender race socst 70 male white 57 121 female white 61 86 male white 31 137 female white 61 Loading data > # Load package > library(openintro)

More information

ggplot2 and maps Marcin Kierczak 11/10/2016

ggplot2 and maps Marcin Kierczak 11/10/2016 11/10/2016 The grammar of graphics Hadley Wickham s ggplot2 package implements the grammar of graphics described in Leland Wilkinson s book by the same title. It offers a very flexible and efficient way

More information

Maps & layers. Hadley Wickham. Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University.

Maps & layers. Hadley Wickham. Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University. Maps & layers Hadley Wickham Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University July 2010 1. Introduction to map data 2. Map projections 3. Loading & converting

More information

Introduction to Minitab 1

Introduction to Minitab 1 Introduction to Minitab 1 We begin by first starting Minitab. You may choose to either 1. click on the Minitab icon in the corner of your screen 2. go to the lower left and hit Start, then from All Programs,

More information

Session 3 Nick Hathaway;

Session 3 Nick Hathaway; Session 3 Nick Hathaway; nicholas.hathaway@umassmed.edu Contents Manipulating Data frames and matrices 1 Converting to long vs wide formats.................................... 2 Manipulating data in table........................................

More information

Graphics in R. There are three plotting systems in R. base Convenient, but hard to adjust after the plot is created

Graphics in R. There are three plotting systems in R. base Convenient, but hard to adjust after the plot is created Graphics in R There are three plotting systems in R base Convenient, but hard to adjust after the plot is created lattice Good for creating conditioning plot ggplot2 Powerful and flexible, many tunable

More information

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

Stat405. Displaying distributions. Hadley Wickham. Thursday, August 23, 12 Stat405 Displaying distributions Hadley Wickham 1. The diamonds data 2. Histograms and bar charts 3. Homework Diamonds Diamonds data ~54,000 round diamonds from http://www.diamondse.info/ Carat, colour,

More information

The Basics of Plotting in R

The Basics of Plotting in R The Basics of Plotting in R R has a built-in Datasets Package: iris mtcars precip faithful state.x77 USArrests presidents ToothGrowth USJudgeRatings You can call built-in functions like hist() or plot()

More information

Visualizing Data: Customization with ggplot2

Visualizing Data: Customization with ggplot2 Visualizing Data: Customization with ggplot2 Data Science 1 Stanford University, Department of Statistics ggplot2: Customizing graphics in R ggplot2 by RStudio s Hadley Wickham and Winston Chang offers

More information

Session 5 Nick Hathaway;

Session 5 Nick Hathaway; Session 5 Nick Hathaway; nicholas.hathaway@umassmed.edu Contents Adding Text To Plots 1 Line graph................................................. 1 Bar graph..................................................

More information

Stat 849: Plotting responses and covariates

Stat 849: Plotting responses and covariates Stat 849: Plotting responses and covariates Douglas Bates Department of Statistics University of Wisconsin, Madison 2010-09-03 Outline R Graphics Systems Brain weight Cathedrals Longshoots Domedata Summary

More information

Graphical critique & theory. Hadley Wickham

Graphical critique & theory. Hadley Wickham Graphical critique & theory Hadley Wickham Exploratory graphics Are for you (not others). Need to be able to create rapidly because your first attempt will never be the most revealing. Iteration is crucial

More information

Old Faithful Chris Parrish

Old Faithful Chris Parrish Old Faithful Chris Parrish 17-4-27 Contents Old Faithful eruptions 1 data.................................................. 1 duration................................................ 1 waiting time..............................................

More information

Introduction to Data Visualization

Introduction to Data Visualization Introduction to Data Visualization Author: Nicholas G Reich This material is part of the statsteachr project Made available under the Creative Commons Attribution-ShareAlike 3.0 Unported License: http://creativecommons.org/licenses/by-sa/3.0/deed.en

More information

TrelliscopeJS. Ryan Hafen. Modern Approaches to Data Exploration with Trellis Display

TrelliscopeJS. Ryan Hafen. Modern Approaches to Data Exploration with Trellis Display TrelliscopeJS Modern Approaches to Data Exploration with Trellis Display Ryan Hafen Hafen Consulting, LLC Purdue University @hafenstats http://bit.ly/trelliscopejs1 All examples in this talk are reproducible

More information

An introduction to R Graphics 4. ggplot2

An introduction to R Graphics 4. ggplot2 An introduction to R Graphics 4. ggplot2 Michael Friendly SCS Short Course March, 2017 http://www.datavis.ca/courses/rgraphics/ Resources: Books Hadley Wickham, ggplot2: Elegant graphics for data analysis,

More information

Using Built-in Plotting Functions

Using Built-in Plotting Functions Workshop: Graphics in R Katherine Thompson (katherine.thompson@uky.edu Department of Statistics, University of Kentucky September 15, 2016 Using Built-in Plotting Functions ## Plotting One Quantitative

More information

INTRODUCTION TO R. Basic Graphics

INTRODUCTION TO R. Basic Graphics INTRODUCTION TO R Basic Graphics Graphics in R Create plots with code Replication and modification easy Reproducibility! graphics package ggplot2, ggvis, lattice graphics package Many functions plot()

More information

PRESENTING DATA. Overview. Some basic things to remember

PRESENTING DATA. Overview. Some basic things to remember PRESENTING DATA This handout is one of a series that accompanies An Adventure in Statistics: The Reality Enigma by me, Andy Field. These handouts are offered for free (although I hope you will buy the

More information

# Call plot plot(gg)

# Call plot plot(gg) Most of the requirements related to look and feel can be achieved using the theme() function. It accepts a large number of arguments. Type?theme in the R console and see for yourself. # Setup options(scipen=999)

More information

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

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2 Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2 Package gggenes November 7, 2018 Provides a 'ggplot2' geom and helper functions for drawing gene arrow maps. Depends R (>= 3.3.0) Imports grid (>=

More information

BIO 360: Vertebrate Physiology Lab 9: Graphing in Excel. Lab 9: Graphing: how, why, when, and what does it mean? Due 3/26

BIO 360: Vertebrate Physiology Lab 9: Graphing in Excel. Lab 9: Graphing: how, why, when, and what does it mean? Due 3/26 Lab 9: Graphing: how, why, when, and what does it mean? Due 3/26 INTRODUCTION Graphs are one of the most important aspects of data analysis and presentation of your of data. They are visual representations

More information

Data Handling: Import, Cleaning and Visualisation

Data Handling: Import, Cleaning and Visualisation Data Handling: Import, Cleaning and Visualisation 1 Data Display Lecture 11: Visualisation and Dynamic Documents Prof. Dr. Ulrich Matter (University of St. Gallen) 13/12/18 In the last part of a data pipeline

More information

1 The ggplot2 workflow

1 The ggplot2 workflow ggplot2 @ statistics.com Week 2 Dope Sheet Page 1 dope, n. information especially from a reliable source [the inside dope]; v. figure out usually used with out; adj. excellent 1 This week s dope This week

More information

Demo yeast mutant analysis

Demo yeast mutant analysis Demo yeast mutant analysis Jean-Yves Sgro February 20, 2018 Contents 1 Analysis of yeast growth data 1 1.1 Set working directory........................................ 1 1.2 List all files in directory.......................................

More information

Module 6: Advanced Plotting in R

Module 6: Advanced Plotting in R Module 6: Advanced Plotting in R The purpose of this handout is to teach you the basic elements of making advanced graphics in R. You do not need to have completed Modules 1-4 in order for this Module

More information

LAST UPDATED: October 16, 2012 DISTRIBUTIONS PSYC 3031 INTERMEDIATE STATISTICS LABORATORY. J. Elder

LAST UPDATED: October 16, 2012 DISTRIBUTIONS PSYC 3031 INTERMEDIATE STATISTICS LABORATORY. J. Elder LAST UPDATED: October 16, 2012 DISTRIBUTIONS Acknowledgements 2 Some of these slides have been sourced or modified from slides created by A. Field for Discovering Statistics using R. LAST UPDATED: October

More information

Data Visualization. Module 7

Data Visualization.  Module 7 Data Visualization http://datascience.tntlab.org Module 7 Today s Agenda A Brief Reminder to Update your Software A walkthrough of ggplot2 Big picture New cheatsheet, with some familiar caveats Geometric

More information

ETC 2420/5242 Lab Di Cook Week 5

ETC 2420/5242 Lab Di Cook Week 5 ETC 2420/5242 Lab 5 2017 Di Cook Week 5 Purpose This lab is to practice fitting linear models. Reading Read the material on fitting regression models in Statistics online textbook, Diez, Barr, Cetinkaya-

More information

User manual forggsubplot

User manual forggsubplot 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

More information

You submitted this quiz on Sat 17 May :19 AM CEST. You got a score of out of

You submitted this quiz on Sat 17 May :19 AM CEST. You got a score of out of uiz Feedback Coursera 1 of 7 01/06/2014 20:02 Feedback Week 2 Quiz Help You submitted this quiz on Sat 17 May 2014 11:19 AM CEST. You got a score of 10.00 out of 10.00. Question 1 Under the lattice graphics

More information

Resources: Books. Data Visualization in R 4. ggplot2. What is ggplot2? Resources: Cheat sheets

Resources: Books. Data Visualization in R 4. ggplot2. What is ggplot2? Resources: Cheat sheets Resources: Books Hadley Wickham, ggplot2: Elegant graphics for data analysis, 2nd Ed. 1st Ed: Online, http://ggplot2.org/book/ ggplot2 Quick Reference: http://sape.inf.usi.ch/quick-reference/ggplot2/ Complete

More information

social data science Data Visualization Sebastian Barfort August 08, 2016 University of Copenhagen Department of Economics 1/86

social data science Data Visualization Sebastian Barfort August 08, 2016 University of Copenhagen Department of Economics 1/86 social data science Data Visualization Sebastian Barfort August 08, 2016 University of Copenhagen Department of Economics 1/86 Who s ahead in the polls? 2/86 What values are displayed in this chart? 3/86

More information

A Manual How To Use Online Analysis Tools

A Manual How To Use Online Analysis Tools A Manual How To Use Online Analysis Tools How To Use Online Analysis Tools By using the V-Dem analysis and visualisation tool, a user can analyse the development of democracy from 1900 to 2012. There are

More information

SAMLab Tip Sheet #4 Creating a Histogram

SAMLab Tip Sheet #4 Creating a Histogram Creating a Histogram Another great feature of Excel is its ability to visually display data. This Tip Sheet demonstrates how to create a histogram and provides a general overview of how to create graphs,

More information

Data Visualization Principles for Scientific Communication

Data Visualization Principles for Scientific Communication Data Visualization Principles for Scientific Communication 8-888 Introduction to Linguistic Data Analysis Using R Jerzy Wieczorek 11//15 Follow along These slides and a summary checklist are at http://www.stat.cmu.edu/~jwieczor/

More information

Knitr. Introduction to R for Public Health Researchers

Knitr. Introduction to R for Public Health Researchers Knitr Introduction to R for Public Health Researchers Introduction Exploratory Analysis Plots of bike length Multiple Facets Means by type Linear Models Grabbing coefficients Broom package Testing Nested

More information

<style> pre { overflow-x: auto; } pre code { word-wrap: normal; white-space: pre; } </style>

<style> pre { overflow-x: auto; } pre code { word-wrap: normal; white-space: pre; } </style> --- title: "Visualization for Data Management Modules Wheat CAP 2018" author: name: "Jean-Luc Jannink" affiliation: "USDA-ARS" date: "June 7, 2018" output: html_document: fig_height: 6 fig_width: 12 highlight:

More information

Data Science and Machine Learning Essentials

Data Science and Machine Learning Essentials Data Science and Machine Learning Essentials Lab 3C Evaluating Models in Azure ML By Stephen Elston and Graeme Malcolm Overview In this lab, you will learn how to evaluate and improve the performance of

More information

Data Science and Machine Learning Essentials

Data Science and Machine Learning Essentials Data Science and Machine Learning Essentials Lab 3A Visualizing Data By Stephen Elston and Graeme Malcolm Overview In this lab, you will learn how to use R or Python to visualize data. If you intend to

More information

Basic Statistical Methods

Basic Statistical Methods Basic Statistical Methods Lecture 9 Nicholas Christian BIOST 2094 Spring 2011 Outline 1. Summary Statistics 2. Comparing Means 3. Comparing Variances 4. Comparing Proportions 5. Testing Normality 6. Testing

More information

Package lvplot. August 29, 2016

Package lvplot. August 29, 2016 Version 0.2.0 Title Letter Value 'Boxplots' Package lvplot August 29, 2016 Implements the letter value 'boxplot' which extends the standard 'boxplot' to deal with both larger and smaller number of data

More information

Lecture 09. Graphics::ggplot I R Teaching Team. October 1, 2018

Lecture 09. Graphics::ggplot I R Teaching Team. October 1, 2018 Lecture 09 Graphics::ggplot I 2018 R Teaching Team October 1, 2018 Acknowledgements 1. Mike Fliss & Sara Levintow! 2. stackoverflow (particularly user David for lecture styling - link) 3. R Markdown: The

More information

Session 1 Nick Hathaway;

Session 1 Nick Hathaway; Session 1 Nick Hathaway; nicholas.hathaway@umassmed.edu Contents R Basics 1 Variables/objects.............................................. 1 Functions..................................................

More information

Creating a Histogram Creating a Histogram

Creating a Histogram Creating a Histogram Creating a Histogram Another great feature of Excel is its ability to visually display data. This Tip Sheet demonstrates how to create a histogram and provides a general overview of how to create graphs,

More information

Package ggseas. June 12, 2018

Package ggseas. June 12, 2018 Package ggseas June 12, 2018 Title 'stats' for Seasonal Adjustment on the Fly with 'ggplot2' Version 0.5.4 Maintainer Peter Ellis Provides 'ggplot2' 'stats' that estimate

More information

EXPLORATORY DATA ANALYSIS. Introducing the data

EXPLORATORY DATA ANALYSIS. Introducing the data EXPLORATORY DATA ANALYSIS Introducing the data Email data set > email # A tibble: 3,921 21 spam to_multiple from cc sent_email time image 1 not-spam 0 1 0 0

More information

Package sciplot. February 15, 2013

Package sciplot. February 15, 2013 Package sciplot February 15, 2013 Version 1.1-0 Title Scientific Graphing Functions for Factorial Designs Author Manuel Morales , with code developed by the R Development Core Team

More information

Package nonmem2r. April 5, 2018

Package nonmem2r. April 5, 2018 Type Package Package nonmem2r April 5, 2018 Title Loading NONMEM Output Files and Simulate with Parameter Uncertainty Version 0.1.9 Author Magnus Astrand Maintainer Magnus Astrand

More information

Individual Covariates

Individual Covariates WILD 502 Lab 2 Ŝ from Known-fate Data with Individual Covariates Today s lab presents material that will allow you to handle additional complexity in analysis of survival data. The lab deals with estimation

More information

DATA VISUALIZATION WITH GGPLOT2. Coordinates

DATA VISUALIZATION WITH GGPLOT2. Coordinates DATA VISUALIZATION WITH GGPLOT2 Coordinates Coordinates Layer Controls plot dimensions coord_ coord_cartesian() Zooming in scale_x_continuous(limits =...) xlim() coord_cartesian(xlim =...) Original Plot

More information

Financial Econometrics Practical

Financial Econometrics Practical Financial Econometrics Practical Practical 3: Plotting in R NF Katzke Table of Contents 1 Introduction 1 1.0.1 Install ggplot2................................................. 2 1.1 Get data Tidy.....................................................

More information

Package ggsubplot. February 15, 2013

Package ggsubplot. February 15, 2013 Package ggsubplot February 15, 2013 Maintainer Garrett Grolemund License GPL Title Explore complex data by embedding subplots within plots. LazyData true Type Package Author Garrett

More information

Graphing Bivariate Relationships

Graphing Bivariate Relationships Graphing Bivariate Relationships Overview To fully explore the relationship between two variables both summary statistics and visualizations are important. For this assignment you will describe the relationship

More information

R Workshop 1: Introduction to R

R Workshop 1: Introduction to R R Workshop 1: Introduction to R Gavin Simpson Environmental Change Research Centre, Department of Geography UCL April 30, 2013 Gavin Simpson (ECRC, UCL) Introduction to R April 30, 2013 1 / 43 Outline

More information