Importing Graphics for Statistical Plots

2 downloads 135 Views 6MB Size Report
Aug 10, 2006 ... London C51 Evans Gambit. London D20 Queen's Gambit Accepted. London m 18 C33 King's Gambit Accepted. London D20 Queen's Gambit ...
Importing Graphics for Statistical Plots Paul Murrell

August 10 2006

Introduction

Old hat • A statistical graphics system is most commonly used as only a

producer of graphical images.

WMF [file]

Powerpoint

R Gimp PNG [file] Web

Introduction

New hat • It is also useful to make the statistical graphics system a

consumer of graphical images.

PNG [file]

WMF [file]

Powerpoint

R Gimp PostScript [file]

PNG [file] Web

Motivation Why import graphics? • Adding company/institution logos The Level of Interest in R ●

2.0





1.5





1.0 ●

● ●

0.5







0.0



Jan

Mar

May

Jul Aug 1996

Oct

Dec

Motivation Why import graphics? • Backgrounds/watermarks Estimated Population (max.) of Bengal Tigers (in Bhutan) 250

200

150

100

50

0 1993

1996

1998

2001

Motivation Why import graphics? • Custom plotting symbols Opening Gambits of Louis Charles Mahe De La Bourdonnais

09 C38 King's Gambit Accepted 08 C38 King's Gambit Accepted London A03 Bird's Opening 06 B21 Sicilian, 2.f4 and 2.d4 London B21 Sicilian, 2.f4 and 2.d4 12 C33 King's Gambit Accepted 11 C51 Evans Gambit 03 C51 Evans Gambit London m1 C23 Bishop's Opening 13 C51 Evans Gambit 04 D20 Queen's Gambit Accepted 03 D20 Queen's Gambit Accepted London D20 Queen's Gambit Accepted 18 B30 Sicilian London C53 Giuoco Piano London D20 Queen's Gambit Accepted London m 18 C33 King's Gambit Accepted London D20 Queen's Gambit Accepted London C51 Evans Gambit 07 C51 Evans Gambit 07 C51 Evans Gambit Match C51 Evans Gambit

20

40

60

number of moves in game

80

Motivation Why import graphics? • Chart Junk! Estimated Population (max.) of Bengal Tigers (in Bhutan) 250

200

150

100

50

0 1993

1996

1998

2001

Problem Statement

Importing graphics with R • The pixmap package already provides facilities for importing

bitmap images. • We would like a mechanism for importing vector images. • vector images scale • for some images, the output will be much smaller than for a

bitmap

Solution Statement Target only PostScript • There are many (free) tools for converting to PostScript from

other formats: ghostscript and xpdf (PDF), xfig (FIG), InkScape (SVG). • PostScript is a sophisticated graphics language, so very

complex images can be represented • There is an open source interpreter for PostScript

(ghostscript) so we do not have to write an interpreter • PostScript is a programming language so we can write a

PostScript program to export other PostScript images PDF FIG SVG

InkScape ghostscript

PostScript [file]

Solution Statement

Convert to intermediate XML format • XML is plain text, but with a discoverable structure, and a

natural support for storing hierarchical information, etc ... • XML can be read by R • XML can be read by other software • XML can be produced by other software • XML can be converted to other formats (e.g., SVG) PDF FIG SVG

InkScape ghostscript

PostScript [file]

PostScriptTrace() ghostscript

RGML [file]

Solution Statement

Read into general R object • We may want to draw the picture using grid or using

traditional graphics • The image information is data; we may want to transform the

image before drawing it, or we may want to just analyse the image • These general R objects can be created from information

other than imported PostScript files PDF FIG SVG

InkScape ghostscript

PostScript [file]

PostScriptTrace() ghostscript

RGML [file]

readPicture()

"Picture" [R object]

Solution Statement

The grImport package makes it possible to import external PostScript images for use within an R plot.

PostScript [file]

PostScriptTrace() ghostscript

RGML [file]

readPicture()

"Picture" [R object]

grid.picture() grid.symbols()

Examples

%!PS-Adobe-2.0 EPSF-1.2 %%Creator: Adobe Illustrator(TM) %%For: OpenWindows Version 2 %%Title: tiger.eps ... .8 setgray clippath fill -110 -300 translate 1.1 dup scale 0 g 0 G 0 i 0 J 0 j 0.172 w 10 M []0 d 0 0 0 0 k ...

Examples

Estimated Population (max.) of Bengal Tigers (in Bhutan) 250

PostScriptTrace("tiger.ps") tiger