FISH 397C Winter 2009 Evan Girvetz More Complex Graphics in R © R Foundation, from

Slides:



Advertisements
Similar presentations
1 SESSION 5 Graphs for data analysis. 2 Objectives To be able to use STATA to produce exploratory and presentation graphs In particular Bar Charts Histograms.
Advertisements

Chapter 3 – Web Design Tables & Page Layout
Introduction to R Graphics
Matrix Manipulation and 2D Plotting
Graphics in R data analysis and visualization Katia Oleinik Scientific Computing and Visualization Boston University
Jeopardy Multiple Choice Fill in the Blank Modified T/F Vocabulary Positioning of data Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400.
STROUD Worked examples and exercises are in the text PROGRAMME F4 GRAPHS.
R graphics  R has several graphics packages  The plotting functions are quick and easy to use  We will cover:  Bar charts – frequency, proportion 
Plotting Systems in R Dr. Jieh-Shan George YEH
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.
Evan Girvetz Winkenwerder Introduction to Graphics in R © R Foundation, from
Visualization and Data Mining. 2 Outline  Graphical excellence and lie factor  Representing data in 1,2, and 3-D  Representing data in 4+ dimensions.
Graphing With Excel Presented by Frank H. Osborne, Ph. D. © 2008 ID 2950 Technology and the Young Child.
First-Year Engineering Program 1 Autumn 2009 Graphing with Microsoft Excel Lecture 11 Engineering H191 Engineering Fundamentals and Laboratory.
Introduction to R A. Di Bucchianico. Introduction to R2 Types of statistical software command-line software –requires knowledge of syntax of commands.
1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 – Graphs and Charts: Delivering a Message Robert Grauer and Maryann Barber Exploring.
FISH 397C Winter 2009 Evan Girvetz Basic Statistical Analyses and Contributed Packages in R © R Foundation, from
MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.
© Copyright 2000, Julia Hartman 1 Scatterplot Output: Editing the Graph You can edit the output to display the entire variable label. Click inside the.
Data Tutorial Tutorial on Types of Graphs Used for Data Analysis, Along with How to Enter Them in MS Excel Carryn Bellomo University of Nevada, Las Vegas.
EViews. Agenda Introduction EViews files and data Examining the data Estimating equations.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Assumption of Homoscedasticity
Introduction to SPSS Short Courses Last created (Feb, 2008) Kentaka Aruga.
How To Make Graphs in Microsoft Excel Outline Making Bar Graphs Making Scatter Plots – 1 series Making Scatter Plots – Multiple Series.
1 Create a Questionnaire Learning Objective  To learn how to use the features in Microsoft Publisher to create a questionnaire.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week5: Charts/Plots in R.
An Introduction to R graphics Elizabeth Garrett-Mayer Slides borrowed from Cody Chiuzan & Delia Voronca March 24, 2014.
Fundamental Graphics in R Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University.
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...)
Hands-on Introduction to R. Outline R : A powerful Platform for Statistical Analysis Why bother learning R ? Data, data, data, I cannot make bricks without.
Using SPSS for Windows Part II Jie Chen Ph.D. Phone: /6/20151.
Field Trip # 21 Creating PDFs with Java By Keith Lynn.
A Picture Is Worth A Thousand Words. DAY 7: EXCEL CHAPTER 4 Tazin Afrin September 10,
An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012.
Introduction to SPSS. Object of the class About the windows in SPSS The basics of managing data files The basic analysis in SPSS.
Advanced Stata Workshop FHSS Research Support Center.
Learning R hands on. Organization of Folders: Class Data folder has datasets (end in.csv or.rda) Rcode has the scripts of R commands that can cut and.
Graphical Analysis in Excel EGN 1006 – Introduction to Engineering.
Who Wants to be a Millionaire? LIFELINES 1.50/50 2.Poll the audience 3.Ask Another Student.
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.
Plotting Complex Figures Using R
Mr. Magdi Morsi Statistician Department of Research and Studies, MOH
1. Tables, Charts, and Graphs Microsoft Word & Excel 2003.
Data Science and Big Data Analytics Chap 3: Data Analytics Using R
Conduct Simple Correlations Section 7. Correlation –A Pearson correlation analyzes relationships between parametric, linear (interval or ratio which are.
Introduction to Graphics in R 3/12/2014. First, let’s get some data Load the Duncan dataset It’s in the car package. Remember how to get it? – library(car)
STROUD Worked examples and exercises are in the text 1 STROUD Worked examples and exercises are in the text Programme F4: Graphs PROGRAMME F4 GRAPHS.
Chapter 4 Minitab Recipe Cards. Correlation coefficients Enter the data from Example 4.1 in columns C1 and C2 of the worksheet.
Presenting Multivariate Data Harry R. Erwin, PhD School of Computing and Technology University of Sunderland.
Introduction to plotting data Fish 552: Lecture 4.
Review > head(tripData) > table(speciesData$SpeciesCode) > grep("a", c("aa","ab","bb")) > c(2,3,8) %in% c(1,2,3,5,7,9) > bocTrip
Descriptive Statistics using R. Summary Commands An essential starting point with any set of data is to get an overview of what you are dealing with You.
More Complex Graphics in R Fish 552: Lecture 8. Recommended Readings How to Display Data Badly (Howard Wainer, 1984) –
IENG-385 Statistical Methods for Engineers SPSS (Statistical package for social science) LAB # 1 (An Introduction to SPSS)
Review > mean(humidity, na.rm=T) > humidity[!is.na(humidity)] > X x Y Y[[1]][2,3] > zone.fac
Using R Graphs in R.
Chemistry Monday, 9/21.
By Dr. Madhukar H. Dalvi Nagindas Khandwala college
DEPARTMENT OF COMPUTER SCIENCE
Trevor A. Branch FISH 552 Introduction to R
Lecture 5 advanced multipanel plots
Introduction to Exploratory Descriptive Data Analysis in S-Plus II
Stat 251 (2009, Summer) Lab 2 TA: Yu, Chi Wai.
R Course 5th lecture.
R Course 5th lecture.
Simulate Multiple Dice
Presentation transcript:

FISH 397C Winter 2009 Evan Girvetz More Complex Graphics in R © R Foundation, from

Hands-on Exercise Read in the possum.csv dataset to a data frame called possum –Note that the first column of data should be the row names –There are column headings for the other columns

possum Data Frame Look at data frame > head(possum) case site Pop sex age hdlngth skullw totlngth taill footlgth earconch eye chest belly C3 1 1 Vic m C5 2 1 Vic f C Vic f C Vic f C Vic f C Vic f

Plotting Multiple Columns Plot three columns at one time > possum[,c(6,8,9)] > plot(possum[,c(6,8,9)])

Multiple Graphs on One Layout Look up mfrow and mfcol under par > ?par mfrow : multiple plots on one graph filled by row mfcol : same but by column

Multiple Graphs on One Layout The mfrow (or mfcol ) command needs to be given to par prior to making the plots > par(mfrow=c(2,3)) Now draw plots in the order you want them displayed > plot(possum$hdlngth~possum$totlngth) > plot(possum$hdlngth~possum$taill) > plot(possum$totlngth~possum$taill) > hist(possum$hdlngth) > hist(possum$totlngth) > hist(possum$taill)

Hands-on Exercise Create a plot with three graphs across –1: head length vs. total length (x vs y) –2: Histogram of total length –3: Histogram of head length Add more informative labels and titles –“Head Length” –“Tail Length” –“Total Length”

Making customized layouts layout(mat, widths = rep(1, ncol(mat)), heights = rep(1, nrow(mat)), respect = FALSE) mat a matrix object specifying the location of the next N figures on the output device. Each value in the matrix must be 0 or a positive integer. If N is the largest positive integer in the matrix, then the integers {1,...,N-1} must also appear at least once in the matrix. widths a vector of values for the widths of columns on the device. Relative widths are specified with numeric values. Absolute widths (in centimetres) are specified with the lcm() function (see examples). heights a vector of values for the heights of rows on the device. Relative and absolute heights can be specified, see widths above.

> mat <- matrix(c(1,1,3,2), 2, 2, byrow = TRUE) > mat > lay1 <- layout(mat=mat) > layout.show(lay1) layout : custom layouts

> mat <- matrix(c(1,1,0,2), 2, 2, byrow = TRUE) > lay1 <- layout(mat=mat) > layout.show(lay1)

layout : custom layouts > mat <- matrix(c(1,1,1,1,2,3), 3, 2, byrow = TRUE) > lay1 <- layout(mat=mat) > layout.show(lay1)

layout : custom layouts > plot(possum$hdlngth~possum$totlngth) > hist(possum$hdlngth) > hist(possum$totlngth)

layout : custom layouts > mat <- matrix(c(2,0,1,3),2,2,byrow=TRUE) > lay1 <- layout(mat, c(3,1), c(1,3), TRUE) > layout.show(lay1)

Simple Analyses: hist > ?hist # look at the help for hist > hdlngth.hist <- hist(possum$hdlngth) > totlngth.hist <- hist(possum$totlngth) > totLngth.hist ## look at totLngth.hist > plot(hdlngth.hist)

barplot > ?barplot > barplot(hdlngth.hist$counts) > par(mfrow= c(1,2)) > barplot(hdlngth.hist$counts) > barplot(hdlngth.hist$counts, horiz = T)

barplot > par(mfrow= c(1,2)) > barplot(hdlngth.hist$counts) > barplot(hdlngth.hist$counts, horiz = T)

Hands-on Exercise Add these plots in this order –Scatter plot –totlngth histogram –hdlnth histogram

Changing the Margin Sizes > ?par # look at help for mar > par(mar = c(par(mar=c(3,3,1,1))) > par(mar = c(par(mar=c(0,3,1,1))) > par(mar = c(par(mar=c(3,0,1,1)))

Hands on Exercise Redo your layout using these margin sizes for the three plots in this order > par(mar = c(par(mar=c(3,3,1,1))) > par(mar = c(par(mar=c(0,3,1,1))) > par(mar = c(par(mar=c(3,0,1,1)))

Linear Regression : lm Use linear modeling: > totHd.lm <- lm(hdlngth ~ totlngth, data = possum) > summary(totHd.lm) > totHd.lm$coefficients > totHd.lm$residuals

Linear Regression : lm Linear regression diagnostic graphs > plot(totHd.lm)

Adding lines to plots: abline > ?abline # look at the help for abline > par(mfrow = c(1,1)) > plot(possum$hdlngth~possum$totlngth) > abline(totHd.lm, lwd = 2, lty = 2)

Hands-on Exercise Now add a trend line to the scatter plot in your layout

Text Expressions > coefA <- totHd.lm$coeficients[1,1] > coefB <-totHd.lm$coeficients[2,1] > text(x=80,y=101, expression(tailLen == * (headLen) ))

Hands On Exercise Add this equation to the scatter plot in your layout Write the layout to a.png file and view in a graphics viewer

Lattice Graphics > library(lattice) > attach(possum) The lattice library must be loaded to use the lattice graphical functions

> hist(totlngth) # base graphics

> histogram(totlngth) # lattice graphics

> histogram(~totlngth | sex)

> histogram(~totlngth | sex*Pop)

> densityplot(~totlngth | sex*Pop)

> plot(taill~totlngth)# Base Graphics

> xyplot(taill~totlngth)# Lattice graphics

> xyplot(taill~totlngth | sex) # Lattice graphics

Lattice Graphics dotplot(factor ~ numeric,..) # 1-dim. Display stripplot(factor ~ numeric,..) # 1-dim. Display barchart(character ~ numeric,..) histogram( ~ numeric,..) densityplot( ~ numeric,..) # Density plot bwplot(factor ~ numeric,..) # Box and whisker plot qqmath(factor ~ numeric,..) # normal probability plots splom( ~ dataframe,..) # Scatterplot matrix parallel( ~ dataframe,..) # Parallel coordinate plots cloud(numeric ~ numeric * numeric,...) # 3D surface wireframe(numeric ~ numeric * numeric,...) # 3D scatterplot

Detach the possum data set > detach(possum)

Other Graphics and Expressions > symbols(0,0,circles=0.95,bg="gray", xlim=c(-1,2.25),ylim=c(1,1),inches=FALSE)

Other Graphics and Expressions > xVals <- c(1,3,4) > yVals <- c(4,2,3) > circleSizes <- c(.1,.2,.3) > symbols(xVals, yVals,circles= circleSizes, bg="gray”, xlim = c(0,5), ylim = c(0,5),inches=FALSE)

Other Graphics and Expressions > symbols(xVals, yVals,circles= circleSizes, bg=c(“red”, “green”, “blue”), xlim = c(0,5), ylim = c(0,5),inches=FALSE)

Other Graphics and Expressions > symbols(0,0,circles=0.95,bg="gray", xlim=c(-1,2.25),ylim=c(1,1),inches=FALSE) > text(1.75,0,expression("Area" ==pi*phantom("'") *italic(r)^2))

Other Graphics and Expressions > symbols(0,0,circles=0.95,bg="gray", xlim=c(-1,2.25),ylim=c(1,1),inches=FALSE) > text(1.75,0,expression("Area" ==pi*phantom("'") *italic(r)^2)) > arrows(0,0,-.95,0,length=.1,code=3)

Other Graphics and Expressions > symbols(0,0,circles=0.95,bg="gray", xlim=c(-1,2.25),ylim=c(1,1),inches=FALSE) > text(1.75,0,expression("Area" ==pi*phantom("'") *italic(r)^2)) > arrows(0,0,-.95,0,length=.1,code=3) > text(-0.45,-strheight("R"), expression(italic(r) == 0.95))

Finding Locations: locator() > location <- locator(n=1) Now click on the graphic where you’d like the label > text(location$x,location$y, expression("Area"==pi*phantom("'")*italic(r)^2))

Drawing on graphics: locator() > locator(n=2, type = "l") Now click on the two points where you’d like to draw a line > locator(n=4, type = "p") Now click on the four locations where you’d like to place points