Introduction to R for Epidemiologists

Similar documents
Manufactured Home Production by Product Mix ( )

Reporting Child Abuse Numbers by State

How Social is Your State Destination Marketing Organization (DMO)?

Alaska ATU 1 $13.85 $4.27 $ $ Tandem Switching $ Termination

What's Next for Clean Water Act Jurisdiction

Arizona does not currently have this ability, nor is it part of the new system in development.

Alaska ATU 1 $13.85 $4.27 $ $ Tandem Switching $ Termination

MapMarker Standard 10.0 Release Notes

Alaska no no all drivers primary. Arizona no no no not applicable. primary: texting by all drivers but younger than

AGILE BUSINESS MEDIA, LLC 500 E. Washington St. Established 2002 North Attleboro, MA Issues Per Year: 12 (412)

MapMarker Plus 10.2 Release Notes

Ted C. Jones, PhD Chief Economist

Chart 2: e-waste Processed by SRD Program in Unregulated States

Bulk Resident Agent Change Filings. Question by: Stephanie Mickelsen. Jurisdiction. Date: 20 July Question(s)

MapMarker Plus v Release Notes

CONSOLIDATED MEDIA REPORT B2B Media 6 months ended June 30, 2018

User Experience Task Force

MapMarker Plus 12.0 Release Notes

Is your standard BASED on the IACA standard, or is it a complete departure from the. If you did consider. using the IACA

π H LBS. x.05 LB. PARCEL SCALE OVERVIEW OF CONTROLS uline.com CONTROL PANEL CONTROL FUNCTIONS lb kg 0

Question by: Scott Primeau. Date: 20 December User Accounts 2010 Dec 20. Is an account unique to a business record or to a filer?

Publisher's Sworn Statement

Managing Transportation Research with Databases and Spreadsheets: Survey of State Approaches and Capabilities

CONSOLIDATED MEDIA REPORT Business Publication 6 months ended December 31, 2017

SECTION 2 NAVIGATION SYSTEM: DESTINATION SEARCH

LAB #6: DATA HANDING AND MANIPULATION

Oklahoma Economic Outlook 2016

Wireless Network Data Speeds Improve but Not Incidence of Data Problems, J.D. Power Finds

Oklahoma Economic Outlook 2015

Terry McAuliffe-VA. Scott Walker-WI

J.D. Power and Associates Reports: Overall Wireless Network Problem Rates Differ Considerably Based on Type of Usage Activity

4/25/2013. Bevan Erickson VP, Marketing

Crop Progress. Corn Emerged - Selected States [These 18 States planted 92% of the 2016 corn acreage]

Loops. An R programmer can determine the order of processing of commands, via use of the control statements; repeat{}, while(), for(), break, and next

For Every Action There is An Equal and Opposite Reaction Newton Was an Economist - The Outlook for Real Estate and the Economy

Established Lafayette St., P.O. Box 998 Issues Per Year: 12 Yarmouth, ME 04096

57,611 59,603. Print Pass-Along Recipients Website

How Employers Use E-Response Date: April 26th, 2016 Version: 6.51

MapMarker Plus v Release Notes

US STATE CONNECTIVITY

Instructions for Enrollment

Crop Progress. Corn Dough Selected States [These 18 States planted 92% of the 2017 corn acreage] Corn Dented Selected States ISSN:

Advanced LabVIEW for FTC

Disaster Economic Impact

JIM TAYLOR PILOT CAR SVC J & J PILOT CAR SVC PILOTCAR.NET ROYAL ESCORT

Real Estate Forecast 2017

BOUNDARY PVC EVERLASTING FENCE 100% VIRGIN VINYL THE NEW YORK STYLE FENCE STOCK COLORS WHITE BEIGE BROWN/CLAY GRAY. Copyright 2007

WINDSTREAM CARRIER ETHERNET: E-NNI Guide & ICB Processes

The Promise of Brown v. Board Not Yet Realized The Economic Necessity to Deliver on the Promise

Embedded Systems Conference Silicon Valley

Unsupervised Learning

2011 Aetna Producer Certification Help Guide. Updated July 28, 2011

Levels of Measurement. Data classing principles and methods. Nominal. Ordinal. Interval. Ratio. Nominal: Categorical measure [e.g.

Local Telephone Competition: Status as of December 31, 2010

12 Interacting with Trellis Displays

Distracted Driving Accident Claims Involving Mobile Devices Special Considerations and New Frontiers in Legal Liability

Online Certification/Authentication of Documents re: Business Entities. Date: 05 April 2011

Guide to the Virginia Mericle Menu Collection

DATES OF EVENT: Conference: March 31 April 2, 2009 Exhibits: April 1 3, Sands Expo & Convention Center, Las Vegas, NV

Ted C. Jones Chief Economist. Ted C. Jones, PhD Chief Economist

Summary of the State Elder Abuse. Questionnaire for Hawaii

DATES OF EVENT: Conference: March 23 March 25, 2010 Exhibits: March 24 March 26, Sands Expo & Convention Center, Las Vegas, NV

76 Million Boomers. 83 Million Millennials 19 to Million Millennials 16 to 35

Summary of the State Elder Abuse. Questionnaire for Alaska

C.A.S.E. Community Partner Application

DATES OF NEXT EVENT: Conference: June 4 8, 2007 Exhibits: June 4 7, 2007 San Diego Convention Center, San Diego, CA

BRAND REPORT FOR THE 6 MONTH PERIOD ENDED JUNE 2014

ADJUSTER ONLINE UPDATING INSTRUCTIONS

2018 Payroll Tax Table Update Instructions (Effective January 2, 2018)

Qualified recipients are Chief Executive Officers, Partners, Chairmen, Presidents, Owners, VPs, and other real estate management personnel.

SQP Product Guide. Paper & Packaging Needs

FDA's Collaborative Efforts to Promote ISO/IEC 17025:2005 Accreditation for the Nation's Food/Feed Testing Laboratories

Legal-Compliance Department March 22, 2019 Page 1 of 7

24-Month Extension of Post-Completion Optional Practical Training (OPT)

Telephone Appends. White Paper. September Prepared by

Legal-Compliance Department October 11, 2017 Page 1 of 8

KEY BENEFITS STANDARD FEATURE(S)

No Place But Up Interest Rates Rents, Prices Real Estate and the Economy

NEHA-NRPP APPLICATION FOR CERTIFICATION

Options not included in this section of Schedule No. 12 have previously expired and the applicable pages may have been deleted/removed.

EyeforTravel s Hotel Distribution Index. EyeforTravel s Hotel Distribution Index

Summary of the State Elder Abuse. Questionnaire for Texas

45 th Design Automation Conference

5 August 22, USPS Network Optimization and First Class Mail Large Commercial Accounts Questionnaire Final August 22, 2011

Summary of the State Elder Abuse. Questionnaire for Nebraska

GURLEY PRECISION INSTRUMENTS Sales Representatives List: North America

The State of E-Discovery: An Overview of State & Uniform Rulemaking Efforts

BRAND REPORT FOR THE 6 MONTH PERIOD ENDED JUNE 2018

energy efficiency Building Energy Codes

11 Manipulating the trellis Object

US PS E d u cati o n K it

Summary of the State Elder Abuse. Questionnaire for New York

U.S. Residential High Speed Internet

Year in Review. A Look Back at Commission on Paraoptometric Certification. 243 N. Lindbergh Blvd St. Louis MO

IACMI - The Composites Institute

STATE SEXUAL ASSAULT COALITIONS

1. STATEMENT OF MARKET SERVED

Robin Schneider, Executive Director of Texas Campaign for the Environment August 21, 2008

Providing Solutions B2B 2017

OPT Work Permission for F-1 Students OPT

Transcription:

Introduction to R for Epidemiologists Jenna Krall, PhD Thursday, January 29, 2015

Final project Epidemiological analysis of real data Must include: Summary statistics T-tests or chi-squared tests Regression Figures Can use provided dataset OR you may provide your own If using your own data, it: Must have at least 6 variables (with at least 2 continuous variables) Must have at least 100 observations Must be able to answer a relevant question (e.g. is air pollution associated with mortality?) You must have your data approved by me by March 5

Outline 1. Introduction to base plotting 2. Customizing plots 3. Multiple figures 4. Margins 5. Other plots 6. Saving plots 7. Rules for displaying data

Introduction to base plotting Base R comes with excellent graphing capabilities Scatterplots Histograms Box plots Graphical devices (how your computer represents graphical objects) available in R pdf postscript png jpeg

Introduction to base plotting base R plots: useful for creating quick plots Other graphics packages exist in R Great for "faceting" Great for multiple panels of plots Other graphics packages ggplot2 lattice Written by Hadley Wickham (RStudio) We will cover ggplot2 later in the term Also useful for multiple panels of plots We will not cover in this course

Introduction to base plotting Recall Fisher s iris data data(iris) head(iris) ## Sepal.Length Sepal.Width Petal.Length Petal.Width Species ## 1 5.1 3.5 1.4 0.2 setosa ## 2 4.9 3.0 1.4 0.2 setosa ## 3 4.7 3.2 1.3 0.2 setosa ## 4 4.6 3.1 1.5 0.2 setosa ## 5 5.0 3.6 1.4 0.2 setosa ## 6 5.4 3.9 1.7 0.4 setosa head(iris$sepal.length) ## [1] 5.1 4.9 4.7 4.6 5.0 5.4

Introduction to base plotting To create a scatterplot, plot(x, y) plot(x = iris$sepal.length, y = iris$sepal.width) iris$sepal.width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 iris$sepal.length

Introduction to base plotting Histograms show the data distribution for a variable The data distribution is the frequency of different values hist(iris$sepal.length) Histogram of iris$sepal.length Frequency 0 5 10 15 20 25 30 4 5 6 7 8 iris$sepal.length

Introduction to base plotting Bar plots are used to show the relative frequency of different values of a categorial variable barplot(state.x77[, "Illiteracy"]) 0.0 0.5 1.0 1.5 2.0 2.5 Alabama Georgia Maine Nevada Ohio Texas

Customizing plots What can we change? Add labels Change colors Change plotting symbol Add multiple plots?plot.default?par

Customizing plots Adding labels plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Colors Use the col argument in the plot function to set color plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", col = "red", main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Colors We can also use numbers to specify colors: plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", col = 3, main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Colors We can also use hexadecimal notation (hex) for the combination of red, green, and blue to specify colors: plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", col = "#FF00FF", main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Colors colors() ## [1] "white" "aliceblue" "antiquewhite" ## [4] "antiquewhite1" "antiquewhite2" "antiquewhite3" ## [7] "antiquewhite4" "aquamarine" "aquamarine1" ## [10] "aquamarine2" "aquamarine3" "aquamarine4" ## [13] "azure" "azure1" "azure2" ## [16] "azure3" "azure4" "beige" ## [19] "bisque" "bisque1" "bisque2" ## [22] "bisque3" "bisque4" "black" ## [25] "blanchedalmond" "blue" "blue1" ## [28] "blue2" "blue3" "blue4" ## [31] "blueviolet" "brown" "brown1" ## [34] "brown2" "brown3" "brown4" ## [37] "burlywood" "burlywood1" "burlywood2" ## [40] "burlywood3" "burlywood4" "cadetblue" ## [43] "cadetblue1" "cadetblue2" "cadetblue3" ## [46] "cadetblue4" "chartreuse" "chartreuse1" ## [49] "chartreuse2" "chartreuse3" "chartreuse4" ## [52] "chocolate" "chocolate1" "chocolate2" ## [55] "chocolate3" "chocolate4" "coral" ## [58] "coral1" "coral2" "coral3" ## [61] "coral4" "cornflowerblue" "cornsilk" ## [64] "cornsilk1" "cornsilk2" "cornsilk3" ## [67] "cornsilk4" "cyan" "cyan1"

Colors http://www.stat.columbia.edu/~tzheng/files/rcolor.pdf

Colors plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", main = "Sepal width vs. sepal length for Fisher's Iris data", ylab = "Sepal width", col = "dodgerblue") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Colors We can also give col a vector: col_species <- vector(length = length(iris$species)) col_species[iris$species == "setosa"] <- "dodgerblue" col_species[iris$species == "versicolor"] <- "darkorchid" col_species[iris$species == "virginica"] <- "orangered" plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", main = "Sepal width vs. sepal length for Fisher's Iris data", ylab = "Sepal width", col = col_species)

Colors We can also give col a vector: Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Plotting symbol plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", pch = 2, main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Customizing plots Bar plots are used to show the relative frequency of different values of a categorial variable barplot(state.x77[, "Illiteracy"]) 0.0 0.5 1.0 1.5 2.0 2.5 Alabama Georgia Maine Nevada Ohio Texas

Customizing plots We can use the las argument in the plot function to change the orientation of the axis barplot(state.x77[, "Illiteracy"], xlab = "State", ylab = "Illiteracy rate", main = "Illiteracy rate by state", las = 2) Illiteracy rate by state 2.5 2.0 Illiteracy rate 1.5 1.0 0.5 0.0 Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming State But now the x-axis labels are outside the plot!

Customizing plots Use par to set global plot options head(par()) ## $xlog ## [1] FALSE ## ## $ylog ## [1] FALSE ## ## $adj ## [1] 0.5 ## ## $ann ## [1] TRUE ## ## $ask ## [1] FALSE ## ## $bg ## [1] "transparent"

Margins Change margins using par(mar = c(bottom, left, top, right)) Let s first look at the default We select the mar element from par() mar.default <- par()$mar mar.default ## [1] 5.1 4.1 4.1 2.1 Suppose we want to increase the bottom margin by 2 par(mar = c(7.1, 4.1, 4.1, 2.1)) plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", main = "Sepal width vs. sepal length for Fisher's Iris data")

Margins Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length Plotting area extends here

Customizing plots par(mar = mar.default + c(5, 0, 0, 0)) barplot(state.x77[, "Illiteracy"], xlab = "State", ylab = "Illiteracy rate", main = "Illiteracy rate by state", las = 2) Illiteracy rate by state 2.5 2.0 Illiteracy rate 1.5 1.0 0.5 0.0 Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming State

Customizing plots par(mar = mar.default + c(5, 0, 0, 0)) barplot(state.x77[, "Illiteracy"], xlab = "", ylab = "Illiteracy rate", main = "Illiteracy rate by state", las = 2) mtext("state", side = 1, line = 8) Illiteracy rate by state 2.5 2.0 Illiteracy rate 1.5 1.0 Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming 0.5 0.0 State

Sizing plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Sizing Decrease size of plotting points plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", cex =.1, main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Sizing Increase size of axis labels and axes: plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", cex.lab = 1.5, cex.axis = 2, main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.5 6.5 7.5 Sepal length

Sizing Look under cex for?par plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", cex.main =.7, main = "Sepal width vs. sepal length for Fisher's Iris data") Sepal width vs. sepal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length

Layering plots What if we want to add a horizontal line for the mean sepal width? plot(x = iris$sepal.length, y = iris$sepal.width) iris$sepal.width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 iris$sepal.length

Layering plots What if we want to add a horizontal line for the mean sepal width? plot(x = iris$sepal.length, y = iris$sepal.width) abline(h = mean(iris$sepal.width), col = "red") iris$sepal.width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 iris$sepal.length

Layering plots plot(x = iris$sepal.length, y = iris$sepal.width) abline(h = mean(iris$sepal.width), col = "red") abline(v = mean(iris$sepal.length), col = "blue") iris$sepal.width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 iris$sepal.length

Layering plots Adding a specific point plot(x = iris$sepal.length, y = iris$sepal.width) points(x = mean(iris$sepal.length), y = mean(iris$sepal.width), col = "red", pch = "+", cex = 2) iris$sepal.width 2.0 2.5 3.0 3.5 4.0 + 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 iris$sepal.length

Layering plots We can also add loess line to scatterplot Used to assess direction and magnitude associations or specify breakpoints for regression splines plot(x = iris$sepal.length, y = iris$sepal.width) lowess_iris <- lowess(x = iris$sepal.length, y = iris$sepal.width) lines(x = lowess_iris$x, y = lowess_iris$y, col = "red") iris$sepal.width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 iris$sepal.length

Multiple figures Sepal width vs. sepal length for Fisher's Iris data Sepal width vs. petal length for Fisher's Iris data Sepal width 2.0 2.5 3.0 3.5 4.0 Sepal width 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length 1 2 3 4 5 6 7 Petal length Petal width vs. sepal length for Fisher's Iris data Petal width vs. petal length for Fisher's Iris data Petal width 0.5 1.0 1.5 2.0 2.5 Petal width 0.5 1.0 1.5 2.0 2.5 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Sepal length 1 2 3 4 5 6 7 Petal length

Multiple figures The mfrow option in par allows us to plot multiple figures in one plot Takes the form par(mfrow = c(number of rows, number of columns)) # Change par to allow multiple figures par(mfrow = c(2, 2)) # Create four plots plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", main = "Sepal width vs. sepal length for Fisher's Iris data") plot(x = iris$petal.length, y = iris$sepal.width, xlab = "Petal length", ylab = "Sepal width", main = "Sepal width vs. petal length for Fisher's Iris data") plot(x = iris$sepal.length, y = iris$petal.width, xlab = "Sepal length", ylab = "Petal width", main = "Petal width vs. sepal length for Fisher's Iris data") plot(x = iris$petal.length, y = iris$petal.width, xlab = "Petal length", ylab = "Petal width", main = "Petal width vs. petal length for Fisher's Iris data")

Saving plots Always set your working directory before saving your plots Saving your plot as a png (portable network graphic): Height and width are in pixels (default is 480 by 480) png("iris_scatterplot.png", height = 700, width = 480) plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", main = "Sepal width vs. sepal length for Fisher's Iris data") dev.off() ## pdf ## 2

Saving plots Saving your plot as a pdf (portable document format): Height and width are in inches (default is 7 by 7) pdf("iris_scatterplot.pdf", height = 11, width = 7) plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", main = "Sepal width vs. sepal length for Fisher's Iris data") dev.off() ## pdf ## 2

Saving plots What if you don t run dev.off()? Graphics device does not close You will not have your desired output Can create multiple pages of plots pdf("iris_scatterplot_2.pdf") plot(x = iris$sepal.length, y = iris$sepal.width, xlab = "Sepal length", ylab = "Sepal width", main = "Sepal width vs. sepal length for Fisher's Iris data") plot(x = iris$petal.length, y = iris$petal.width, xlab = "Petal length", ylab = "Petal width", main = "Petal width vs. petal length for Fisher's Iris data") dev.off()

Last week s plot # Load google flu data load("googleflu.rdata") # Sort by date flu <- flu[order(flu$date), ] # Find years for data year <- substr(flu$date, 1, 4) # Subset to 2013 flu <- flu[year == "2013", ] # Plot time series for 2013 plot(flu$date, flu$atlanta, type = "b", xlab = "Date", ylab = "Google flu activity in Atlanta", main = "Google flu activity in Atlanta in 2013") abline(v = as.date("2013-01-15"), col = "red") text(labels = "Class 1", x = as.date("2013-01-20"), y = 1000, col = "red") abline(v = as.date("2013-02-12"), col = "red") text(labels = "Class 5", x = as.date("2013-03-03"), y = 1000, col = "red")

Last week s plot Google flu activity in Atlanta in 2013 Google flu activity in Atlanta 0 2000 4000 6000 8000 10000 Class 1 Class 5 Jan Mar May Jul Sep Nov Jan Date

Rules for displaying data