r graph ics can r draw graphs
play

R graph ics Can R Draw Graphs? My first peer review experience ... - PowerPoint PPT Presentation

R graph ics Can R Draw Graphs? My first peer review experience ... Paul Murrell Reviewers comments The University of Auckland An obvious reject, trivial, with no research component. June 17 2006 The article was accepted! R graph ics


  1. R graph ics Can R Draw Graphs? My first peer review experience ... Paul Murrell Reviewer’s comments The University of Auckland “An obvious reject, trivial, with no research component.” June 17 2006 The article was accepted! R graph ics Overview The article was called “Layouts: a mechanism for arranging plots Some new graphics features in R on a page” ... plots not graphs . ( ... with some applications to arranging graphs ) FifthEd ● 1 New drawing primitives: PWB1.0 SixthEd ● ● MiniUnix • X-splines. ● USG1.0 ● PWB1.2 ● • Connectors. Wollongong Interdata LSX ● ● USG2.0 ● 3 ● BSD1 ● • Clipping. CB.Unix.1 ● ● PWB2.0 ● SeventhEd ● USG3.0 Xenix ● 2 ● ● 2 New ways to query graphical objects: ● V32 ● ● CB.Unix.2 ● ● BSD2 ● ● ● Uniplus ● ● 1 ● ● ● ● Unix.TS3.0 Unix.TS1.0 V7M • grobX() ● BSD3 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● Unix.TS.PP 0 ● CB.Unix.3 ● ● ● • grobY() ● ● BSD4 ● ● ● ● ● ● ● ● ● ● TS4.0 −1 ● ● ● ● ● 3 Importing graphics into R: ● BSD4.1 ● ● PDP11.SysV EigthEd ● ● −2 ● SystemV.0 ● ● BSD2.8 ● BSD4.2 • The grImport package. ● SystemV.2 ● −3 NinethEd ● ● BSD4.3 BSD2.9 Ultrix32 Ultrix11 SystemV.3 ● ● −3 −2 −1 0 1 2 3 ● ● ●

  2. X-splines grid.xspline() Splines are smooth curves drawn relative to a set of control Control points are specified as x and y locations, a shape points . Examples are Catmull-Rom splines, where the curve parameter specifies interpolation or approximation at each control interpolates the control points, and B-splines, where the curve point, and the x-spline can be open or closed. It is also possible to approximates the control points. add an arrow to either end of an open spline. An X-spline is a smooth curve drawn relative to a set of control Open Splines Closed Splines −1 −1 −1 0 −1 1 −1 −1 −1 0 −1 1 points, where each control point has a parameter indicating ● ● ● ● ● ● ● ● ● ● ● ● whether the curve should interpolate or approximate that particular ● ● ● ● ● ● ● ● ● ● ● ● 0 0 0 0 0 0 −1 −1 −1 −1 −1 −1 control point. 0 −1 0 0 0 1 0 −1 0 0 0 1 ● ● ● ● ● ● ● ● ● ● ● ● X-splines have been implemented in the grid package for R 2.3.0, ● ● ● ● ● ● ● ● ● ● ● ● 0 0 0 0 0 0 0 0 0 0 0 0 1 −1 1 0 1 1 1 −1 1 0 1 1 via the grid.xspline() function. ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 0 0 0 0 0 0 1 1 1 1 1 1 grid.xspline(x, y, id, id.lengths, default.units, shape, open, arrow, repEnds, name, gp, vp) Applications of X-Splines Connectors • A more interesting“pointer”from a label to a feature of interest. • Unusual shapes. A connector is a curve drawn between two points. The function grid.curve() draws a range of connectors. It's boring I'm snoring I don't like your drawing ● (with apologies to "It's raining, it's pouring") grid.curve(x1, y1, x2, y2, default.units, curvature, angle, ncp, shape, Sing a song of sixpence Oranges and lemons square, squareShape, inflect, Jack and Jill arrow, debug, name, gp, vp) Humpty Dumpty Hey diddle diddle 1600 1650 1700 1750 1800 year (with apologies to "Hickory Dickory Dock") ● Whether you like it or not Your eye is drawn to this spot

  3. Connectors Querying Graphical Objects It has always been possible to determine the width and height of graphical output via grobWidth() and grobHeight() . This is useful for doing things like placing decorations around text. (NULL) (inflect = TRUE) (angle = 135) ● ● Hello world (NULL) (inflect = TRUE) (angle = 135) (arrow = arrow()) (ncp = 8) (shape = 0) (arrow = arrow()) (ncp = 8) (shape = 0) It is now also possible to determine locations on the boundary of (curvature = −1) (square = FALSE) (debug = TRUE) graphical output via grobX() and grobY() . ● (curvature = −1) (square = FALSE) (debug = TRUE) ● ● ● ● ● ● ● ● ● ● ● ● ● grobX(x, theta) ● ● ● ● grobY(x, theta) ● ● ● Flow Diagrams Clipping It has always been possible to clip graphical output to a grid The combination of connectors and being able to determine the viewport. This is typically done, for example, to ensure that boundary points of objects makes it possible to create simple flow plotted data do not“spill”outside the plotting region. diagrams in R. It is now also possible to change the clipping region within a hex(.5, .8, name="h1") viewport, via the grid.clip() function. hex(.5, .6, name="h2") D ... A grid.curve(grobX("h2", 180), B grobY("h2", 180), ● ● ● 2 2 2 grobX("h1", 180), C ● ● ● ● ● ● ● ● ● 1 1 1 grobY("h1", 180), ● ● ● ● ● ● y ● y ● y ● ● ● ● ● ● ● ● ● ● shape=1, ncp=10, ● ● ● ● ● ● 0 0 0 ● ● ● ● square=FALSE, ● ● −1 ● −1 −1 ● ● ● ● ● ● ● curvature=-1, ● ● arrow=arr) 5 10 15 20 5 10 15 20 5 10 15 20 x x x ...

  4. Clipping Importing Graphics grid.clip(x, y, width, height, R graphics can be exported in many different formats, including just, hjust, vjust, PDF, PostScript, PNG, and (on Windows) WMF. This is useful, default.units, name, vp) for example, for including plots within larger reports. ... for (i in 1:length(year)) { The grImport package makes it possible to go the other direction 250 ● ● ● ● grid.clip(x=year[i], y=0, ● ● ● ● ● ● ● ● and import external graphics images for use within an R plot. ● ● ● ● 200 ● ● ● ● ● ● ● ● width=1, ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● height=maxpop[i], 150 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● "native", ● ● ● ● ● ● 100 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● just="bottom") ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 50 PostScriptTrace() readPicture() grid.picture() ● ● ● ● ● ● ● ● PostScript RGML "picture" # pattern fill ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● [file] [file] [R object] ● ● ● ● ● ● ● ● ghostscript grid.symbols() 0 ● ● ● ● ● ● ● ● gridPattern() 1993 1996 1998 2001 } ... The PostScript Bezier Tiger Importing the Tiger %!PS-Adobe-2.0 EPSF-1.2 %%Creator: Adobe Illustrator(TM) %%For: OpenWindows Version 2 %%Title: tiger.eps ... .8 setgray clippath fill PostScriptTrace("tiger.ps") -110 -300 translate 1.1 dup scale tiger <- 0 g readPicture("tiger.ps.xml") 0 G 0 i 0 J 0 j 0.172 w 10 M []0 d 0 0 0 0 k ...

  5. Using the Tiger as a Plot Backdrop A Chess Board <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG" "http://www.w3.org/TR/2001/REC-SVG..."> Estimated Population (max.) of Bengal Tigers <!-- Created with Sodipodi --> (in Bhutan) <svg version="1.0"> 250 ... pushViewport(plotViewport()) <g style="font-size:12;" ... 200 id="g874"> grid.rect() <path d="M 0 437 L 437 0 " 150 grid.xaxis(at=year) style="fill:none;fill-opacity:1" id="path616" /> grid.yaxis() ... 100 ... grid.picture(tiger) 50 # Convert SVG to PostScript ... # using InkScape 0 popViewport() 1993 1996 1998 2001 PostScriptTrace("chess.ps") chess <- readPicture("chess.ps.xml") The Paths in the Chess Board A Chess Piece as a Plotting Symbols The picturePaths() function draws individual paths from a The number of moves required to complete chess games for picture, which makes it possible to identify elements of a picture. different opening gambits. From the career of Louis Charles Mahe De La Bourdonnais (circa 1830). "picture" objects can be subsetted, which makes it possible to extract elements of a picture. London m1 C23 Bishop's Opening 06 B21 Sicilian, 2.f4 and 2.d4 London C53 Giuoco Piano picturePaths(chess[125:136]) 04 D20 Queen's Gambit Accepted 07 C51 Evans Gambit 18 B30 Sicilian London D20 Queen's Gambit Accepted grid.symbols( 12 C33 King's Gambit Accepted London C51 Evans Gambit chess[205:206], 03 C51 Evans Gambit London D20 Queen's Gambit Accepted x=games$num.moves, 13 C51 Evans Gambit London D20 Queen's Gambit Accepted y=1:ngames, 08 C38 King's Gambit Accepted 11 C51 Evans Gambit "native", London A03 Bird's Opening 09 C38 King's Gambit Accepted size=unit(0.5, "cm")) London B21 Sicilian, 2.f4 and 2.d4 03 D20 Queen's Gambit Accepted London m 18 C33 King's Gambit Accepted Match C51 Evans Gambit 07 C51 Evans Gambit 20 40 60 80

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend