THE GRAMMAR OF GRAPHICS USING GGPLOT 2 TO







- Slides: 7

THE GRAMMAR OF GRAPHICS USING GGPLOT 2 TO CREATE INFORMATIVE AND BEAUTIFUL GRAPHICS IN R, EASILY

INTRODUCTION THE PAINFUL PROCESS OF CREATING GRAPHS IN SPSS § Creating complicated graphs in SPSS is possible, but very tedious. § Total time; ~12 hours. § Hard to change details Figure 19; Reforms (t 0) by attitudes on Redistribution, within EVS waves. Footer text: to modify choose 'Insert' (or ‘View’ for Office 2003 or earlier) then 'Header and footer' 18 december 2021 2

PLOTTING IN R § The basic R functions create functional plots, but are again quite limited. § Creating trellis plots for complicated datasets with various graphical layers is time-consuming and requires programming experience. § Lattice helps, and can be used to create anything you might desire… § However, this will probably require writing custom panel functions, and can become difficult very quickly. Footer text: to modify choose 'Insert' (or ‘View’ for Office 2003 or earlier) then 'Header and footer' 18 december 2021 3

THE GRAMMAR OF GRAPHICS LELAND WILKINSON’S APPROACH § Created by Leland Wilkinson, when working (ironically) for SPSS § Ggplot 2 is a (sometimes loose) implementation in R by Hadley Wickham § Create plots not by choosing a chart, but by rules about the building blocks that make a graphic, written in the ‘grammar’ of graphics. § Make graphics easier § Grammar instead of preset plots facilitate innovative display options Footer text: to modify choose 'Insert' (or ‘View’ for Office 2003 or earlier) then 'Header and footer' 18 december 2021 4

EXAMPLE WHAT IS A PIE CHART? § How would you describe a pie chart to someone who has never seen one? § A pie chart is a stacked barchart with polar coordinates § With ggplot, the difference is “+ coord_polar(theta="y")” Footer text: to modify choose 'Insert' (or ‘View’ for Office 2003 or earlier) then 'Header and footer' 18 december 2021 5

EXAMPLES IN R § Extremely easy to overlay different graphical elements and statistical transformations § Very, very many different applications. (Try doing a google search) § Themes can be created and applied to easily create plots with the same ‘look and feel’ (not in my presentation, homework? ) Footer text: to modify choose 'Insert' (or ‘View’ for Office 2003 or earlier) then 'Header and footer' 18 december 2021 6

HELPFUL RESOURCES § Ggplot 2 documentation: http: //docs. ggplot 2. org/current/ § Cookbook; http: //www. cookbook-r. com/Graphs/ § Presentation by creator of ggplot 2, examples and philosophy; http: //www. slideshare. net/hadley/grammar-of-graphics-past-presentfuture § Google, stack overflow, R mailing lists. Footer text: to modify choose 'Insert' (or ‘View’ for Office 2003 or earlier) then 'Header and footer' 18 december 2021 7