[R] grImport symbols

baptiste auguie baptiste.auguie at googlemail.com
Sun Jul 31 01:03:35 CEST 2011


Dear list,

I have two questions regarding grid.symbols() in the grImport package.
This package allows you to import a vector graphic in R, and
grid.symbols() can be used to plot the resulting glyph at arbitrary
locations in a grid viewport.

I have tried the code in the grImport vignette, which is most
interesting, however I am stuck with two problems:

1- Is there a possibility to create a Picture object directly from R
without importing an external image, but rather specified as a regular
grob/gTree, say. I would like to imitate my.symbols from
TeachingDemos, but with grid.

2- I could not figure out what the size argument in grid.symbols()
does. The following example fails rather curiously.

petal.ps <- "%!PS
newpath % start a new shape
0 0 moveto % move to a start location
-5 10 lineto % line to a new location
-10 20 10 20 5 10 curveto % curve to a third location
5 10 lineto % line to a fourth location
closepath % connect back to the start location
0 setgray % set the drawing colour to black
fill % fill the current shape"

cat(petal.ps, file="petal.ps")
library(grImport)
PostScriptTrace("petal.ps")
petal <- readPicture("petal.ps.xml")

grid.symbols(petal, 1:10/10, 1:10/10, size=0.1) # OK

grid.symbols(petal, 1:10/10, 1:10/10, size = seq(0.01, 0.1,
length=10)) # Warning and weird shapes

sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  grid
methods   base

other attached packages:
[1] grImport_0.7-3 XML_3.4-0      ggplot2_0.8.9  proto_0.3-9.2  reshape_0.8.4
[6] plyr_1.5.2

loaded via a namespace (and not attached):
[1] tools_2.13.1

Best regards,

baptiste



More information about the R-help mailing list