Evan Girvetz 206-543-5772 209 Winkenwerder Introduction to Graphics in R © R Foundation, from

Slides:



Advertisements
Similar presentations
PowerPoint: Customizing Charts Computer Information Technology Section 5-13 Some text and examples used with permission from:
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 Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Introduction to R Graphics
Graphics in R data analysis and visualization Katia Oleinik Scientific Computing and Visualization Boston University
Excel 2007 Graphs & Charts. TYPES OF CHARTS Column Bar Pie Line.
CSS Link Styling. The Anchor Element: Link text between the opening and closing can be styled using CSS. Some of the properties that can be set are: font-family,
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
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.
6601 Project---Graphics --Enhancing Plots --Fine Control of Graphics Xingyan Bai, Qian Zhang, Ying Li.
COMPREHENSIVE Excel Tutorial 4 Working with Charts and Graphics.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
How To Make Graphs in Microsoft Excel Outline Making Bar Graphs Making Scatter Plots – 1 series Making Scatter Plots – Multiple Series.
Create a chart. Overview: Charts make data visual Lesson 1: Create a basic chart Lesson 2: Customize your chart COURSE CONTENTS Each lesson includes a.
Creating a Bar Chart On a Mac. Frequency Distribution Create a frequency distribution based on the classes Refer to creating a frequency distribution.
Creating a Bar Chart. Create a frequency distribution based on the classes.
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.
Excel Lesson 10 Using Advanced Chart Features Microsoft Office 2010 Advanced Cable / Morrison 1.
WORKING WITH CHARTS. OBJECTIVES  Plan a chart  Create a chart  Move and resize a chart  Change the chart design  Change the chart layout  Format.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
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.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln
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...)
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.
Graphing Parameters Titles X-Axis Title Y-Axis Title Legend Scales Color Gridlines library(help="graphics") Basic Chart Types The R Graphics Package LineHistogram.
An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012.
Plot Using Excel. Select Data Insert →Charts →Scatter.
Excel chapter 4.
Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 1 Module 5 Box, Dot, Histogram, Strip Charts Do See & HearRead Learn.
How to Make a Graph “Bar” Graph Edition MS Step 1. Construct a generic table including your raw data that you want to be graphed.
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.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff
Making Bar Graphs and Scatter Plots in Microsoft Excel 2007.
Creating a Scatter Plot On a Mac. Data in Excel Spreadsheet Insert the variable you want on the x-axis in the left column Insert the variable you want.
Plotting Complex Figures Using R
EXCEL GRAPHING *Basic Graphing Steps* by A.B. -NNHS.
CHART COMPONENTS Lesson 6 – Working With Charts and Graphics, continued.
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.
Graphing A step by step method. Line Graphs  A line graph is a style of chart that is created by connecting a series of data points together with a line.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
Excel 2010 Intro to Charts A chart is a tool you can use in Excel to communicate your data graphically. Charts allow your audience to see the meaning behind.
Introduction to plotting data Fish 552: Lecture 4.
COM: 111 Introduction to Computer Applications Department of Information & Communication Technology Panayiotis Christodoulou.
Charts MOAC Lesson 6.
Review > mean(humidity, na.rm=T) > humidity[!is.na(humidity)] > X x Y Y[[1]][2,3] > zone.fac
Review > plot(x=primates$Bodywt, y=primates$Brainwt, xlim=c(0,300), ylim=c(0,1400), cex=2, pch=21, col="black", bg="salmon", xlab = "Body weight (kg)",
Excel Working with Charts and Graphs
Charts MOAC Lesson 6.
Using R Graphs in R.
Illustrator lecture 2: how to use Adobe Illustrator with vector plots?
Excel Part 4 Working with Charts and Graphics
Two-Dimensional Plots
Excel Part 4 Working with Charts and Graphics
Trevor A. Branch FISH 552 Introduction to R
Microsoft Office Illustrated Introductory, Windows XP Edition
Excel 2010 Intro to Charts A chart is a tool you can use in Excel to communicate your data graphically. Charts allow your audience to see the meaning behind.
Charts MOAC Lesson 6.
How to Create Tables & Graphs in Excel
Plotting Signals in MATLAB
How to Create Tables & Graphs in Excel
Introduction to R plot Instructor: Li, Han
Excel Part 4 Working with Charts and Graphics
Presentation transcript:

Evan Girvetz Winkenwerder Introduction to Graphics in R © R Foundation, from

Introduction to Graphics in R Two main graphics packages –base graphics changes to layout fairly easy –lattice graphics more structured graphics produces, but changes to the basic layout can be more difficult

Base Graphics: plot() plot() generic function for plotting R objects points, lines, etc. > ?plot > plot(x=primates$Bodywt,y=primates$Brainwt) > plot(x=Bodywt,y=Brainwt, data = primates) > plot(Brainwt~Bodywt, data = primates) Get primates data set from class website lectures page (lecture 3) Look at help for plot

xlab(), ylab() > plot(Brainwt~Bodywt, data = primates, + xlab=“Body Weight (kg)”, + ylab=“Brain Weight (g)”) Add labels to the x and y axes

xlim(), ylim() > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400)) Change the x and y axis limits

points and lines The arguments for the commands points and lines can be used for the command plot Plot must be called to start a plot –Then points and lines can add to a plot > ?points

pch : point character

> plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400), pch=20) Change the point character style

cex : Character expansion > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400), pch=20, + cex = 3) Change the point character size Make it 1.5 time larger

Graphing parameters: par() These graphing parameters apply to all graphs called after they are set, until the graphing parameters are changed. This allows you to only have to write the command once to apply to multiple graphs.

Save old graphing parameters > ? par#show help for par > par() #look at par values > oldPar <- par() #save defaults For example: > par(cex = 1.25) > par() > par(oldPar) #restore defaults

Graphing parameters: par() > par(cex=1.25) # character expansion > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400), pch = 20) Some graphing parameters can be changed using par …others must be changed using par

Graphing parameters: par() > par(cex=1.25, pch = 20) # character expansion > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1500)) Note difference between cex in the plot command and cex in par (the par command changes the text size also)

Multiple Point Characters > plot(Brainwt~Bodywt, xlim=c(0,300), ylim=c(0,1500), pch=21:25) Note that this overrides the pch in par

legend() > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1500), pch=21:25) > legend("topright", legend=row.names(primates), + pch=21:25)

Rotating Tick Labels Look at the las argument under the help for par –0: always parallel to the axis [default] –1: always horizontal –2: always perpendicular to the axis –3: always vertical.

Tick Label Alignment > par(las=1) > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400)) las controls the rotation of labels on both axes

Axis Properties > plot(Brainwt~Bodywt, xlim=c(0,300), ylim=c(0,1400), pch=c(1:5), yaxp=c(0,1200,4))

Use of Colors > palette() Note that there are only eight colors in the default palette > colors() But, there are 657 built in colors Download the R Color Chart from the resources page

Use of Colors > pointColors <- c(“red”, “orange”, + “green”, “blue”, “magenta”) > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400), pch = + 21:25, bg = pointColors)

Use of Colors > pointColors <- c(“red”, “orange”, + “green”, “blue”, “magenta”) > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400), + bg = pointColors) > legend("topright", legend=row.names(primates), + pt.bg= pointColors, pch = 20)

Labeling: text() > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400)) > ?text > text(x=primates$Bodywt, + y=primates$Brainwt, + labels=row.names(primates),pos = 4)

Labeling: text() > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400)) > text(primates$Brainwt~primates$Bodywt, + labels=row.names(primates),pos = 4)

Labeling: text() > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1400)) > text(x=primates$Bodywt, + y=primates$Brainwt+c(-0.125,0,0,0.125,0) + *par()$cxy[2], labels= row.names(primates), + pos = 4)

Labeling: identify() > plot(Brainwt~Bodywt, data = primates, + xlim=c(0,300), ylim=c(0,1500)) > identify(primates$Bodywt, primates$Brainwt, + labels=row.names(primates), n=2) Now click near any two points to label them

Putting it All Together > plot(Brainwt~Bodywt, data = primates, xlim=c(0,300), ylim=c(0,1400),xlab="Body Weight (kg)", ylab="Brain Weight (g)",pch = 21:25, bg = pointColors, yaxp=c(0,1200,4)) > legend("topright", legend=row.names(primates), pt.bg= pointColors, pch = 21:25) > text(x=primates$Bodywt, y=primates$Brainwt+c( ,0,0,0.125,0) *par()$cxy[2], labels= row.names(primates), pos = 4)

Adding Additional Plots You can use points or lines to add an additional plot to this graph. > lines(x=c(50,100,150,200), + y=c(250,400,550,750), type ="b", + lwd = 3, lty = 2)

Adding Additional Plots: points You can use points or lines to add an additional plot to this graph. > points(x = c(150,200,250,300), + y = c(100,150,200,250))