Graphics I Or Making things pretty in R.

Similar documents
MATH& 146 Lesson 11. Section 1.6 Categorical Data

Frequencies. Chapter 2. Descriptive statistics and charts

Package rasterimage. September 10, Index 5. Defines a color palette

E X P E R I M E N T 1

ggplot and ColorBrewer Nice plots with R November 30, 2015

INSTRUCTIONS FOR AUTHORS CONTRIBUTIONS TO JOURNAL EGRSE VERION A4, ONE COLUMN LANDSCAPE!!!

HD-SDI Express User Training. J.Egri 4/09 1

Homework Packet Week #5 All problems with answers or work are examples.

MATLAB Basics 6 plotting

Record your answers and work on the separate answer sheet provided.

Phenopix - Exposure extraction

Technical Reports. MCG 4340 Mechanical Engineering Laboratory Manual

What is Statistics? 13.1 What is Statistics? Statistics

Tech Paper. HMI Display Readability During Sinusoidal Vibration

Visual Encoding Design

Printing From Applications: QuarkXPress 8

PS User Guide Series Seismic-Data Display

MARK SCHEME for the November 2004 question paper 9702 PHYSICS

STAT 113: Statistics and Society Ellen Gundlach, Purdue University. (Chapters refer to Moore and Notz, Statistics: Concepts and Controversies, 8e)

7. Image transmission functions

INSTRUCTIONS FOR AUTHORS

Statistics for Engineers

Version : 27 June General Certificate of Secondary Education June Foundation Unit 1. Final. Mark Scheme

Capstone Experiment Setups & Procedures PHYS 1111L/2211L

Manuscript template: full title must be in sentence case

Package icaocularcorrection

Calculated Percentage = Number of color specific M&M s x 100% Total Number of M&M s (from the same row)

Algebra I Module 2 Lessons 1 19

American Chemical Society Publication Guidelines

Broadcast H.264 files live with ATEM Television Studio!

INTERIM ADVICE NOTE 109/08. Advice Regarding the Motorway Signal Mark 4 (MS4)

Math 81 Graphing. Cartesian Coordinate System Plotting Ordered Pairs (x, y) (x is horizontal, y is vertical) center is (0,0) Quadrants:

Math Final Exam Practice Test December 2, 2013

Chapter 4. Displaying Quantitative Data. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

MATH 214 (NOTES) Math 214 Al Nosedal. Department of Mathematics Indiana University of Pennsylvania. MATH 214 (NOTES) p. 1/3

Data Analytics for Social Science Comparing through visualisation

MIS 0855 Data Science (Section 005) Fall 2016 In-Class Exercise (Week 6) Advanced Data Visualization with Tableau

Part 1: Introduction to computer graphics 1. Describe Each of the following: a. Computer Graphics. b. Computer Graphics API. c. CG s can be used in

Graphical Displays of Univariate Data

Why visualize data? Advanced GDA and Software: Multivariate approaches, Interactive Graphics, Mondrian, iplots and R. German Bundestagswahl 2005

LOGO MANUAL. Definition of the basic use of the logo

UNIVERSITY OF MASSACHUSETTS Department of Biostatistics and Epidemiology BioEpi 540W - Introduction to Biostatistics Fall 2002

Springer Guidelines For The Full Paper Production

This past April, Math

Part 1: Introduction to Computer Graphics

Guidelines for DD&R Summary Preparation

Alternative: purchase a laptop 3) The design of the case does not allow for maximum airflow. Alternative: purchase a cooling pad

More About Regression

All submissions and editorial correspondence should be sent to

QCTool. PetRos EiKon Incorporated

Bioconductor s marray package: Plotting component

NENS 230 Assignment #2 Data Import, Manipulation, and Basic Plotting

MATLAB Programming. Visualization

PHY221 Lab 1 Discovering Motion: Introduction to Logger Pro and the Motion Detector; Motion with Constant Velocity

Journal of Computer Chemistry, Japan: Information for Authors, 2015

6. Research results (studies) are the primary type of article desired but review articles are also welcome.

Section 5.2: Organizing and Graphing Categorical

IHE. Display Consistency Test Plan for Image Displays HIMMS and RSNA. Integrating the Healthcare Enterprise

INSTRUCTIONS FOR AUTHORS. Editor-in-Chief. S. Ferraz-Mello, University of Sa o Paulo-IAG, Brazil

Vision Call Statistics User Guide

The theory of data visualisation

Table of Contents. Introduction...v. About the CD-ROM...vi. Standards Correlations... vii. Ratios and Proportional Relationships...

INSTRUCTIONS TO AUTHORS

Relationships Between Quantitative Variables

How to use the NATIVE format reader Readmsg.exe

STAT 503 Case Study: Supervised classification of music clips

EVO consoles are offered in a number of size options, to suit the installation and working style of the studio.

Fitt s Law Study Report Amia Oberai

Beam test of the QMB6 calibration board and HBU0 prototype

ARCHAEOLOGICAL REPORTS PREPARING YOUR MANUSCRIPT FOR PUBLICATION

1.2 Universiti Teknologi Brunei (UTB) reserves the right to award the tender in part or in full.

Relationships. Between Quantitative Variables. Chapter 5. Copyright 2006 Brooks/Cole, a division of Thomson Learning, Inc.

potentiostat/galvanostat

Author Guidelines for Preparing Manuscript: Manuscript file format

Bridges and Arches. Authors: André Holleman (Bonhoeffer college, teacher in research at the AMSTEL Institute) André Heck (AMSTEL Institute)

Notes Unit 8: Dot Plots and Histograms

What's new in EndNote Version 6?

Once an author has logged into the system, the Author Main Menu will be displayed.

Guidelines for TRANSACTIONS Summary Preparation

ACUSCREEN NDT Joaquín González -

BEAMAGE 3.0 KEY FEATURES BEAM DIAGNOSTICS PRELIMINARY AVAILABLE MODEL MAIN FUNCTIONS. CMOS Beam Profiling Camera

Instructions to authors

NOVA SPM Control Program

Histograms and Frequency Polygons are statistical graphs used to illustrate frequency distributions.

Statistics: A Gentle Introduction (3 rd ed.): Test Bank. 1. Perhaps the oldest presentation in history of descriptive statistics was

Physics 277:Special Topics Medieval Arms and Armor. Fall Dr. Martin John Madsen Department of Physics Wabash College

Home Page 1 Press the House button I E

Proceedings of the Third International DERIVE/TI-92 Conference

MTL Software. Overview

Log-detector. Sweeper setup using oscilloscope as XY display

About Final Cut Pro Includes installation instructions and information on new features

Evolve Graphic Panel Package

Interlace and De-interlace Application on Video

Dot Plots and Distributions

Reproducibility Assessment of Independent Component Analysis of Expression Ratios from DNA microarrays.

STEPS. For Successful Content Design In Digital Signage Systems

When submitting your manuscript, it is important that you provide a printed version in

Element Finish. Fabric PE E PANEL MATRIX PANEL MATRIX PANEL MATRIX

RATE CARD & MEDIA KIT 2013

Quick reference guide

Transcription:

Graphics I Or Making things pretty in R rebecca.smith@kcl.ac.uk

In this session See the range of options for graphics in R Be able to use basic graphics Make clear, attractive graphs Highlight some useful graphics packages

Weight Better than Excel? Chick Weights 400 350 300 250 200 150 100 horsebean linseed soybean sunflower meatmeal casein 50 0 horsebean linseed soybean sunflower meatmeal casein Feed

Benefits of R?

Benefits of R? R is great when you want to produce one type of graph very frequently in a consistent format (e.g. common bar graphs, scatter plots) Producing high resolution plots for publication and presentations Making composite plots Having control over small details (making it perfect) Producing clear, beautiful plots! The best plots are those which viewers immediately understand! Limit clutter, colour, and extraneous objects

Examples demo(graphics) demo(persp) library(lattice) demo(lattice) Data to play with http://stat.ethz.ch/r-manual/rdevel/library/datasets/html/00index.html data(chickwts) data(trees) data(sunspot.year) data(occupationalstatus) data(cars)

Visualising Data data(chickweight) weight Time Chick Diet 42 0 1 1 51 2 1 1 59 4 1 1 64 6 1 1 76 8 1 1 93 10 1 1 Matrix of plots of columns of a data frame (everything by everything) plot(chickweight)

Plot Types Scatter plot: plot() Bar graph: barplot() Strip charts: stripchart() Box plot: boxplot() Pie chart: pie() Histogram: hist() Volcano plot: drawvolcanoplot [requires madb library] Survival curve: survfit followed by plot [requires survival library] You can easily make Volcano plots, QQ plots, or ROC curves with the plot function; however, using specific functions can save time

Plot Types hist(chickweight$weight) boxplot(weight~time) stripchart(weight~time, vertical=t)

Useful additions to scripts Add a title main= title X and Y label ylab= weight, xlab= group Change the point style and size pch=19, cex=1.5 Line type and width lty=2, lwd=2 Change the colour of plotted parts col=c( red, white, blue ) More later and at http://stat.ethz.ch/r-manual/rdevel/library/graphics/html/par.html

pch and lty

Adding lines abline() Adds one or more straight lines through the current plot Needs Intercept and slope Uses all par() features like lty, lwd and col Can use results directly from a linear model plot(weight~time, data=chickweight) abline(coef(lm(chickweight$ weight~chickweight$time)) [1], coef(lm(chickweight$weigh t~chickweight$time))[2], lwd=2, lty=2, col="red")

Axes boxplot(weight~time), xaxt="n") axis(1, 1:12, letters[0:12]) boxplot(weight~time), xaxt="n") axis(1, c(2,4,6,8,10,12), c("b", "d", "f", "g", "i","k"))

Legend Adding a legend to a plot outside of the script Can tell position, group names, etc. fill is for boxes with colours in col is for line and point colour Need to specify lty or pch legend(4, 40, c( Group1", Group2"), fill=c("red", "blue")) legend(4, 40, c( Group1", Group2"), col=c("red", "blue"), pch=1)

Exporting your creations Image type PDF pdf( test.pdf ) TIFF tiff( test.tiff ) PNG png( test.png ) Bitmap bmp( test.bmp ) JPEG jpeg( test.jpeg ) Window size and units (px, mm, in or cm) width = 480, height = 480, units = "px" Resolution res = NA Point size pointsize = 12 tiff( image.tiff, width = 25, height = 25, units = cm, res = 100, pointsize = 10) plot(x~y) dev.off()

Be aware... tiff("cwres.tiff") plot(weight~time, data=chickweight) dev.off() tiff("cwres1.tiff", width = 25, height = 25, units = "cm", res = 100, pointsize = 10) plot(weight~time, data=chickweight) dev.off()

Margins You can adjust how much of a margin around the plot you give Can adjust all margins individually left right v v par(mar=c(2,2,1,1)) ^ ^ bottom top Also allow plotting in the margins mtext(text, side = 3) <- Text is written in one of the four margins par(xpd=na)<- If FALSE, all plotting is clipped to the plot region, if TRUE, all plotting is clipped to the figure region, and if NA, all plotting is clipped to the device region

Matrix Make a matrix of multiple plots par(mfrow=c(2,2)) <- 2 by 2 matrix par(mfrow=c(3,1)) <- 1 column, 3 rows One figure in row 1 and two figures in row 2 layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))

Don t reinvent the wheel... Many graphics packages available in R If there is something complicated, chances someone have made a package or written a script you can adapt ggplot (Jack) sciplot Circos WGCNA

sciplot Useful package for one-way or higher experimental designs Produces line plots and bargraphs library(sciplot) bargraph.ci lineplot.ci

In Action bargraph.ci(time, weight, group=diet, data=chickweight, legend=true, x.leg=0, ylim=c(0,300), col=rainbow(4, s = 1, v = 1))

More complex Can easily use R to create plots for data visualisation and perform QC of data Useful for Showing principal components QQ-plots Sex typing Manhattan plots No matter what you use to plot Keep it simple and understandable Eliminate distractions Chose best fit graph