1 Graphics – Part 2 HRP223 – 2013 November 20, 2013 Copyright © 1999-2013 Leland Stanford Junior University. All rights reserved. Warning: This presentation.

Slides:



Advertisements
Similar presentations
Interaction Design: Visio
Advertisements

Summary Statistics/Simple Graphs in SAS/EXCEL/JMP.
Chapter 6 Photoshop and ImageReady: Part II The Web Warrior Guide to Web Design Technologies.
Final Thoughts HRP 223 – 2013 December 4 th, 2013 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation.
1 Graphics – Part 3 HRP223 – 2013 December 2, 2013 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation.
FIRST COURSE Excel Tutorial 4 Working with Charts and Graphics.
1 SAS Formats and SAS Macro Language HRP223 – 2011 November 9 th, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning:
1 Creating and Tweaking Data HRP223 – 2010 October 24, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
What is New in SAS 9.2? Graphics and More. A Brief History of SAS Graphics 6.x 7.x = had the Output Delivery System (ODS) but it was not widely available.
ABC’s of PowerPoint (Office 2007) Part 1: Basic Vocabulary Part 2: Cursors Part 3: Insert Your Text Part 4: Insert Your Pictures Part 5: Basic Tools &
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Using Charts in a Presentation Lesson 6. Software Orientation Charts can help your audience understand relationships among numerical values. The figure.
PowerPoint: Tables Computer Information Technology Section 5-11 Some text and examples used with permission from: Note: We are.
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
SAS for Categorical Data Copyright © 2004 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright.
ADVANCED MICROSOFT POWERPOINT Lesson 6 – Creating Tables and Charts
1 Graphics HRP223 – 2013 November 18, 2013 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is.
Instructor: Professor Cora Martinez, PhD Department of Civil and Environmental Engineering Florida International University.
11 Chapter 3: Getting Started with Tasks 3.1 Introduction to Tasks and Wizards 3.2 Creating a Frequency Report 3.3 Generating HTML, PDF, and RTF Output.
Bay Area SUG June SAS ® 9.2 Implications for Biotech SAS ® 9.2 Implications for Biotech Bay Area SAS User’s Group June 7 th 2010 Sarmad Pirzada,
Make the Main Title with Large Bold Type Your Name and Title Here Your Department Here Texas A&M Health Science Center Make the Main Title with Large Bold.
Data Analysis Using SPSS
Abstract # 0000 Make the Main Title with Large Bold Type Use Smaller Type for the Subtitle. Above Type is 105pt. This Type is 70pt. Make authors’ names.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Committed to Shaping the Next Generation of IT Experts. Exploring Microsoft Office Word 2007 Chapter 3: Enhancing a Document Robert Grauer, Keith Mulbery,
HPR Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
Working with Data in Windows HRP223 – 2009 Sept 28 th, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
1 Graphics in EG and R HRP223 – 2009 November 16 th, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation.
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
ODS Statistical Graphics in SAS 9.2 January 17, 2010.
1 Graphics HRP223 – 2012 November 28, 2012 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® PowerPoint 2010 © 2011 The McGraw-Hill Companies,
Microsoft ® Office Excel 2007 Working with Charts.
Introduction to SAS/Graph 9.2 Ken Barz Colorado Prevention Center 22Oct2009 Ken Barz Colorado Prevention Center.
1 Lab 2 and Merging Data (with SQL) HRP223 – 2009 October 19, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning:
1 Graphics in EG and R HRP223 – 2009 November 16 th, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation.
Introduction to Enterprise Guide Jennifer Schmidt Rhonda Ellis Cassandra Hall.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
11/25/2015Slide 1 Scripts are short programs that repeat sequences of SPSS commands. SPSS includes a computer language called Sax Basic for the creation.
PowerPoint Lesson 6 Working with Tables and Charts Microsoft Office 2010 Advanced Cable / Morrison 1.
1 Graphics – Part 2 HRP223 – 2013 November 20, 2013 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation.
© 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Lecture 29 Enhancing Presentations with Graphics (2)
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
1 Lab 1 HRP223 – 2011 Oct 10, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
Graphics in EG and R HRP223 – 2009 November 16th, 2009
1 Lab 1 HRP223 – 2009 October 5, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
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.
1 Data Manipulation (with SQL) HRP223 – 2009 October 12, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Committed to Shaping the Next Generation of IT Experts. Exploring Microsoft Office Word 2007 Chapter 3: Enhancing a Document Robert Grauer, Keith Mulbery,
Beginning Data Manipulation HRP Topic 4 Oct 14 th 2012 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
© Execview Ltd 2015: all rights reserved Execview Scorecard Training/Reference Guide 2013 Key functions guide for Scorecard administrators.
SOC 305, Prof. Robert Martin Southeastern Louisiana University.
Make the Main Title with Large Bold Type Use Smaller Type for the Subtitle. Above Type is 110pt. This Type is 80pt. Make authors’ names smaller. This is.
Lesson 4: Working with Charts and Tables
PowerPoint: Tables and Charts
Chapter 8: ODS Graphics ODS graphics were not available prior to SAS 9.2 They have been implemented across a wide range of procedures Functionality isn’t.
Working with Data in Windows
SAS Output Delivery System
INTRODUCTION TO SGPLOT Zahir Raihan OVERVIEW  ODS Graphics  SGPLOT overview  Plot Content  High value plot statements  High value plot options 
Lab 3 and HRP259 Lab and Combining (with SQL)
Lab 2 and Merging Data (with SQL)
Lab 2 HRP223 – 2010 October 18, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
Data Manipulation (with SQL)
Using Charts in a Presentation
Presentation transcript:

1 Graphics – Part 2 HRP223 – 2013 November 20, 2013 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and international treaties. Unauthorized reproduction of this presentation, or any portion of it, may result in severe civil and criminal penalties and will be prosecuted to maximum extent possible under the law.

2 Statistical Graphics Procs proc sgPlot – general plotting procedure that replaces gplot proc sgScatter – lots of tools for scatterplots and scatter matrices proc sgPanel – quick and easy trellis/lattice/matrix/panel of plots Proc sgRender – used with proc template to make totally custom plots – It replaces proc greplay

3 What is a good graphic? Don’t make your audience think unnecessarily! – The point of the graphic should stand out instantly. – Plot the quantity (inference) that you want people to notice. Show the central tendency and the variability. Minimize the amount of ink on the page. Be sure colorblind people can understand it. – Use a black and white photocopier and make sure you can distinguish all groups.

4 Notice the approximately equal symbol I want the data in frequency order to show relative magnitude of cancer....

5 Setting the bar order.... Default is alphabetical order.

6 Using Unicode characters via hex codes... OMG... High quality voodoo to put in the approximately equal symbol.

7 What is wrong with this? What is the point that the reader should learn from this? How is the variability represented? What are the error bars? Can you interpret a 1 SD error bars? How many people are included? Ink to information … How many numbers are depicted? Never contrast black on blue. Read this reproduction of Steve Simon’s blog comments on SD vs SE bars: er-blog.com/article html

8 Another Way

9 How did I do that?

10

11 Don’t put a legend on the plot, add a pop-up description tooltip for pages on the web and save the graphics template.

12 The Graphic Template Premade complex plot designs are stored in a graphic template. You can also save the graphic template for any plot you make. Add tmplout= to the gplot statement.

13 The Template I gave it a name Use the new template on the dataset.

14 With the title in the graphic

15 Another version of the same data

16 Moderately Awful Code Bubble sizes are set by providing a radius… I force the area by setting the smallest and largest bubble size in centimeters. I want to use this part of the plot for the legend so I name it.

17 Built in Graphics Most analysis procedures (and the EG GUI) allow you to turn on graphics.... I use them to explore data but then use sgplot code for publication/posters.

18

19 What is wrong with this? What is the point of this graphic? How are the two sexes represented? What data is this?

20 Easy But Awful Boxplots

21 What is wrong with this? Lovely white space What is the point? How are the sexes represented? How many people? Where is the mean? What data is this?

22 What is the point of this graphic? How are the two sexes represented? A Good Boxplot

23 What is the point of this graphic? A Very Good Boxplot

24 Code for a Very Good Boxplot 9.4

25 Built in Graphics Many Enterprise Guide analyses have built in diagnostic graphics. They can be too complex....

26 When you test for the difference in the mean SAS gives you a great plot.

27 If you do not want to explain what Kernel density estimation is… remove the lines.

28 Finding the template Add before the procedure that draws the graphic add ods trace on; and include ods trace off; afterwards. This prints the names of all the templates used by the procedure in the log. product.procedure.Graphis.TemplateName

29 Looking at a Template You can ask proc template to display the template with the source statement: proc template; source stat.ttest.graphics.summary2; run; Remember to type this before you start editing: ods path(prepend) work.template (update);

30 Don’t Panic This is a complete template except for the proc template statement here and a run statement at the bottom. Copy this into an editor window and add proc template.

31 After adding proc template and commenting out the Kernel statements rerun the code.

32 Oops. Unknown key words… You can fix the color coding on the template code easily.

33 Fixed (permanently) All your subsequent plots will have no density line.

34 Avoid Thinking Put labels on the graphic directly instead of using a key. If you want people to compare the difference between two lines, plot the difference, not the two lines. Don’t include graphics that your audience will not understand.

35 Bivariate Comparisons with Lines People are extremely bad at judging the distance between two curves. Never ask people to judge up and down (vertical) distances between curves. Based on: Robbins Creating More Effective Graphs, 2005 The distance between the two curves is the same at all points.

36 Too Many Graphics If the ods graphics on statement gives you too many graphics, you can specify which graphics you want by including code designed for the procedure. Typically it looks like this: plot(only) = (table names). This design is poorly implemented because you need to know where to put the plot statement and what the table names are. Does it go on the proc line (like phreg), the tables line (like proc freq), or some other line? Also the table names specified with a plot statement do not always match the ODS table names.

37 Usually you can use an ODS exclude statement or an ODS select statement to pick the correct things to print. Using the plots(only) = syntax is more efficient.

38 Splitting a Grid Some procedures produce a grid of plots. You can get access to the individual plots by specifying plots(unpack). Then you can use plots(only)=tableName to get just the right parts. ODS select or exclude statements will not work.

39 plots(GlobalOptionsGoHere). The global options apply to all graphics in this procedure.

40 How to make graphics for publication Size File type Dots per inch etc...

41 I Typically Use HTML This says the images should show tooltips with extra statistical details when you hover the mouse over parts of the graphic. (I can’t image these.) This is the appearance template. For optimal results use: Analysis: color Default : overdistinguishes symbols for color or B&W Journal or journal2, etc: black and white Statistical or statistical2, etc: color Include image_dpi = 300 to set the resolution to be higher than the default 100 dots per inch. Try 300 for final images pasting into MS Office.

42 ods graphics on; This turns on the ODS statistical graphics. Behind the scenes this combines your data with a pre-specified description of what to plot and the aesthetics of the appearance. Your data Graph template Style template What Where? Colors Fonts

43 Useful ods graphics options ods graphics on / ods graphics / reset; ods graphics off; Width = 8in Height = 11in Imagefmt = jpg imagename = thingy imagefmt = staticmap ; Make a series of graphics called thingy1, thingy2, etc. If you set only width or height, it will use a 4:3 aspect ratio. Reset the graphic counter back to 1 Use pop-up tooltips with details. If you want to disable ods graphics for a procedure

44

45 ODS Graphics Editor with EG If you want to do extensive tweaking to a graphic, you can use the WYSIWYG ODS Graphics editor. Unfortunately it only works with ODS graphics procedures and you need to rerun the code in SAS to invoke it.

46 Move code from EG to SAS 1.Use the query builder to put your data in a permanent SAS library (not the work library). 2.Right click on the graphic node which is run on data in a permanent library and choose Open… Open Last Submitted Code. 3.Copy the code beginning with the SQL that makes the data. 4.Start SAS and paste the code into the program editor.

47 Move all your code to SAS Because the ODS graphics editor is not in EG (yet), you can export the entire set of code for the project and then rerun it in SAS.

48 ODS Graphics Editor with EG (2) After exporting all your EG project, open the code in SAS and add these lines at the top of the program: ods rtf file = "c:\blah\somefile.rtf"; ods listing sge = on; Then open the graphic of interest.

49

50 WYSIWYG Editing Right click and/or double click to set properties for objects in the plot. The tool is optimized for some of the ODS style templates but you can use custom colors.

51 Right click on things to set properties. – Colors, text details, fonts – Point and click annotation – Symbols, arrows, text, circles

52 WYSIWYG Editing While the Statistical graphics editor is a much needed improvement, it is incomplete. You can only use a few, style templates (for setting default colors and such) and you can not use custom style templates. This means that you can not do critical tasks like manually set the color for different values in scatter plots.

53 Plot Types Categorical variables – Descriptive Bar charts Dot plots – Inferential Continuous variables – Histogram – Box plot – Violin plots – Quantile and QQ plots

54 Frequency Plots EG for frequency plots Custom code

55 Bar Charts The ink-to-information ratio is lousy. A one dimensional quantity is being “expanded” into two dimensions. – Doubling of the amount corresponds to how much of an increase in area?

56 SAS Bar Charts SAS makes the reader do extra work by rotating the axis labels in ActiveX images. They pointlessly include variable labels by default.

57 How to do it? Notice you can Edit the data and apply filters. You can right click on variables and apply user-defined formats off the Properties dialog.

58 First create the format. In the Data windowpane of the Bar Chart GUI, right click on the variable and change the format to the User Defined format you had created.

59 The GUI is Solid My only complaints are that the rotate grouping values text does not work (position in this example) and the summary statistics do not show up when you request ActiveX images.

60.PNG format ActiveX image format

61 Saving the Graphic for Publication The easiest way to get publication quality graphics is to set the output type to be RTF.

62 Default Output and Graphics The default graphic format in EG is ActiveX. These images can be edited (even on the web) but they only display with Internet Explorer. I have set my graphics to display as ActiveX images. Tweak this with Tools> Options… > Graph.

63

64 Types of Images The default formats of the images are determined by the ODS destinations you are using: – LISTING: pgn visible in the Windows Image Fax Viewer – HTML: png, gif, jpg contained in web pages and visible in Internet Explorer, Firefox or Opera – LATEX: PostScrpt, epsi, gif, jpeg, pgn are visible in GhostView – PCL or PS: contained in Postscript file are visible in GhostView – PDF: contained in pdf, which is visible with Adobe Reader – RTF: visible in MS Word RTF graphics are done at 300 dpi by default

65 You can browse the ODS appearance templates from the Style Manager on the Tools menu.

66 Plot Types Categorical variables – Bar charts – Dot plots Continuous variables – Histogram – Box plot – Violin plots – Quantile and QQ plots

67 Dot charts Categorical variables

68 Grouped Categorical Variables To graph categorical data in SAS you need to get Michael Friendly’s Visualizing Categorical Data. Unfortunately, his macros are copyrighted with the book… So I will show you the R versions. – Fourfold plots – Mosaic plots – Association plots Grouped categorical variables

69 If you want to use R Download R for Mac or PC cran.cnr.berkeley.edu/bin/macosx/ cran.cnr.berkeley.edu/bin/windows/base cran.cnr.berkeley.edu/bin/macosx/ cran.cnr.berkeley.edu/bin/windows/base

70 How to learn R I usually teach R classes in the summer. – has links to my slide decks for R classes.

71 Plots for inference Categorical plots – Confidence limits on odds ratios – Four-fold plots – Expectancy plots – Mosaic plots

72 Fourfold Plots They draw 4 slices of pie with the area corresponding to the number of people in each cell of a 2x2 table and they have confidence bands such that if the confidence bounds overlap on adjacent pie pieces, they are not statistically significantly different. Grouped categorical variables 45% male vs. 30% female admission

73 More males were admitted than females. There is clear evidence of sexist policies in admissions! Grouped categorical variables

74 Department A admitted more females than males and every other department had no bias! The joy of Simpsons paradox. Grouped categorical variables

75 Mosaic Plots So you have an contingency table and you want to know if there is as an association. You do a chi-square test and it says there are associations between the rows and columns. What next? Grouped categorical variables

76 Some basic voodoo in R shows which combinations are over (in blue) or under represented (in red). Grouped categorical variables

77 I prefer the simpler association plots. Grouped categorical variables

78 Continuous Outcomes The Distribution Analysis menu option can do basic plots. Continuous variables

79 The resolution of the histogram is okay but the others are unacceptable.

80 Use sgplot for high resolution plots. Continuous variables

81 As you add more requests to the plot, it resizes and shifts things to make room. It draws them in the order you request them. It reads the requests from the first listed to the bottom. Change the order if you want to have an item appear layered on top of, or behind, another thing. Some colors are not set yet in the enhanced editor. Use the menu Tools>Options>Enhanced Editor… then click User Defined Keywords to add the coloring.

82 I want the title!

83 How is that made? proc format library = work; value $smoked "Non-smoker" = "None " missing = "Missing" other = "Not none" ; run; data fram; set sashelp.heart; smokin = put(smoking_Status, $smoked.); run;

84 How is that made? title "5209 Cholesterol Measures from Framingham Heart Study"; proc sgplot data = fram tmplout="c:\blah\plate.sas"; histogram cholesterol; density cholesterol / type = kernel; density cholesterol / type = normal; keylegend / location=inside position=topright across=1; run; Make a new graphics template

85 proc template; define statgraph sgplotFram; begingraph /; EntryTitle "5209 Cholesterol Measures from Framingham Heart Study" /; layout overlay; Histogram 'Cholesterol'n / primary=true binaxis=false LegendLabel="Cholesterol"; DensityPlot 'Cholesterol'n / Lineattrs=GraphFit kernel() LegendLabel="Kernel" NAME="DENSITY"; DensityPlot 'Cholesterol'n / Lineattrs=GraphFit2 normal() LegendLabel="Normal" NAME="DENSITY1"; DiscreteLegend "DENSITY" "DENSITY1" / Location=Inside across=1 halign=right valign=top; endlayout; endgraph; end; run; proc sgrender data = work.fram template = template=sgplotFram ; run; This was saved in plate.sas. Render a graphic with the template and dataset specified. Note I changed the name of this template.

86 How to set the color for a histogram

87 proc sgplot data = fram; histogram weight / fillattrs = (color = coral); run;

88 You can also tweak the style template

89 Continuous variables

90 Violin A violin plot mirrors the shape of the histogram (density). They can be done in R. Continuous variables

91 Grouped Continuous Variables You can use the Distribution Analysis to get basic grouped plots. For better looking plots you need to write sgplot and/or sgpanel code. Grouped continuous variables

92 Request distinct graphics by subgroups. Grouped continuous variables

93 Grouped continuous variables

94 Actually this took a bit of voodoo. Grouped continuous variables

95 1 st 2 nd Grouped continuous variables

96 Double click here. Put details on the histogram tweaks here. I use/tweak nrow ncol and endpoints often. endpoints = 2 to 10 by 0.5 midpoints = Grouped continuous variables

97 Grouped continuous variables

98 Grouped continuous variables

99 I want to add in a reference line showing what is normal and put the categories in order.

100

101 Side by Side Violin Plots Grouped continuous variables

102 Paired Continuous Variables People typically show paired data with scatterplots. EG generate them: Grouped continuous variables

103 Scatter Plot Grouped continuous variables

104 Jittered Plot

105 Jitter vs. Sunflowers In R you can also do sunflower plots. Grouped continuous variables

106 Ordinary Least Squares Regression People typically plot a regression line to show a relationship between two continuous variables. Grouped continuous variables

107 Regression line You can easily add a regression line to the scatter plot.

108 proc sgplot data = fram; scatter x = height y = weight; run; proc sgplot data = fram; reg x = height y = weight; run;

109 ods listing sge = on style = statistical; proc sgplot data = fram; reg x = height y = weight / markerattrs = (color = green) lineattrs = graphdata1 (color = lime); run;

110 ods listing style = statistical; proc sgplot data = fram; reg x = height y = weight / group = sex ; run;

111 Bisquare Figure out what is an odd value and then put a weight on it to devalue it. There are many robust regression algorithms around. R and S-Plus software have them well implemented. Grouped continuous variables

112 Loess and Splines Loess is a technique essentially creates a rolling window and gets a weighted average across the values visible inside the window. Splines are curved lines that allow different amounts of stiffness to the curves. Grouped continuous variables

113 Smooth = 25 Smooth = 50 Smooth = 99

114 Proc phreg has a lot of new features but nothing major in the graphics. With phreg, if you specify ods graphics on you do not automatically get any plots. Here I request survival and cumulative hazard plots including the global confidence limits option (cl). Once again the option names are not consistent with the table names.

115 Proc lifetest can show the number at risk but the implementation is weak. It labels the groups with numbers even if the strata are character strings. You have to manually edit them and this affords ample opportunity for mistakes. I don’t see a way to change the censoring symbol in the legend. This shows the number of people at risk after 20, 40 etc days.

116 Beyond the Basic Univariate plots There are 4 SG procedures that allow you to build up complex univariate plots and do multivariate (trellis/lattice) plots.

117 Statistical Graphics Procs proc sgPlot – general plotting procedure that replaces gplot Proc sgRender – used with proc template to make totally custom plots – It replaces proc greplay proc sgScatter – lots of tools for scatterplots and scatter matrices proc sgPanel – quick and easy trellis/lattice/matrix/panel of plots

118 Grids You can produce lattices full of graphics with proc gpanel.

119

120 Spaghetti Plots Data from Singer and Willett:

121 SGPlot vs Template You can replicate everything done with proc sgplot using the template language but don’t reinvent the wheel if you don’t need to. You will want to use proc template to build custom graphics that use many panels. Proc sgplot uses statements that start like reg but template uses names like regressionplot. – Similar but not identical names… boo.

122

123

124 layout gridded = ticks do not have to align layout lattice = ticks must align

125

126