Lecture 3 + Seminar 3 A workshop on graphing using ggplot2.

Slides:



Advertisements
Similar presentations
Interaction Design: Visio
Advertisements

Summary Statistics/Simple Graphs in SAS/EXCEL/JMP.
Rich Pugh Andy Nicholls Head to Head: Lattice vs ggplot2 Rich Pugh
Title Blocks and Lettering
Visual Displays of Data Chapter 3. Uses of Graphs >Positive and negative uses Can accurately and succinctly present information Can reveal/conceal complicated.
Copyright © 2010, 2007, 2004 Pearson Education, Inc. All Rights Reserved. Lecture Slides Elementary Statistics Eleventh Edition and the Triola.
Chapter 10—Creating Presentations
GIMP Tutorial v2.0 Boo Virk
HAWKES LEARNING SYSTEMS Students Matter. Success Counts. Copyright © 2013 by Hawkes Learning Systems/Quant Systems, Inc. All rights reserved. Section 2.2.
Graphing With Excel 2010 University of Michigan – Dearborn Science Learning Center Based on a presentation by James Golen Revised by Annette Sieg…
Copyright © 2005 Department of Computer Science CPSC 641 Winter Data Analysis and Presentation There are many “tricks of the trade” used in data.
1 Data Analysis H There are many “tricks of the trade” used in data analysis and results presentation H A few will be mentioned here: –statistical analysis.
Let's zoom in on one corner of the coordinate plane
SW318 Social Work Statistics Slide 1 Using SPSS for Graphic Presentation  Various Graphics in SPSS  Pie chart  Bar chart  Histogram  Area chart 
Week 4 LSP 120 Joanna Deszcz. 3 Types of Graphs used in QR  Pie Charts Very limited use Category sets must make a whole  XY Graphs or Line Graphs Use.
Using Charts in a Presentation Lesson 6. Software Orientation Charts can help your audience understand relationships among numerical values. The figure.
Section 5: Graphs in Science
Instructor: Professor Cora Martinez, PhD Department of Civil and Environmental Engineering Florida International University.
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.
Designing a Presentation
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
1 iSee Player Tutorial Using the Forest Biomass Accumulation Model as an Example ( Tutorial Developed by: (
Baburao Kamble (Ph.D) University of Nebraska-Lincoln
Graphs in Science You Can Do It!!!.
Creating Integrated Web-based Projects using Microsoft Word.
Writing Business Reports. Introduction Gives background of problem or assignment. Introduces the subject and shows why it is significant or important.
Applications for Web Development (CIS 162) Intro to Photoshop.
Line graphs are a powerful tool in science.
Interaction Design Interaction Design - Joan Cahill - Visio Interaction Design: Visio.
Microsoft ® Office Excel 2007 Working with Charts.
Chapter 4: Create, Edit, and Perform Calculations in Reports Exploring Microsoft Office Access 2007.
Microsoft Office 2007 Excel Chapter 1 Creating a Worksheet and an Embedded Chart.
Organizational Text Patterns What is structure?. Monday, December 2, 2013 In the Genre/Green section of your journal Write: Information Text: Then copy.
HAWKES LEARNING SYSTEMS Students Matter. Success Counts. Copyright © 2013 by Hawkes Learning Systems/Quant Systems, Inc. All rights reserved. Section 2.2.
16 Graph Skills How to read and understand advanced types of bar charts, area graphs, climographs and triangle graphs How to advance their skills of drawing.
Chapter 2 Web Page Design Mr. Gironda. Elements of a Web Page These are things that most web pages use.
1 STAT 500 – Statistics for Managers STAT 500 Statistics for Managers.
Advanced Stata Workshop FHSS Research Support Center.
Excel chapter 4.
1. Chapter 15 Creating Charts 3 Charting Data in Word A chart or graph presents data visually. A chart depicts numeric data in a graphical format. If.
Return to Outline Copyright © 2011 by Maribeth H. Price 3-1 Labeling and annotation.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
McGraw-Hill Career Education© 2008 by the McGraw-Hill Companies, Inc. All Rights Reserved. Office Excel 2007 Lab 2 Charting Worksheet Data.
CMAP Concept Mapping Activity Climate Change Unit.
Student report cards Presentation for Primary School Staff 2007.
Chapter One, Section 5: Graphs in Science
Making Bar Graphs and Scatter Plots in Microsoft Excel 2007.
Ggplot2 A cool way for creating plots in R Maria Novosolov.
Microsoft® Excel Use the Chart Tools Design tab. 1 Use the Chart Tools Layout and Format tabs. 2 Create chart sheets and chart objects. 3 Edit.
PowerPoint Information Your Name. How to add a theme  Design Tab  Add Variants-Change Colors, Fonts, Effects, and Background Style.  Color-Choose from.
Copyright © 2006 by Maribeth H. Price 9-1 Chapter 9 Presenting Data.
Mapping local community assets online Read this if you want to learn how to: 1)Create online maps of local community assets using Google Maps 2)Allow other.
TABLE OF CONTENTS 2014 BasmahAlQadheeb. What is a report? A report is a clearly structured document that presents information as clearly as possible.
Graphs in Science Section 1.5.
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.
Creating Charts Ms. Hall Spring Using the Insert Tab to Create Charts The Insert tab contains the command groups you’ll use to create charts in.
Desktop Publishing Lesson 5 — Enhancing Publications.
Using Graphs and Charts Organizing results from Scientific data.
Formatting a Research Paper Lesson 10 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft Word 2013.
Data Representation: Making Tables & Graphs. Data Tables.
ArcGIS 9 ch 12 Edited 06/14/05 1 Creating Your Presentation Your final step is to get your work ready for presentation. Making a good map requires an artistic.
IENG-385 Statistical Methods for Engineers SPSS (Statistical package for social science) LAB # 1 (An Introduction to SPSS)
Computer Fundamentals 1
EET 2259 Unit 11 Charts and Graphs
ggplot2 Merrill Rudd TAs: Brooke Davis and Megsie Siple
CPSC 531: System Modeling and Simulation
Data Presentation Carey Williamson Department of Computer Science
Exploring Microsoft Office Access 2010
Carey Williamson Department of Computer Science University of Calgary
EET 2259 Unit 11 Charts and Graphs
Presentation transcript:

Lecture 3 + Seminar 3 A workshop on graphing using ggplot2

Plotting packages in R Graphics functions in the base package: plot ( ), hist ( ), etc. lattice package ggplot2 Specialised functions inside other packages: plotrix, car, plotmeans, etc. Have an internal logic for a range of statistical plots

Programme Graphing and figures – general principles Guidelines for different kinds of graphs and publications: – Specialist (colour) publications – Presentations – Journal papers (APA guidelines) Quick plots using qplot (plus, a review on saving graphs) More flexible graphs using ggplot Final formatting using ggplot Seminar and assignment: At the seminar, you will complete an exercise to create an APA-style plot. Then, to complete the assignment, you will need to add at least one additional piece of formatting at home. Reading: book by the author of ggplot

General principles: Graphs and figures should... 1.Summarise and/or reveal data, making large datasets coherent 2.Encourage the viewer to think about the data being presented (rather than some aspect of the graph, like how pink, “pretty” or poorly visible it is) 3.Avoid distorting the data 4.Encourage the viewer to compare different pieces of data

A graph that satisfies all four criteria despite its complexity:graph

A graph that satisfies all four criteria despite its simplicity: Figure 4.2. Estimated means (and 95% CIs) of inferred natural control across success-slope conditions when covariates (soccer interest and prior beliefs) were evaluated at their mean values.

Guidelines for different types of graphs All graphs: – Think about when to start scales at the origin (0) Bar graphs: – If needing colour, use pastel colours to avoid overwhelming the viewer. – Best to use some shading (e.g., grey or patterns) to prevent the graph from looking like a wire frame. – Histograms: consider displaying the mean/median value as well. Graphs involving points (and possibly lines): – Vibrant colours work well for points and lines, making them quite visible. – Best to start y-axis at 0. – Use a line if there is a flow of time from one point to the next. – Patterns disappear if you stretch the x-axis too far. Scatter plots: – Simplify the look by not using a thick border. – Any line through the dots must be thicker than the dots or in a brighter colour.

Guidelines for different publication types Journal articlesSpecialist (colour) articlesConference presentations Follow APA guidelines – e.g., page 4 in this style manual.this Follow APA guidelines as much as possible, but use colour if an additional explanatory tool is needed. Colours: think about whether they should be vibrant or neutral, given (a) your topic, and (b) whether you are plotting points or bars (see previous slide). No caption available, so more labelling in the title or inside the graph is needed. Figures can be useful for a non- specialist audience. Same advice as for specialist articles regarding colour. For small sample sizes, you might not even need an x-axis and y-axis. Can instead label points of interest directly. Think about: What story do you want to tell? Who are you telling the story to?

University ratings by Czech students University ratings by foreign students Students highly unsure on average Highlighting individual data points:

Quick plots using qplot The qplot function is in the ggplot2 package. The function is very useful for data exploration, as it is possible to draw fairly complex plots with one or two lines of code. The function is not useful for final plots for presentations and publications because the overall appearance of the plots is difficult to change. Basic principle: "geoms" (representations of data) have "aesthetics“ (properties) that can be "mapped" to variables in the dataset or “set” to a desired value – geom examples: point, histogram, smooth (regression line) – aesthetics (aes) examples: x and y (the variables being plotted), colour, size, shape, alpha (transparency), group – additional arguments to do with avoiding overplotting: position and facet (facet_grid and facet_wrap) Start script

Saving graphs: a review In the Plots tab, Export -> Save Plot As Image... Then choose Image Format and Size By default, graphs are saved to your working directory, but you can choose any folder by clicking “Directory” after clicking “Save Plot As Image”. Back to script

More flexible graphs using ggplot The ggplot function is also in the ggplot2 package. Key concepts, apart from the already mentioned geoms, aesthetics, position, facet, setting and mapping: – Layers (+): The graph is not displayed until you add a layer, but it is customary to specify the aesthetics that apply to all layers at the very beginning. – Stats: Stats have default geoms, while geoms have default stats. – Each plot is treated as a variable (e.g., sepf3). – The aesthetics in each layer override any aesthetics specified at the beginning. – Search for these terms in the script and in the book for concrete examples. We covered: overlaying of histograms and regression lines, adding error bars to line plots and bar plots, setting axis limits (coord_cartesian), faceting, and free scales.

Final formatting using ggplot Adjusted throughTerms to find in the script Overall colour-scheme: black and white? settings for colours theme_set scale_colour_manual theme_bw() scale_colour_hue() scale_colour_grey Appearance of pointsgeom_point geom_params Appearance of error bars stat_summary (in our script) Other possibilities: geom_errorbar, geom_params colour = "gray41" Appearance of linesscale_linetype_manual scale_linetype_manual(values=c( "dotted", "solid", "longdash", "dotdash")) Gridlinestheme(panel.grid.major = element_line( )) theme(panel.grid.minor = element_line( )) panel.grid.major = element_line(colour = "gray41", size = 1) panel.grid.minor.y = element_blank()

Adjusted throughTerms to find in the script Labels along the axes scale_x_continuous (when x is not a factor variable) scale_x_discrete scale_y_continous scale_y_discrete scale_x_continuous(breaks = 1:2, labels = c("Trials 1-24", "Trials 25-48“, name = "Time period") scale_y_continuous(name = "") Facet labelstheme(strip.text = ___) Changes to name of factor levels strip.text.y = element_text(size=14, face = "bold") levels(longsub2$Measure) <- c("Kick Dir Entropy", "No. of Player\nChanges") Text sizetheme( ___ = element_text( )) theme(axis.title.x = element_text(size= 20), axis.text.y = element_text(size=14, colour = "black") Legendscale_linetype_manual scale_colour_hue etc. Depending on what aesthetic (colour, linetype, shape) you have mapped the variable to theme(legend.text = ___) scale_linetype_manual(values=c("dotted", "solid", "longdash", "dotdash"), name="Success Slope", breaks=c("Descending", "U-shaped", "Ascending", "Flat"), labels=c("Desc.", "U- shaped", "Ascending", "Flat")) legend.text = element_text(size=12)

Layering during final formatting (Script line 597) If you are adding something to an existing layer – such as stat_summary( ) – you need to redraw the whole plot under its current name or a new name. sepf3 <- ggplot(data = longsub2, aes(x=Time, y=Value, group = SeqCond)) + geom_line(mapping = aes(linetype = SeqCond), stat = "summary", stat_params = list(fun.y = mean), position = pd, geom_params = list(size =.75)) + facet_grid(Measure ~., scales = "free_y") + stat_summary(fun.data = "mean_cl_normal", geom = "errorbar", ymin = min, ymax = max, width =.05, mult = 1, position = pd, colour = "gray41") + geom_point(stat = "summary", stat_params = list(fun.y = mean), position = pd, geom_params = list(fill = "white", shape = 21, size = 3)) + scale_x_continuous(breaks = 1:2, labels = c("Trials 1-24", "Trials 25-48"), name = "Time period") + scale_linetype_manual(values=c("dotted", "solid", "longdash", "dotdash")) sepf3

Layering during final formatting If you are adding an entirely new layer, you can just use “+”, but it is best to avoid this, since you are highly likely to need to go back and make many changes to existing layers later on. sepf4 <- sepf3 + theme(axis.title.x = element_text(size= 20)) sepf5 <- sepf4 + theme(axis.text.y = element_text(size=14, colour = "black"), axis.text.x = element_text(size = 14, colour = "black"), strip.text.y = element_text(size=14, face = "bold")) There would be an error drawing this because some aspects of theme ( ) were already specified when drawing sepf4.

Reading Wickham, H. (2009). ggplot2: Elegant Graphics for Data Analysis. Available online: Book09hWickham.pdf Book09hWickham.pdf Additional resources: Field, A., Miles, J., & Field, Z. (2012). Discovering Statistics Using R. Sage: UK. Chapter 4. Exploring data with graphs. Support website: