R Graphics using the Grid Package Sigal Blay Statistical Genetics Working Group Dept. Of Statistics and Actuarial Science Simon Fraser University January.

Slides:



Advertisements
Similar presentations
The Problem Decomposition of programs in terms of classes and in terms of crosscutting concerns are both useful, but languages based on source files allow.
Advertisements

Calling C code from R an introduction Sigal Blay Dept. of Statistics and Actuarial Science Simon Fraser University October 2004.
MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.
Lecture 3 A First Graphic Program. Features of a simple graphic program.
Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles.
Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
Advanced Manufacturing Laboratory Department of Industrial Engineering Sharif University of Technology Session # 7.
DETAILED DESIGN, IMPLEMENTATIONA AND TESTING Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
T T07-01 Sample Size Effect – Normal Distribution Purpose Allows the analyst to analyze the effect that sample size has on a sampling distribution.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
OPNET Modeler - An Introduction For COSC (taught by Dr. Osborne) - Zankar Parekh.
Invitation to Computer Science 5th Edition
The NetBeans IDE CSIS 3701: Advanced Object Oriented Programming.
CSC 113 Java Programming II
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington GUI and the UI API COMP.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington While loops and the UI API.
Computer Graphics Lecture 1 July 11, Computer Graphics What do you think of? The term “computer graphics” is a blanket term used to refer to the.
10/9/20151 Unreal Basics CIS 488/588 Bruce R. Maxim UM-Dearborn.
MULTIMEDIA Is the presentation of information by a computer system using graphics, animation, sound and text.
Invitation to Computer Science 5 th Edition Chapter C++ Programming in C++
General Purpose Packages GRAPHICS Chapter 5. General Purpose Packages Features of Graphics Packages Entering text Entering text Common tools Common tools.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Java.  In java you can paint your own custom drawing (such as graphs, charts, drawings and, in particular, computer games) because you cannot find standard.
1 Towards a common statistical enterprise architecture Ongoing process reengineering at Statistics Sweden Service Oriented Architecture – SOA Sharing of.
©GoldSim Technology Group LLC., 2012 Dashboards August 2012 Webinar By Jason Lillywhite.
Creating Vectors – Part One 2.02 Understand Digital Vector Graphics.
LING 408/508: Programming for Linguists Lecture 23 November 25 th.
Documenting a function. Documenting a function definition We have a template for information that we need you to put at the top of each function - if.
1 MEMB113: ENGINEERING GRAPHICS & CAE 13 ASSEMBLY AND DETAIL DRAWING.
DETAILED DESIGN, IMPLEMENTATION AND TESTING Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Institute for Visualization and Perception Research 1 © Copyright 2000 Haim Levkowitz Raster graphics alg’s for drawing 2D primitives Points of view Application.
Hierarchical Modeling.  Explain the 3 different types of model for which computer graphics is used for.  Differentiate the 2 different types of entity.
1 Quiz Manager – Detail Steps. 2 Materials License Quiz Manager Create a new multiple choice or short answer quiz Reuse previously created quizzes Edit.
Kansas State University Department of Computing and Information Sciences CIS 736: Computer Graphics Friday, January 21, 2000 William H. Hsu Department.
Volumize3d Volumize3d Training Lesson 6 - Planner.
Invitation to Computer Science 5 th Edition Chapter Ada Programming in Ada.
Computer Graphics Lecture 1. Books D. Hearn, M. P. Baker, "Computer Graphics with OpenGL", 3rd Ed., Prentice Hall, 2003, ISBN
1 Section 11.4 Java Interfaces – The Implementation Perspective Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
MUTHER’S GRID MIS 373: Basic Operations Management1 Dept. 1 Dept 2. Dept 3. Dept 4. Dept. 5 Dept 6. A A A.
Overview of R and ggplot2 for graphics
Sinhala Language Support for Java Micro Edition
Java Programming: From Problem Analysis to Program Design,
Introduction to D3.js and Bar Chart in D3.js
Structure Modelling.
Muhammad Saif ur Rehman
التسعير الفصل الرابع عشر.
eBooks & audiobooks … from your library!
Standard Grade Graphic Communication Credit KI Q1.
CSV files Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
I.T.: Application By Bhupendra Ratha, Lecturer
Biology Today Third Edition
Interfaces, Classes & Objects
Page 12 Directions: C’ B B’ C A A’
Overview of R and ggplot2 for graphics
eBooks & audiobooks … from your library!
Creating Vectors – Part One
Creating Vectors – Part One
Computer Science Discoveries Unit 1 Chapter 2 Lesson 5
40% CIRCLE INFOGRAPHIC 50% 25% 15% 5%
Statistical Process Control
Internal components of a computer.
How to Draw a Regular Polygon
Graphic Organisers Blanks for completing by teachers
Today’s Schedule Today’s Schedule editable text editable text
For More Details:
FormTrap Snippets.
Today’s Schedule Today’s Schedule editable text editable text
Statistical Process Control
Today’s Schedule Today’s Schedule editable text editable text
Presentation transcript:

R Graphics using the Grid Package Sigal Blay Statistical Genetics Working Group Dept. Of Statistics and Actuarial Science Simon Fraser University January 2006

Grid Low level graphics system Produces editable graphical components (not just graphics output) Object Oriented - graphical components can be reused and recombined

A standard set of graphical primitives: grid.rect(...) grid.lines(...) grid.polygon(...) grid.circle(...) grid.text(...) library(help = grid) for details

For every function of the form grid.* there is an equivalent function *Grob that returns a graphical object but doesn't draw it on the graphics device: grid.rect(...) rectGrob(...) grid.lines(...) linesGrob(...) grid.polygon(...) polygonGrob(...) grid.circle(...) circleGrob(...) grid.text(...) textGrob(..) Usage: Rect <- rectGrob(...) grid.draw(Rect)

Graphical output can be positioned and sized relative to a large number of coordinate systems grid.rect(x = unit(0, “native"), y = unit(1.5, “npc"), height = unit(0.5, "inches"), width = unit(0.8, “lines”)) help(unit) for details

Can specify various graphical parameters grid.rect(gp=gpar(col="red", lwd=2, fill="yellow", lty="dotted")) grid.text(gp=gpar(col="red", fontsize=10, fontface="italic")) help(gpar) for details

Working with viewports All drawing occurs in the current grid viewport, a defined rectangular region with it's own defined coordinate system: vp <- viewport(width=0.5, height=0.2, angle=45) grid.show.viewport(vp) help(viewport) for details

vp <- viewport(width=0.5, height=0.2, angle=45, name="VP") pushViewport(vp) grid.rect() popViewport()

vp <- viewport(width=0.5, height=0.2, angle=45, name="VP") pushViewport(vp) grid.rect() grid.xaxis() grid.yaxis()

vp <- viewport(width=0.5, height=0.2, angle=45, name="VP") pushViewport(vp) grid.rect() grid.xaxis() grid.yaxis() grid.text("viewport region", y = 0.9)

vp <- viewport(width=0.5, height=0.2, angle=45, name="VP") pushViewport(vp) grid.rect() grid.xaxis() grid.yaxis() grid.text("viewport region", y = 0.9) upViewport() grid.text("root region",y = 0.1)

vp <- viewport(width=0.5, height=0.2, angle=45, name="VP") pushViewport(vp) grid.rect() grid.xaxis() grid.yaxis() grid.text("viewport region", y = 0.9) upViewport() grid.text("root region",y = 0.1) grid.text("more text", vp="VP“ y=0.7)

Query the viewport tree > current.viewport() viewport[ROOT] > current.vpTree() viewport[ROOT]->(viewport[VP]) > downViewport("VP") > popViewport() > current.vpTree() viewport[ROOT]

Can push multiple viewport pushViewport(vpList(vp1, vp2, vp3)) Can push nested viewports pushViewport(vpStack(vp1, vp2, vp3)) pushViewport(vpTree(vp1, vpList(vp2, vp3))) Can integrate with a layout

plotViewport(...) a convenience function for producing a viewport with a central plot region surrounded by margins given in terms of a number of lines of text. dataViewport(...) a convenience function for producing a viewport with x- and/or y-scales based on numeric values passed to the function.

grid creates graphical objects ( grobs ): grid.rect(..., name="box") grid.circle(...) grid.edit("box", gp=gpar(fill="yellow")) grid.remove("box") 

gTree – a tree of grobs vp<-viewport(..., name="view") x <- xaxisGrob(name = "axis1") y <- yaxisGrob(name = "axis2") points <- pointsGrob(1:9, 1:9, name="dataPoints") title <- textGrob(..., name="myTitle") tree <- gTree(name="Tree”, vp=vp, children=gList(x,y,title,points)) grid.draw(tree)

Query and edit a gTree > getNames() # list all top-level grobs [1] "Tree“ > childNames(tree) [1] "axis1" "axis2" "myTitle“ "dataPoints" > childNames(grid.get("Tree")) [1] "axis1" "axis2" "myTitle“ "dataPoints" > grid.add("Tree", grid.rect()) > grid.edit(gPath("Tree","dataPoints"), pch=2)

Example: LDheatmap package Plots measures of pairwise linkage disequilibria for SNPs

> getNames() [1] "ldheatmap" > childNames(grid.get("ldheatmap")) [1] "heatMap" "geneMap" "Key“ > childNames(grid.get("heatMap")) [1] "heatmap" "title" > childNames(grid.get("geneMap")) [1] "diagonal" "segments" "title" "symbols“ "SNPnames" > childNames(grid.get("Key")) [1] "colorKey" "title" "labels" "ticks” "box"

grid.edit("symbols", pch=20, gp=gpar(cex=2)) grid.edit(gPath("ldheatmap","heatMap","title"), gp=gpar(col="red")) grid.edit(gPath("ldheatmap","heatMap","heatmap“), gp=gpar(col="white", lwd=2)) 

Conclusion the R grid package enables the production of reusable and flexible graphical components

Further reading R Graphics / Paul Murrell