Plotting Complex Figures Using R

Slides:



Advertisements
Similar presentations
R for Macroecology Functions and plotting. A few words on for  for( i in 1:10 )
Advertisements

EXAMPLE 1 Write an equation of a line from a graph
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to R Graphics
Graphics in R data analysis and visualization Katia Oleinik Scientific Computing and Visualization Boston University
Spreadsheets A spreadsheet package is a general purpose computer package that is designed to perform calculations. A spreadsheet is a table which is divided.
R graphics  R has several graphics packages  The plotting functions are quick and easy to use  We will cover:  Bar charts – frequency, proportion 
MICROSOFT OFFICE 2013 EXCEL 1. 2 File Tab 1 Title Bar 5. Group 7 Name Box 6 Active Cell 8 Formula Bar 4 Ribbon 9 Column 10. Row 11 Sheet Tabs 12 View.
Fundamental Features of Graphs All graphs have two, clearly-labeled axes that are drawn at a right angle. –The horizontal axis is the abscissa, or X-axis.
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.
Evan Girvetz Winkenwerder Introduction to Graphics in R © R Foundation, from
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
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.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 9 Margins and Print.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week5: Charts/Plots in R.
CHAPTER 14 Formatting a Workbook Part 1. Learning Objectives Format text, numbers, dates, and time Format cells and ranges CMPTR Chapter 14: Formatting.
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
Baburao Kamble (Ph.D) University of Nebraska-Lincoln
R Graphics Lori Shepherd-Kirchgraber May 22, 2012.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Graphs in Science You Can Do It!!!.
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...)
IC 3 BASICS, Internet and Computing Core Certification Key Applications Lesson 10 Creating and Formatting an Excel Worksheet.
The introduction to SPSS Ⅱ.Tables and Graphs for one variable ---Descriptive Statistics & Graphs.
WORKBOOK FORMATTING Nolan Tomboulian Tomboulian.wikispaces.com HOW THINGS LOOK CELL COLORFONT COLOR CELL BORDERSFONT SIZE CELL SIZEFONT.
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.
Microsoft ® Office Excel 2007 Working with Charts.
Graphs in Physics PowerPoint #4. A graph is… A convenient way to show data.
Advanced Stata Workshop FHSS Research Support Center.
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.
Session 9 Managerial Spreadsheet Modeling -- Prof. Juran1.
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 Lesson 13 Organizing and Enhancing Worksheets Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
PROC GPLOT GPLOT is used to make two dimensional scatter-plots. General Syntax: proc gplot data=data-set options; plot y-variable*x-variable/options; run;
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
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.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
Change margins. 1 Preview a document. 2 Change paper size and orientation. 3 Print envelopes and labels. 4 Choose print options. 5 2.
Introduction to plotting data Fish 552: Lecture 4.
By Christy Quattrone Click to View Types of Graphs Data Analysis, Grade 5.
Change margins. 1 Preview a document. 2 Change paper size and orientation. 3 Print envelopes and labels. 4 Choose print options. 5 2.
Review > mean(humidity, na.rm=T) > humidity[!is.na(humidity)] > X x Y Y[[1]][2,3] > zone.fac
GRAPHING RULES.
Organizing Qualitative Data
Working with Charts © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Using R Graphs in R.
Unit 4 Statistical Analysis Data Representations
Trevor A. Branch FISH 552 Introduction to R
Excel 1 Microsoft Office 2013.
Microsoft Office Illustrated Introductory, Windows XP Edition
You might want to start your title ‘A graph to show....’
Formatting a Workbook Part 1
CSc4730/6730 Scientific Visualization
3.5 Write and Graph Equations of Lines
Plotting Signals in MATLAB
EXAMPLE 1 Write an equation of a line from a graph
Organizing Qualitative Data
Chapter 3 Visual Display of Data.
Title of presentation | Presentation by [Enter details in 'Header & Footer' field 18/05/2019.
Microsoft Office Illustrated Fundamentals
Microsoft PowerPoint Tutorial Graphs BIS 101 Spring 2018.
Presentation transcript:

Plotting Complex Figures Using R Simon Andrews simon.andrews@babraham.ac.uk v1.1

The R Painters Model Plot area Base plot Overlays

Core Graph Types Local options to change a specific plot Global options to affect all graphs

Common Options Axis scales Axis labels Plot titles Plot characters xlim c(min,max) ylim c(min,max) Axis labels xlab(text) ylab(text) Plot titles main(text) sub(text) Plot characters pch(number) cex(number)

Plot Characters

Plot Type Specific Options

Plot (scatterplots and line graphs) Input: Almost anything. 2 x Vectors Output: Nothing Options: type l=line, p=point, b=line+point lwd line width (thickness) lty line type (1=solid,2=dashed,3=dotted etc.)

Barplot (bar graphs) Input: Vector (single) or Matrix (stack or group) Output: Bar centre positions Options: names.arg Bar labels (if not from data) horiz=TRUE Plot horizontally beside=TRUE Plot multiple series as a group not stacked

Hist (histograms) Input: Vector Output: Summary of binned data Options: breaks Number or limits of bins probability Y axis is probability, not freq labels Per bin text labels

Boxplot Input: Vector, List or formula (data~factor) Output: Summary of the boxplot parameters Options: range Sensitivity of whiskers varwidth Width represents total observations horizontal Plot horizontally

Controlling plot area options with par

Par The par function controls global parameters affecting all plots in the current plot area Changes affect all subsequent plots Many par options can also be passed to individual plots

Par examples Reading current value Setting a value Restoring a value par()$cex Setting a value par(cex=1.5) -> old.par Restoring a value par(old.par) dev.off()

Par options Margins Warning mai (set margins in inches) mar (set margins in number of lines) mex (set lines per inch) 4 element vector (bottom, left, top, right) Warning Error in plot.new() : figure margins too large

Par options Fonts and labels cex – global char expansion cex.axis cex.lab cex.main cex.sub

Par options Font style font (font.axis,font.main,font.sub,font.lab) 1 = Plain text 2 = Bold text 3 = Italic text 4 = Bold italic text las (label orientation) 0 = Parallel to axis 1 = Horizontal 2 = Perpendicular 3 = Vertical

Par options Multi-panel mfrow(rows,cols) Not supported by some packages

Exercise 1

Using Colour

Specifying colours Hexadecimal strings Controlled names #FF0000 (red) #0000FF (blue) #CC00CC (purple) Controlled names “red” “green” etc. colors()

Built in colour schemes Functions to generate colours Pass in number of colours to make Functions: rainbow heat.colors cm.colors terrain.colors topo.colors

Colour Packages Color Brewer ColorRamps Set of pre-defined, optimised palettes library(RColorBrewer) brewer.pal(no colours, palette) ColorRamps Create smooth palettes for ramped colour Generates a function to make actual colour vectors colorRampPalette(c(“red”,”white”,”blue”)) colorRampPalette(c(“red”,”white”,”blue”))(5)

Colour Packages Colorspace library(colorspace) choose.palette()

Applying Colour to Plots Vector of colours passed to the col parameter Vector of factors used to divide the data Colours taken from pallete Can read or set using pallete function palette() palette(brewer.pal(9,”Set1”) Ordered by levels of factor vector

Dynamic use of colour Colouring by density Colouring by value Pass data and palette to densCols Vector of colours returned Colouring by value Need function to map values to colours

Colour Mapping Function map.colours <- function(value,range,palette) { proportion <- (value-range[1])/(range[2]-range[1]) index <- round((length(palette)-1)*proportion)+1 return(palette[index]) }

Exercise 2

Plot Overlays

Points Input: 2 Vectors (x and y positions) Options: pch cex

Lines / Arrows / Abline Input: Options: Lines 2 vectors (x and y) Arrows 4 vectors (x0,x1,y0,y1) Abline Intercept and slope (or correlation object) Options: lwd angle (arrows)

Polygon (shaded areas) Input: 2 vectors (x and y) for bounding region Options: col

Text (in plot text) Input: Options: Text, x, y adj (x and y offsets) pos (auto offset 1=below,2=left,3=above, 4=right)

Legend Input: Options: Position (x,y or “topright”,”bottomleft” etc) Text labels Options: fill (colours for shaded boxes) xpd=NA (draw outside plot area)

Multi-axis plots Draw one plot Set par (new=TRUE) Draw second plot (not overlay) Don’t draw axes (xaxt=“n”, yaxt=“n”) Don’t draw axis labels (xlab=“”, ylab=“”) Add custom axis side to set location lines to set offset mtext function (NOT parameter) to add text.

Exercise 3