5/2/2015330 Lecture 41 STATS 330: Lecture 4. 5/2/2015330 Lecture 42 Housekeeping My contact details…. Plus much else on course web page www.stat.auckland.ac.nz/~lee/330/

Slides:



Advertisements
Similar presentations
Summary Statistics/Simple Graphs in SAS/EXCEL/JMP.
Advertisements

Chapter 3 – Web Design Tables & Page Layout
Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation.
Microsoft ® Office Excel ® 2003 Training How to create a chart.
Introduction to Formatting VistaPHw Charts Brought to you by: The Vista Partnership February 2007.
Working with Tables for Page Design – Lesson 41 Working with Tables for Page Design Lesson 4.
STROUD Worked examples and exercises are in the text PROGRAMME F4 GRAPHS.
Microsoft Excel 2003 To start Excel, click the start button. A slightly different procedure might be required for computers on a network. If you need assistance,
1 CA202 Spreadsheet Application Combining Data from Multiple Sources Lecture # 6.
Loading Excel Double click the Excel icon on the desktop (if you have this) OR Click on Start All Programs Microsoft Office Microsoft Office Excel 2003.
Click here to enter. Click a menu option to view more details Starters Main Courses Desserts Click on the coffee cup to return when Navigating For Vocabulary.
Elizabeth North UMCES Horn Point Laboratory Using Surfer 8.0 UMCES HPL May 30, 2006.
FIRST COURSE Excel Tutorial 4 Working with Charts and Graphics.
SUNY Morrisville-Norwich Campus- Week 7 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Graphing With Excel Presented by Frank H. Osborne, Ph. D. © 2008 ID 2950 Technology and the Young Child.
1 CA202 Spreadsheet Application Creating Dynamic Lists with PivotTables Lecture # 9.
Chapter 7 Data Management. Agenda Database concept Import data Input and edit data Sort data Function Filter data Create range name Calculate subtotal.
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 11 1 Microsoft Office Excel 2003 Tutorial 11 – Importing Data Into Excel.
Overview Importing text files Creating Forms Creating Reports.
7/3/ Lecture 21 STATS 330: Lecture 2. 7/3/ Lecture 22 Housekeeping matters STATS 762 –An extra test (details to be provided). An extra assignment.
Introduction to Excel 2007 Part 1: Basics and Descriptive Statistics Psych 209.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Microsoft Office © Copyright William Rowan Objective By the end of this you will have being given a brief introduction to: Microsoft Word Microsoft.
NU Data Excel Orientation Graphing of Screening Data and Basic Graphing Functions.
Python plotting for lab folk Only the stuff you need to know to make publishable figures of your data. For all else: ask Sourish.
Graphing with Excel: Graphing Made Easy Mac 2008 Version.
Access Ch 5 Review.
Instructor: Professor Cora Martinez, PhD Department of Civil and Environmental Engineering Florida International University.
Integrating Microsoft Project with Other Programs
 Insert a picture from a file  Move and delete images  Use the Picture Tools tab  Add styles, effects, and captions to images  Resize photos  Use.
Excel 2007 Part (2) Dr. Susan Al Naqshbandi
Importing your Own Data To display in GIS Lab 4a: (Table Join) Mapping By State, County, or Nation.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
European Computer Driving Licence Syllabus version 5.0 Module 4 – Spreadsheets Chapter 22 – Functions Pass ECDL5 for Office 2007 Module 4 Spreadsheets.
Lesson No:9 MS-Word Tools, Mail Merge and working with Tables CHBT-01 Basic Micro process & Computer Operation.
4/22/2017 5:36 PM EViews Training Creating Workfiles.
Micro sites Basic training guide. Welcome to your Micro site. Here you can create your own personal page within the Countrywide website. When you first.
Teacher’s Assessment Assistant Worksheet Builder Starting the Program
Creating Charts for the Agency Budget Creating Budget Charts, Slide 1Copyright © 2004, Jim Schwab, University of Texas at Austin.
An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012.
Enjoy-a-Ball Franchisee Basic training guide. Welcome to your Enjoy-a-Ball Micro site. Here you can create your own personal page within the Enjoy-a-Ball.
Office Management Tools II Ms Saima Gul. Office Management Tools II Ms Saima Gul.
© 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Creating Charts Lecture 19.
Graphing with Excel The Basics. Working With Excel The spreadsheet program Excel is useful for constructing data tables and graphs The results can easily.
Tables Sacramento City College Engineering Design Technology.
A Simple Guide to Using SPSS ( Statistical Package for the Social Sciences) for Windows.
DAY 6: MICROSOFT EXCEL – CHAPTER 3 Sravanthi Lakkimsetty September 2, 2015.
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.
1. 2 Word Processing Word Processing is writing words and sentences on the computer. It is easy to change or move text in a word document. People use.
Introduction to Spreadsheets Part 1 The ‘Quick’ and ‘Easy’ guide to using Microsoft Excel.
MySQL Importing and creating a database. CSV (Comma Separated Values) file CSV = Comma Separated Values – they are simple text files containing data which.
Integrate, check and share documents Module 3.3. Integrate, check and share documents Module 3.3.
Export/Import of TurningPoint Session Files II: Exporting.tpz (Session) Files to csv Files Ready for Import into D2L Tanya Joosten and Gerald Bergtrom.
Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation.
Unit 3: Text, Fields & Tables DT2510: Advanced CAD Methods.
Data & Graphing vectors data frames importing data contingency tables barplots 18 September 2014 Sherubtse Training.
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.
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 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.
Tables MOAC LESSON 6. Table  Arrangement of data made up of horizontal rows and vertical columns  Used to organize information.
EMPA Statistical Analysis
Multi-Axis Tabular Loads in ANSYS Workbench
Creates the file on disk and opens it for writing
Using R Graphs in R.
Select Your Meeting Export Your Contacts From Outlook How to create a csv contact file from Outlook to import into Select Your Meeting
Performing Mail Merges
Computer Fundamentals
Creates the file on disk and opens it for writing
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.
Chapter 5 – Symbols, Tables, and Fields
Presentation transcript:

5/2/ Lecture 41 STATS 330: Lecture 4

5/2/ Lecture 42 Housekeeping My contact details…. Plus much else on course web page Or via Cecil

5/2/ Lecture 43

5/2/ Lecture 44 Today’s lecture: R for graphics Aim of the lecture: To show you how to use R to produce the plots shown in the last few lectures

5/2/ Lecture 45 Getting data into R  In 330, as in many cases, data comes in 2 main forms As a text file As an Excel spreadsheet  Need to convert from these formats to R  Data in R is organized in data frames Row by column arrangement of data (as in Excel) Variables are columns Rows are cases (individuals)

5/2/ Lecture 46 Text files to R  Suppose we have the data in the form of a text file  Edit the text file (use Notepad or similar) so that The first row consists of the variable names Each row of data (i.e. data on a complete case) corresponds to one line of the file  Suppose data fields are separated by spaces and/or tabs  Then, to create a data frame containing the data, we use the R function read.table

5/2/ Lecture 47 Example: the cherry tree data Suppose we have a text file called cherry.txt (probably created using Notepad or maybe Word, but saved as a text file) First line: variable names Data for each tree on a separate line, separated by “white space” (spaces or tabs)

5/2/ Lecture 48 Creating the data frame In R, type cherry.df = read.table(file.choose(), header=TRUE) and press the return key This brings up the dialog to select the file cherry.txt containing the data. Click here to select file Click here to load data

5/2/ Lecture 49 Check all is OK!

5/2/ Lecture 410 Getting data from a spreadsheet (1) Create the spreadsheet in Excel Save it as Comma Delimited Text (CSV) This is a text file with all cells separated by commas File is called cherry.csv

5/2/ Lecture 411 Getting data from a spreadsheet (2) In R, type cherry.df = read.table(file.choose(), header=TRUE, sep=“,”) and proceed as before

Getting data from the R330 package  The package R330 contains several data sets used in the course, including the cherry tree data  To access the data frame: Install the R330 package (see Appendix A.10 of the coursebook) In R, type > library(R330) > data(cherry.df) 5/2/ Lecture 412

5/2/ Lecture 413 Data frames and variables  Suppose we have read in data and made a data frame  At this point R doesn’t know about the variables in the data frame, so we can’t use e.g. the variable diameter in R commands  We need to say attach(cherry.df) to make the variables in cherry.df visible to R.  Alternatively, say cherry.df$diameter (better)

5/2/ Lecture 414 Scatterplots In R, there are 2 distinct sets of functions for graphics, one for ordinary graphics, one for trellis. Eg for scatterplots, we use either plot (ordinary R) or xyplot (Trellis) In the next few slides, we discuss plot.

5/2/ Lecture 415 Simple plotting plot(cherry.df$height, cherry.df$volume, xlab=“Height (feet)”, ylab=“Volume (cubic feet)”, main = “Volume versus height for 31 black cherry trees”) i.e. label axes (give units if possible), give a title

5/2/ Lecture 416

Alternative form of plot plot(volume ~ height, xlab=“Height (feet)”, ylab=“Volume (cubic feet)”, main = “Volume versus height for 31 black cherry trees”, data = cherry.df) Don’t need use the $ notation with this form, note reversal of x,y 5/2/ Lecture 417

5/2/ Lecture 418 Colours, points, etc par(bg="darkblue") plot(cherry.df$height, cherry.df$volume, xlab="Height (feet)", ylab="Volume (cubic feet)", main = "Volume versus height for 31 black cherry trees", pch=19,fg="white", col.axis=“lightblue",col.main="white", col.lab=“white",col="white",cex=1.3) Type ?par for more info

5/2/ Lecture 419

5/2/ Lecture 420 Lines  Suppose we want to join up the rats on the rats plot. (see data next slide)  We could try plot(rats.df$day, rats.df$growth, type=“l”) but this won’t work  Points are plotted in order they appear in the data frame and each point is joined to the next

5/2/ Lecture 421 Rats: the data > rats.df growth group rat change day More data

5/2/ Lecture 422 Don’t want this!

5/2/ Lecture 423 Solution Various solutions, but one is to plot each line separately, using subsetting plot(day,growth,type="n") lines (day[rat==1],growth[rat==1]) lines (day[rat==2],growth[rat==2]) and so on …. (boring!), or (better) for(j in 1:16){ lines (day[rat==j],growth[rat==j]) } Draw axes, labels only

5/2/ Lecture 424 Indicating groups Want to plot the litters with different colours, add a legend: Rats 1-8 are litter 1, 9-12 litter 2, litter 3 plot(day,growth,type="n") for(j in 1:8)lines(day[rat==j], growth[rat==j],col="white") # litter 1 for(j in 9:12)lines (day[rat==j], growth[rat==j],col="yellow") # litter 2 for(j in 13:16)lines (day[rat==j], growth[rat==j],col="purple") # litter 3 Set colour of line

5/2/ Lecture 425 legend legend(13,380, legend = c(“Litter 1”, “Litter 2”, “Litter 3”), col = c("white","yellow","purple"), lwd = c(2,2,2), horiz = TRUE, cex = 0.7) (Type ?legend for a full explanation of these parameters)

5/2/ Lecture 426

Points and text x=1:25 y=1:25 plot(x,y, type="n") points(x,y,pch=1:25, col="red", cex=1.2) 5/2/ Lecture 4

5/2/ Lecture 4

Points and text (3) x=1:26 y=1:26 plot(x,y, type="n") text(x,y, letters, col="blue", cex=1.2) 5/2/ Lecture 4

5/2/ Lecture 4

Use of pos 5/2/ Lecture 431 x = 1:10 y = 1:10 plot(x,y) position = rep(c(2,4), 5) mytext = rep(c(“Left",“Right"), 5) text(x,y,mytext, pos=position)

5/2/ Lecture 432

5/2/ Lecture 433 Trellis  Must load trellis library first library(lattice)  General form of trellis plots xyplot(y~x|W*Z, data=some.df)  Don’t need to use the $ form,, trellis functions can pick out the variables, given the data frame

5/2/ Lecture 434 Main trellis functions  dotplotfor dotplots, use when X is categorical, Y is continuous  bwplotfor boxplots, use when X is categorical, Y is continuous  xyplotfor scatter plots, use when both x and y are continuous  equal.countuse to turn continuous conditioning variable into groups

Changing background colour To change trellis background to white trellis.par.set(background = list(col="white")) To change plotting symbols trellis.par.set(plot.symbol = list(pch=16, col="red", cex=1)) 5/2/ Lecture 435

5/2/ Lecture 436 Equal.count xyplot(volume~height|diameter, data=cherry.df)

5/2/ Lecture 437 Equal.count (2) diam.gp<-equal.count(diameter,number=4,overlap=0) xyplot(volume~height|diam.gp, data=cherry.df)

Changing plotting symbols To change plotting symbols trellis.par.set(plot.symbol = list(pch=16, col="red", cex=1)) 5/2/ Lecture 438

5/2/ Lecture 439

5/2/ Lecture 440 Non-trellis version coplot(volume~height|diameter, data=cherry.df)

5/2/ Lecture 441 Non-trellis version (2) coplot(volume~height|diameter, data=cherry.df,number=4,overlap=0)

5/2/ Lecture 442 Other useful functions  Regular R scatterplot3d (3d scatter plot, load library scatterplot3d) contour, persp (draws contour plots, surfaces) pairs  Trellis cloud (3d scatter plot)

Rotating plots  You need to install the R330 package Create a data frame e.g. called data.df with the response in the first column  Then, type reg3d(data.df) 5/2/ Lecture 443