Introduction to plotting data Fish 552: Lecture 4.

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

Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Step-by-Step: Adjust a Chart Axis USE the Pricing Final presentation that is still open from the previous exercise. 1.Click the chart on slide 2 to select.
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
2D Plots 1 ENGR 1181 MATLAB 12.
Introduction to R Graphics
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
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
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
6601 Project---Graphics --Enhancing Plots --Fine Control of Graphics Xingyan Bai, Qian Zhang, Ying Li.
Web Page Development Identify elements of a Web Page Start Notepad
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.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week5: Charts/Plots in R.
Making Tables and Graphs with Excel The Basics. Where do my IV and DV go? Just like you would create a data table on paper, your IV goes in the leftmost.
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.
Graphics in R. X
PLOTS AND FIGURES DAVID COOPER SUMMER Plots One of the primary uses for MATLAB is to be able to create publication quality figures from you data.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
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...)
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012.
Microsoft ® Office Excel 2007 Working with Charts.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
Plotting risk perceptions vs. political orientation & science comprehension Steve Genco August 19, 2015.
Getting Started with TI-Interactive. TI-Interactive TI-Interactive can be used to create a variety of graphs. Scatter Plots, Line Plots, Histograms, Modified.
S5-1 ADM740, Section 5, June 2007 Copyright  2007 MSC.Software Corporation SECTION 5 PLOT CONFIGURATION FILES.
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.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
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.
UW CSE 190p Section 7/26, Summer 2012 Dun-Yu Hsiao.
GRAPHICS MODULE 14 STUDY BOOK. Graphic commands SCREEN - puts the screen into graphics mode WINDOW - allows scaling of the screen LINE - 3 formats –LINE.
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
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
Intermacs Form Download Excel Tutorial Pivot Tables, Graphic Tools, Macros By: Devin Koehl.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
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.
ENGR 1181 College of Engineering Engineering Education Innovation Center Excel Graphing.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
TEMPLATE DESIGN © Professional Template for a 36x48 poster presentation Your name and the names of the people who have.
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
Review > mean(humidity, na.rm=T) > humidity[!is.na(humidity)] > X x Y Y[[1]][2,3] > zone.fac
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Open the standard.idw template. Save copy as a different file name. If you want to create as a template, save to the c:\Program Files\Autodesk \Inventor10.
Creating a Plot The plot function can take one or more inputs; e.g. plot (x, y) or plot (y) Note that in the two-argument version, the vectors x and.
Using R Graphs in R.
Course Information Do not rely on color to distinguish curves (due to black-white printout). Use different line styles to distinguish curves (solid, dashed,
Lecture 25: Exploring data
Trevor A. Branch FISH 552 Introduction to R
Net 222: Communications and networks fundamentals (Practical Part)
MATLAB How to use (using M-files) Double click this icon
Microsoft Office Illustrated Introductory, Windows XP Edition
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
How to Use Microsoft Excel for Data Entry
Presentation transcript:

Introduction to plotting data Fish 552: Lecture 4

Recommended Readings R Graphics –R Graphics: Chapters 1 and 2 (Paul Murrell, 2006) – Only ch. 1 is available free online, but ch. 2 is recommended as well if you have access to the book

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

Base Graphics: plot() plot() generic function for plotting R objects –points, lines, points and lines,... > ?plot Download the primates data and read it into R –Notice the row names

3 Ways to plot plot(x = primates$Bodywt, y = primates$Brainwt) plot(Brainwt ~ Bodywt, data = primates) attach(primates) plot(x = Brainwt, y = Bodywt) detach(primates)

xlab(), ylab() By default, R will use the name of the variables as axis labels Add labels to the x and y axes plot(Brainwt ~ Bodywt, data = primates, xlab = “Body Weight (kg)”, ylab = “Brain Weight (g)”)

xlim(), ylim() By default R chooses x and y limits just larger than the range of your data To change the default x and y limits plot(Brainwt ~ Bodywt, data = primates, xlim = c(0,300), ylim = c(0,1400))

Use of Colors The color palette when color is specified by a number > palette() [1] "black" "red" "green3" "blue" "cyan“ [6] "magenta" "yellow" "gray" plot(Brainwt ~ Bodywt, data = primates, xlim = c(0,300), ylim = c(0,1400), col = 2)

In-class exercise 1 Copy and paste these commands into your R script and run them. Try to figure out what’s going on here... plot(Brainwt ~ Bodywt, data = primates, xlim = c(0,300), ylim = c(0,1500), col = 4) plot(Brainwt ~ Bodywt, data = primates, xlim = c(0,300), ylim = c(0,1500), col = "blue") plot(Brainwt ~ Bodywt, data = primates, xlim = c(0,300), ylim = c(0,1500), col = 12) plot(Brainwt ~ Bodywt, data = primates, xlim = c(0,300), ylim = c(0,1500), col = c(2,4))

Use of Colors There are 657 colors to choose from colors() point.colors <- c("red", "orange", "green", "blue", "magenta") plot(Brainwt ~ Bodywt,..., col = point.colors)

Point character control pch : point character The default plotting character is an unfilled circle (pch = 1) plot(Brainwt ~ Bodywt,..., pch = 20) cex: character expansion The default expansion is none (cex = 1) plot(Brainwt ~ Bodywt,..., cex = 3)

More options bg : set background color for devices –Use this option in combination with pch plot(Brainwt~Bodywt,..., bg = point.colors, pch = 21)

Plot generated with code from: ?points

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. Show help for par (?par) List all par options > par() $xlog [1] FALSE..

Graphing parameters: par() Save default par values > old.par <- par() Example par(cex = 1.25) Restore defaults > par(oldPar) Warning messages: 1: In par(oldPar) : graphical parameter "cin" cannot be set 2: In par(oldPar) : graphical parameter "cra" cannot be set 3: In par(oldPar) : graphical parameter "csi" cannot be set 4: In par(oldPar) : graphical parameter "cxy" cannot be set 5: In par(oldPar) : graphical parameter "din" cannot be set R.O. indicates read-only arguments: These may only be used in queries and cannot be set

Multiple Point Characters Simple extension of one pch plot(Brainwt~Bodywt,..., pch = 21:25)

locator() Interactive function Identifies the locations of a point on a graph > locator(1) $x [1] $y [1] loc <- locator(1)

legend() Look up help on legend function ( ?legend ) –Many of the options are the same as described in par legend(loc$x, loc$y, legend = rownames(primates), pt.bg = point.colors, pch = 21:25) plot(Brainwt ~ Bodywt,.... legend("topright", legend = rownames(primates), pt.bg = point.colors, pch = 21:25, bty = 'n') no box around legend topright, bottomleft, middle,...

Axis Properties yaxp / xaxp : control tick marks –c(lower point, upper point, number of intervals between tick marks) plot(Brainwt ~ Bodywt,..., yaxp = c(0,1500,5))

Hands-on Exercise 2 Try to replicate this graph –You’ll need to figure out how to add a title –Think outside the box with pch –Note the axes

Axis properties For more control, try the axis() function –?axis plot(Brainwt ~ Bodywt,…, yaxt = ‘n’, xaxt = ‘n’ ) axis(2, at = c(0,300,600,900,1200,1500), labels = c(0,300,600,900,1200,"BIG")) axis(1, at=c(50,100,150,200,2.... Suppress the x and y axis ticks and labels 1=below, 2=left, 3=above and 4=right

Labeling: text() Look up help on ?text plot(Brainwt ~ Bodywt, data = primates, text(primates$Bodywt, primates$Brainwt, labels = rownames(primates),pos = 4) adj along with the coordinates allows for more precise placement of labels text(primates$Bodywt, primates$Brainwt, labels = rownames(primates),adj = -0.5) Values of 1, 2, 3 and 4, respectively indicate positions below, to the left, above and to the right of the coordinates Shift to the right coordinates by ½ inch

Labeling: identify() identify() can be used to label or identify points on a graph –?identify Click near two of the points plot(Brainwt ~ Bodywt,... identify(primates$Bodywt, primates$Brainwt, labels = rownames(primates), n = 2)

Adding points and lines points() and lines() take many of the same arguments as plot() –These can be added to the current plot ?lines –lty specifies the line type 0 = blank 1 = solid 2 = dashed 3 = dotted 4 = dot-dash 5 = long-dash 6 = two dash

Adding points and lines - type specifies the type of plot to be drawn "p" - points, "l" - lines, "b" - both, "c" - lines part alone of "b", "o" - ‘overplotted’, "h" - ‘histogram’ like (or ‘high-density’) vertical lines, "s" - stair steps, "n" for no plotting. lines(x = c(50,100,150,200), y = c(250,400,550,750), type = "b", lwd = 3, lty = 2)

Additional points or lines Add lines lines(x = c(50,100,150,200), y = c(250,400,550,750), type ="b", lwd = 3, lty = 2) Add points points(x = c(150,200,250,300), y = c(100,150,200,250), cex = 3, pch = 20)

Hands-on Exercise 3 The equation for the standard normal density: exp(-x^2)/sqrt(2*pi) Hint: I used type= three separate times