Introduction to R plot Instructor: Li, Han

Slides:



Advertisements
Similar presentations
Excel Spread Sheet- plug in dates along top row skipping column A.
Advertisements

Prepared by : Mahmoud A. Abu Hashish  Used to organize and analyze information  Made up of columns and rows  Columns and rows intersect.
Introduction to R Graphics
+ Chapter 1 Section 2 By Abby Chopoorian and Morgan Smith.
FIRST COURSE Excel Tutorial 4 Working with Charts and Graphics.
Customizing Graphs Base graphics options. plot() The workhorse plotting function plot(x) plots values of x in sequence or a barplot plot(x, y) produces.
Microsoft Excel 2010 Chapter 7
Evan Girvetz Winkenwerder Introduction to Graphics in R © R Foundation, from
Graph these numbers. 1. Highlight the rows you need for your axes 2. Click on the chart wizard icon.
COMPREHENSIVE Excel Tutorial 4 Working with Charts and Graphics.
EXCEL PART 2. Chart Elements Chart Title Plot Area Data Marker X AxesCategory Name Y axes.
Chapter 9 Creating Graphs in Illustrator. Objectives Create a graph Edit a graph using the Graph Data window Use the Group Selection tool Use the Graph.
CHAPTER 1: Picturing Distributions with Graphs
By: Jose Mahendra Aji. First you must click the start button on the bottom left of your screen. Type in “Microsoft office excel” in the search section.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week5: Charts/Plots in R.
Instructor: Professor Cora Martinez, PhD Department of Civil and Environmental Engineering Florida International University.
Spreadsheets and Marks © Nipawin School Division 2003.
CMPF 112 : COMPUTING SKILLS FOR ENGINEERS MICROSOFT OFFICE SUITE: EXCEL.
An Introduction to R graphics Elizabeth Garrett-Mayer Slides borrowed from Cody Chiuzan & Delia Voronca March 24, 2014.
AN INTRODUCTION TO GRAPHICS IN R. Today Overview Overview –Gallery of R Graph examples High-Level Plotting Functions High-Level Plotting Functions Low-Level.
R Graphics Lori Shepherd-Kirchgraber May 22, 2012.
R-Graphics Day 2 Stephen Opiyo. Basic Graphs One of the main reasons data analysts turn to R is for its strong graphic capabilities. R generates publication-ready.
Creating Graphs in R Graphing techniques Sharon style! (I am not sure if this is a good or bad thing but this is what I do...)
Exploring Excel 2003 Revised - Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 – Graphs and Charts: Delivering a.
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.
Exploring Microsoft Office C51BR1 Business Reporting By David Kilgour
Microsoft Publisher 2010 Chapter 4 Creating a Custom Publication from Scratch.
An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012.
Microsoft ® Office Excel 2007 Working with Charts.
Tables and Graphs How to import your Webstats into Excel and make pretty charts and tables. POL 242 June 14, 2006.
PRINTING & PAGE BREAKS 1 Nolan Tomboulian Tomboulian.Wikispaces.com.
1. Chapter 15 Creating Charts 3 Charting Data in Word A chart or graph presents data visually. A chart depicts numeric data in a graphical format. If.
Return to Outline Copyright © 2011 by Maribeth H. Price 3-1 Labeling and annotation.
Creating Graphs in Illustrator
Exploring Microsoft Excel 2002 Chapter 4 Chapter 4 Graphs and Charts: Delivering a Message By Robert T. Grauer Maryann Barber Exploring Microsoft Excel.
Exploring Microsoft Excel 97 Chapter 4 Graphs and Charts: Delivering a Message Office graphic copyright by Microsoft Corp.
R-Graphics Stephen Opiyo. Basic Graphs One of the main reasons data analysts turn to R is for its strong graphic capabilities. R generates publication-ready.
CRSD Technology Training Tony Judice. Quick Access Toolbar – can be modifiedSave as… allows you to save the file to a different location and also as an.
R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff
Plotting Complex Figures Using R
Chapter 15: Spreadsheet and Worksheet Basics Lesson 96: Worksheets with Charts © 2010, 2006 South-Western, Cengage Learning.
Introduction to Drafting and Design In order to begin our drawing we have to set the drawing limits or the paper size.
1 HTML Frames
S-PLUS Lecture 6 Jaeyong Lee. Graphical Parameters type = “c”: c =p (default), l, b,s,o,h,n. pch=“+” : character or numbers 1 – 18 lty=1 : numbers lwd=2.
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.
Introduction to plotting data Fish 552: Lecture 4.
R 그래픽스 5 : R을 이용한 도형그리기 (1) 원(circle) 그리기
1 Berger Jean-Baptiste
Review > mean(humidity, na.rm=T) > humidity[!is.na(humidity)] > X x Y Y[[1]][2,3] > zone.fac
From digital to craft: How to make a data matrix with SNS data There are many applications that allow its users to visualize different networks directly.
This is only an introduction!!
CSS Layouts: Positioning and Navbars
How to add a network printer in Windows 7
How to make a visual aid in MS Power Point
Excel Part 4 Working with Charts and Graphics
Average Rebound Height
Excel Part 4 Working with Charts and Graphics
Trevor A. Branch FISH 552 Introduction to R
Average Rebound Height
Exploring Microsoft Excel
Homework: Frequency & Histogram worksheet
Title goes here (72-108pt) RESULTS RESULTS RESULTS RESULTS RESULTS
Using the QGIS Layout Manager to create
Practice Activity – Part 1
Simple plots using R Instructor: Li, Han
Chapter 8 Using Document Collaboration and Integration Tools
Excel Part 4 Working with Charts and Graphics
Graphical Descriptions of Data
R in Action Obtaining and installing R and RStudio
Presentation transcript:

Introduction to R plot Instructor: Li, Han chapter 3 Introduction to R plot Instructor: Li, Han

Contents creat/save a plot symbol, line and color title and range text and mtext add lines legend combine multiple plots

Why plot? When we analyze data, the first thing is to look at the data, and check its patterns, for example, the range of the data symmetric or left, right skew? the most common values any outlier?

data example mpg cyl am Mazda RX4 21.0 6 1 Mazda RX4 Wag Toyota Corolla 33.9 4 Merc 280C 17.8 Ford Pantera L 15.8 8 Ferrari Dino 19.7 ...

Example 1 attach(mtcars) plot(wt, mpg, col=1) abline(lm(mpg~wt), col=2) title("Regression of MPG on Weight") detach(mtcars)

Creat a plot To creat a plot, there are two methods: directly plot, then save it under the graphics window, by clicking file -> save as -> choose the graph type start a device, then plot, after that close the device

Example 2 jpeg("mygraph.jpeg") attach(mtcars) plot(wt, mpg, col=1) abline(lm(mpg~wt), col=2) title("Regression of MPG on Weight") detach(mtcars) dev.off()

Open multiple graph windows In R, it will open one graph window by default. To open multiple graph windows, use #make a new plot dev.new() #make another new plot

A simple plot Example 3 dose <- c(20, 30, 40, 45, 60) drugA <- c(16, 20, 27, 40, 60) drugB <- c(15, 18, 25, 31, 40) plot(dose, drugA, type="b")

Graph parameters In R, we could set the parameters of par() to make a plot, for instance, the type and the color of a line, the size of the graph. To save the original graph parameters, use opar <- par(no.readonly=TRUE). After finishing the plot, reset the paramters to their original values by using par(opar).

Example 4 opar <- par(no Example 4 opar <- par(no.readonly=TRUE) par(lty=2, pch=17) plot(dose, drugA, type="b") par(opar)

Symbol and line The parameters for setting the type and magnitude of symbol and lines are pch=? the type of a symbol cex=? the magnitude of a symbol lty=? the type of a line lwd=? the width of a line

Example 5 plot(dose, drugA, type="b", lty=3, lwd=3, pch=15, cex=2)

col To specify the color for plotting, set col=? We use set col=”red”, col=”black”, col=”blue” or col=1, col=2,.... Other color parameters: col.axis, col.lab, col.main, col.sub

Size of a graph pin=c(a, b): size of a graph in inch with width=a, height=b mai=c(a, b, d, f): the marginal size of a graph in inch, with bottom=a, left=b, up=d, right=f

Example 6 opar <- par(no Example 6 opar <- par(no.readonly=TRUE) par(pin=c(2,3)) par(lwd=2, cex=1.5) par(cex.axis=0.75, font.axis=3) plot(dose, drugA, type="b", pch=19, lty=2, col="red") dev.new() plot(dose, drugB, type="b", pch=23, lty=6, col="blue", bg="green") par(opar)

title and range of plotting Example 7 plot(dose, drugA, type="b", col="red", lty=2, pch=2, lwd=2, main="Clinical Trials for Drug A", sub="This is hypothetical data", xlab="Dosage", ylab="Drug Response", xlim=c(0, 60), ylim=c(0, 70))

Add lines To add lines to the graph, there are several methods: abline(h=yvalues, v=xvalues, col=?, lty=?) lines(x,y, col=?, lty=?)

Example 8 plot(dose, drugA, type="b", pch=19, lty=1, col="red") abline(h=40,v=c(35, 50), col=2) lines(dose, drugB, lty=2)

legend When we have multiple lines in a graph, we need to use legend to tell their specific information to distinguish them. legend(location, title, legend, lty, col,...)

Example 9 plot(dose, drugA, type="b", lty=1, col="red", ylab="Drug") lines(dose, drugB, lty=2) legend("topleft", title="Drug type", legend=c("Drug A", "Drug B"), lty=c(1,2), col=c("red",1))

text() To add text in specific location, use text(location, “text to write”, pos,...) mtext(“text to write”, side, line,...)

Example 10 attach(mtcars) plot(wt,mpg) text(wt,mpg, row Example 10 attach(mtcars) plot(wt,mpg) text(wt,mpg, row.names(mtcars), cex=0.6, pos=4, col="red") mtext("Cars", side=4, las=2, line=0.5) detach(mtcars)

Combine multiple plots If we would like to show multiple plots together, we need to specify the number of plots and how to place them. # We will draw m*n plots, row by row par(mfrow=c(m,n)) # We will draw m*n plots, column by column par(mfcol=c(m,n))

Example 10 par(mfrow=c(2,2)) plot(dose, drugA, type="b", lty=1, col="red", ylab="Drug") #plot 1 plot(dose, drugA, type="b", lty=1, col="red", ylab="Drug") #plot 2 hist(drugA) #plot 3 hist(drugB) #plot 4

layout() Example 11 layout(matrix(c(1,1,2,3), 2,2, byrow=T), widths=c(2,2), heights=c(3,3)) plot(dose, drugA) plot(dose, drugB) plot(drugA, drugB)

Try the examples and enjoy plotting!