The R Project SVN R

Rev

Rev 86192 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
56186 murdoch 1
 
89461 maechler 2
R Under development (unstable) (2026-02-10 r89394) -- "Unsuffered Consequences"
3
Copyright (C) 2026 The R Foundation for Statistical Computing
85945 ripley 4
Platform: aarch64-apple-darwin23.3.0
56186 murdoch 5
 
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
7
You are welcome to redistribute it under certain conditions.
8
Type 'license()' or 'licence()' for distribution details.
9
 
10
R is a collaborative project with many contributors.
11
Type 'contributors()' for more information and
12
'citation()' on how to cite R or R packages in publications.
13
 
14
Type 'demo()' for some demos, 'help()' for on-line help, or
15
'help.start()' for an HTML browser interface to help.
16
Type 'q()' to quit R.
17
 
18
> pkgname <- "grid"
19
> source(file.path(R.home("share"), "R", "examples-header.R"))
20
> options(warn = 1)
21
> library('grid')
22
> 
61787 ripley 23
> base::assign(".oldSearch", base::search(), pos = 'CheckExEnv')
73819 hornik 24
> base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv')
56186 murdoch 25
> cleanEx()
26
> nameEx("Grid")
27
> ### * Grid
28
> 
29
> flush(stderr()); flush(stdout())
30
> 
31
> ### Name: Grid
32
> ### Title: Grid Graphics
33
> ### Aliases: Grid
34
> ### Keywords: dplot
35
> 
36
> ### ** Examples
37
> 
61435 ripley 38
> ## Diagram of a simple layout
56186 murdoch 39
> grid.show.layout(grid.layout(4,2,
40
+                      heights=unit(rep(1, 4),
41
+                                   c("lines", "lines", "lines", "null")),
42
+                      widths=unit(c(1, 1), "inches")))
43
> ## Diagram of a sample viewport
44
> grid.show.viewport(viewport(x=0.6, y=0.6,
80081 hornik 45
+                             width=unit(1, "inches"), height=unit(1, "inches")))
56186 murdoch 46
> ## A flash plotting example
47
> grid.multipanel(vp=viewport(0.5, 0.5, 0.8, 0.8))
48
> 
49
> 
50
> 
51
> cleanEx()
52
> nameEx("arrow")
53
> ### * arrow
54
> 
55
> flush(stderr()); flush(stdout())
56
> 
57
> ### Name: arrow
84536 smeyer 58
> ### Title: Describe arrows to add to a line
56186 murdoch 59
> ### Aliases: arrow
60
> ### Keywords: dplot
61
> 
62
> ### ** Examples
63
> 
64
> arrow()
65
$angle
66
[1] 30
67
 
68
$length
69
[1] 0.25inches
70
 
71
$ends
72
[1] 2
73
 
74
$type
75
[1] 1
76
 
77
attr(,"class")
78
[1] "arrow"
86192 maechler 79
> str(arrow(type = "closed"), give.attr=FALSE)
80
"arrow" (pkg {grid}) object:
81
 $ angle : num 30
82
 $ length: 'simpleUnit' num 0.25inches
83
 $ ends  : int 2
84
 $ type  : int 2
56186 murdoch 85
> 
86
> 
87
> 
88
> cleanEx()
81257 murrell 89
> nameEx("as.mask")
90
> ### * as.mask
91
> 
92
> flush(stderr()); flush(stdout())
93
> 
94
> ### Name: as.mask
95
> ### Title: Define a Soft Mask
96
> ### Aliases: as.mask
97
> ### Keywords: dplot
98
> 
99
> ### ** Examples
100
> 
101
> ## NOTE: on devices without support for masks normal line segments 
102
> ##       will be drawn
103
> grid.newpage()
104
> ## Alpha mask
105
> grid.segments(y0=1, y1=0, gp=gpar(col=2, lwd=100))
106
> pushViewport(viewport(mask=circleGrob(gp=gpar(fill=rgb(0,0,0,.5)))))
107
> grid.segments(gp=gpar(col=3, lwd=100))
108
> grid.newpage()
109
> ## Luminance mask
110
> grid.segments(y0=1, y1=0, gp=gpar(col=2, lwd=100))
111
> pushViewport(viewport(mask=as.mask(circleGrob(gp=gpar(fill="grey50")),
112
+                                    "luminance")))
113
> grid.segments(gp=gpar(col=3, lwd=100))
114
> 
115
> 
116
> 
117
> cleanEx()
57578 ripley 118
> nameEx("calcStringMetric")
119
> ### * calcStringMetric
120
> 
121
> flush(stderr()); flush(stdout())
122
> 
123
> ### Name: calcStringMetric
124
> ### Title: Calculate Metric Information for Text
125
> ### Aliases: calcStringMetric
126
> ### Keywords: dplot
127
> 
128
> ### ** Examples
129
> 
130
> grid.newpage()
131
> grid.segments(.01, .5, .99, .5, gp=gpar(col="grey"))
132
> metrics <- calcStringMetric(letters)
133
> grid.rect(x=1:26/27,
134
+           width=unit(metrics$width, "inches"),
135
+           height=unit(metrics$ascent, "inches"),
136
+           just="bottom",
137
+           gp=gpar(col="red"))
138
> grid.rect(x=1:26/27,
139
+           width=unit(metrics$width, "inches"),
140
+           height=unit(metrics$descent, "inches"),
141
+           just="top",
142
+           gp=gpar(col="red"))
143
> grid.text(letters, x=1:26/27, just="bottom")
144
> 
145
> test <- function(x) {
146
+     grid.text(x, just="bottom")
147
+     metric <- calcStringMetric(x)
148
+     if (is.character(x)) {
149
+         grid.rect(width=unit(metric$width, "inches"),
150
+                   height=unit(metric$ascent, "inches"),
151
+                   just="bottom",
152
+                   gp=gpar(col=rgb(1,0,0,.5)))
153
+         grid.rect(width=unit(metric$width, "inches"),
154
+                   height=unit(metric$descent, "inches"),
155
+                   just="top",
156
+                   gp=gpar(col=rgb(1,0,0,.5)))
157
+     } else {
158
+         grid.rect(width=unit(metric$width, "inches"),
159
+                   y=unit(.5, "npc") + unit(metric[2], "inches"),
160
+                   height=unit(metric$ascent, "inches"),
161
+                   just="bottom",
162
+                   gp=gpar(col=rgb(1,0,0,.5)))
163
+         grid.rect(width=unit(metric$width, "inches"),
164
+                   height=unit(metric$descent, "inches"),
165
+                   just="bottom",
61435 ripley 166
+                   gp=gpar(col=rgb(1,0,0,.5)))
57578 ripley 167
+     }
168
+ }
169
> 
170
> tests <- list("t",
171
+               "test",
172
+               "testy",
173
+               "test\ntwo",
174
+               expression(x),
175
+               expression(y),
176
+               expression(x + y),
177
+               expression(a + b),
178
+               expression(atop(x + y, 2)))
179
> 
180
> grid.newpage()
181
> nrowcol <- n2mfrow(length(tests))
182
> pushViewport(viewport(layout=grid.layout(nrowcol[1], nrowcol[2]),
183
+                       gp=gpar(cex=5, lwd=.5)))
184
> for (i in 1:length(tests)) {
185
+     col <- (i - 1) %% nrowcol[2] + 1
186
+     row <- (i - 1) %/% nrowcol[2] + 1
187
+     pushViewport(viewport(layout.pos.row=row, layout.pos.col=col))
188
+     test(tests[[i]])
189
+     popViewport()
190
+ }
191
> 
192
> 
193
> 
194
> 
195
> cleanEx()
56186 murdoch 196
> nameEx("current.viewport")
197
> ### * current.viewport
198
> 
199
> flush(stderr()); flush(stdout())
200
> 
201
> ### Name: Querying the Viewport Tree
202
> ### Title: Get the Current Grid Viewport (Tree)
63911 murrell 203
> ### Aliases: current.viewport current.parent current.vpTree current.vpPath
204
> ###   current.transform current.rotation
56186 murdoch 205
> ### Keywords: dplot
206
> 
207
> ### ** Examples
208
> 
209
> grid.newpage()
210
> pushViewport(viewport(width=0.8, height=0.8, name="A"))
211
> pushViewport(viewport(x=0.1, width=0.3, height=0.6,
212
+   just="left", name="B"))
213
> upViewport(1)
214
> pushViewport(viewport(x=0.5, width=0.4, height=0.8,
215
+   just="left", name="C"))
216
> pushViewport(viewport(width=0.8, height=0.8, name="D"))
217
> current.vpPath()
81257 murrell 218
GRID.VP.69::A::C::D 
56186 murdoch 219
> upViewport(1)
220
> current.vpPath()
81257 murrell 221
GRID.VP.69::A::C 
56186 murdoch 222
> current.vpTree()
81257 murrell 223
viewport[ROOT]->(viewport[GRID.VP.69]->(viewport[A]->(viewport[B], viewport[C]->(viewport[D])))) 
56186 murdoch 224
> current.viewport()
225
viewport[C] 
226
> current.vpTree(all=FALSE)
227
viewport[C]->(viewport[D]) 
228
> popViewport(0)
229
> 
230
> 
231
> 
232
> cleanEx()
63911 murrell 233
> nameEx("depth")
234
> ### * depth
235
> 
236
> flush(stderr()); flush(stdout())
237
> 
238
> ### Name: depth
84536 smeyer 239
> ### Title: Determine the number of levels in an object
63911 murrell 240
> ### Aliases: depth depth.viewport depth.path
241
> ### Keywords: dplot
242
> 
243
> ### ** Examples
244
> 
245
> vp <- viewport()
246
> depth(vp)
247
[1] 1
248
> depth(vpStack(vp, vp))
249
[1] 2
250
> depth(vpList(vpStack(vp, vp), vp))
251
[1] 1
252
> depth(vpPath("vp"))
253
[1] 1
254
> depth(vpPath("vp1", "vp2"))
255
[1] 2
256
> 
257
> 
258
> 
259
> cleanEx()
74634 murrell 260
> nameEx("deviceLoc")
261
> ### * deviceLoc
262
> 
263
> flush(stderr()); flush(stdout())
264
> 
265
> ### Name: deviceLoc
266
> ### Title: Convert Viewport Location to Device Location
267
> ### Aliases: deviceLoc deviceDim
268
> ### Keywords: dplot
269
> 
270
> ### ** Examples
271
> 
272
> ## A tautology
273
> grid.newpage()
274
> pushViewport(viewport())
275
> deviceLoc(unit(1, "inches"), unit(1, "inches"))
276
$x
77889 murrell 277
[1] 1inches
74634 murrell 278
 
279
$y
77889 murrell 280
[1] 1inches
74634 murrell 281
 
282
> 
283
> ## Something less obvious
284
> grid.newpage()
285
> pushViewport(viewport(width=.5, height=.5))
286
> grid.rect()
287
> x <- unit(1, "in")
288
> y <- unit(1, "in")
289
> grid.circle(x, y, r=unit(2, "mm"))
290
> loc <- deviceLoc(x, y)
291
> loc
292
$x
77889 murrell 293
[1] 2.7inches
74634 murrell 294
 
295
$y
77889 murrell 296
[1] 2.75inches
74634 murrell 297
 
298
> upViewport()
299
> grid.circle(loc$x, loc$y, r=unit(1, "mm"), gp=gpar(fill="black"))
300
> 
301
> ## Something even less obvious
302
> grid.newpage()
303
> pushViewport(viewport(width=.5, height=.5, angle=30))
304
> grid.rect()
305
> x <- unit(.2, "npc")
306
> y <- unit(2, "in")
307
> grid.circle(x, y, r=unit(2, "mm"))
308
> loc <- deviceLoc(x, y)
309
> loc
310
$x
77889 murrell 311
[1] 2.39165408813987inches
74634 murrell 312
 
313
$y
77889 murrell 314
[1] 3.20650635094611inches
74634 murrell 315
 
316
> upViewport()
317
> grid.circle(loc$x, loc$y, r=unit(1, "mm"), gp=gpar(fill="black"))
318
> 
319
> 
320
> 
321
> cleanEx()
63911 murrell 322
> nameEx("explode")
323
> ### * explode
324
> 
325
> flush(stderr()); flush(stdout())
326
> 
327
> ### Name: explode
84536 smeyer 328
> ### Title: Explode a path into its components
63911 murrell 329
> ### Aliases: explode explode.character explode.path
330
> ### Keywords: dplot
331
> 
332
> ### ** Examples
333
> 
334
> explode("vp1::vp2")
335
[1] "vp1" "vp2"
336
> explode(vpPath("vp1", "vp2"))
337
[1] "vp1" "vp2"
338
> 
339
> 
340
> 
341
> cleanEx()
56186 murdoch 342
> nameEx("gEdit")
343
> ### * gEdit
344
> 
345
> flush(stderr()); flush(stdout())
346
> 
347
> ### Name: gEdit
348
> ### Title: Create and Apply Edit Objects
349
> ### Aliases: gEdit gEditList applyEdit applyEdits
350
> ### Keywords: dplot
351
> 
352
> ### ** Examples
353
> 
354
> grid.rect(gp=gpar(col="red"))
355
> # same thing, but more verbose
356
> grid.draw(applyEdit(rectGrob(), gEdit(gp=gpar(col="red"))))
357
> 
358
> 
359
> 
360
> cleanEx()
361
> nameEx("gPath")
362
> ### * gPath
363
> 
364
> flush(stderr()); flush(stdout())
365
> 
366
> ### Name: gPath
367
> ### Title: Concatenate Grob Names
368
> ### Aliases: gPath
369
> ### Keywords: dplot
370
> 
371
> ### ** Examples
372
> 
373
> gPath("g1", "g2")
374
g1::g2 
375
> 
376
> 
377
> 
378
> cleanEx()
379
> nameEx("getNames")
380
> ### * getNames
381
> 
382
> flush(stderr()); flush(stdout())
383
> 
384
> ### Name: getNames
385
> ### Title: List the names of grobs on the display list
386
> ### Aliases: getNames
387
> ### Keywords: dplot
388
> 
389
> ### ** Examples
390
> 
391
> grid.grill()
392
> getNames()
81257 murrell 393
[1] "GRID.text.179"     "GRID.rect.180"     "GRID.circle.181"  
394
[4] "GRID.circle.182"   "GRID.rect.183"     "GRID.rect.184"    
395
[7] "GRID.segments.185" "GRID.segments.186"
56186 murdoch 396
> 
397
> 
398
> 
399
> cleanEx()
400
> nameEx("gpar")
401
> ### * gpar
402
> 
403
> flush(stderr()); flush(stdout())
404
> 
405
> ### Name: gpar
406
> ### Title: Handling Grid Graphical Parameters
407
> ### Aliases: gpar get.gpar
408
> ### Keywords: dplot
409
> 
410
> ### ** Examples
411
> 
412
> gp <- get.gpar()
413
> utils::str(gp)
414
List of 14
415
 $ fill      : chr "transparent"
416
 $ col       : chr "black"
417
 $ lty       : chr "solid"
418
 $ lwd       : num 1
419
 $ cex       : num 1
420
 $ fontsize  : num 12
421
 $ lineheight: num 1.2
422
 $ font      : int 1
423
 $ fontfamily: chr ""
424
 $ alpha     : num 1
425
 $ lineend   : chr "round"
426
 $ linejoin  : chr "round"
427
 $ linemitre : num 10
428
 $ lex       : num 1
429
 - attr(*, "class")= chr "gpar"
430
> ## These *do* nothing but produce a "gpar" object:
431
> gpar(col = "red")
432
$col
433
[1] "red"
434
 
435
> gpar(col = "blue", lty = "solid", lwd = 3, fontsize = 16)
436
$col
437
[1] "blue"
438
 
439
$lty
440
[1] "solid"
441
 
442
$lwd
443
[1] 3
444
 
445
$fontsize
446
[1] 16
447
 
448
> get.gpar(c("col", "lty"))
449
$col
450
[1] "black"
451
 
452
$lty
453
[1] "solid"
454
 
455
> grid.newpage()
80081 hornik 456
> vp <- viewport(width = .8, height = .8, gp = gpar(col="blue"))
56186 murdoch 457
> grid.draw(gTree(children=gList(rectGrob(gp = gpar(col="red")),
458
+                      textGrob(paste("The rect is its own colour (red)",
459
+                                     "but this text is the colour",
460
+                                     "set by the gTree (green)",
461
+                                     sep = "\n"))),
462
+       gp = gpar(col="green"), vp = vp))
463
> grid.text("This text is the colour set by the viewport (blue)",
464
+           y = 1, just = c("center", "bottom"),
465
+           gp = gpar(fontsize=20), vp = vp)
466
> grid.newpage()
467
> ## example with multiple values for a parameter
468
> pushViewport(viewport())
469
> grid.points(1:10/11, 1:10/11, gp = gpar(col=1:10))
470
> popViewport()
471
> 
472
> 
473
> 
474
> cleanEx()
57725 murrell 475
> nameEx("grid.DLapply")
476
> ### * grid.DLapply
477
> 
478
> flush(stderr()); flush(stdout())
479
> 
480
> ### Name: grid.DLapply
481
> ### Title: Modify the Grid Display List
482
> ### Aliases: grid.DLapply
483
> ### Keywords: dplot
484
> 
485
> ### ** Examples
486
> 
487
> grid.newpage()
63911 murrell 488
> grid.rect(width=.4, height=.4, x=.25, y=.75, gp=gpar(fill="black"), name="r1")
489
> grid.rect(width=.4, height=.4, x=.5, y=.5, gp=gpar(fill="grey"), name="r2")
490
> grid.rect(width=.4, height=.4, x=.75, y=.25, gp=gpar(fill="white"), name="r3")
57725 murrell 491
> grid.DLapply(function(x) { if (is.grob(x)) x$gp <- gpar(); x })
492
NULL
493
> grid.refresh()
494
> 
495
> 
496
> 
497
> cleanEx()
498
> nameEx("grid.bezier")
499
> ### * grid.bezier
500
> 
501
> flush(stderr()); flush(stdout())
502
> 
503
> ### Name: grid.bezier
504
> ### Title: Draw a Bezier Curve
505
> ### Aliases: grid.bezier bezierGrob
506
> ### Keywords: dplot
507
> 
508
> ### ** Examples
509
> 
510
> x <- c(0.2, 0.2, 0.4, 0.4)
511
> y <- c(0.2, 0.4, 0.4, 0.2)
512
> 
513
> grid.newpage()
514
> grid.bezier(x, y)
515
> grid.bezier(c(x, x + .4), c(y + .4, y + .4),
516
+             id=rep(1:2, each=4))
517
> grid.segments(.4, .6, .6, .6)
518
> grid.bezier(x, y,
519
+             gp=gpar(lwd=3, fill="black"),
520
+             arrow=arrow(type="closed"),
521
+             vp=viewport(x=.9))
522
> 
523
> 
524
> 
525
> cleanEx()
56186 murdoch 526
> nameEx("grid.cap")
527
> ### * grid.cap
528
> 
529
> flush(stderr()); flush(stdout())
530
> 
531
> ### Name: grid.cap
532
> ### Title: Capture a raster image
533
> ### Aliases: grid.cap
534
> ### Keywords: dplot
535
> 
536
> ### ** Examples
537
> 
538
> 
539
> 
540
> 
541
> cleanEx()
542
> nameEx("grid.clip")
543
> ### * grid.clip
544
> 
545
> flush(stderr()); flush(stdout())
546
> 
547
> ### Name: grid.clip
548
> ### Title: Set the Clipping Region
549
> ### Aliases: grid.clip clipGrob
550
> ### Keywords: dplot
551
> 
552
> ### ** Examples
553
> 
554
> # draw across entire viewport, but clipped
555
> grid.clip(x = 0.3, width = 0.1)
556
> grid.lines(gp=gpar(col="green", lwd=5))
557
> # draw across entire viewport, but clipped (in different place)
558
> grid.clip(x = 0.7, width = 0.1)
559
> grid.lines(gp=gpar(col="red", lwd=5))
560
> # Viewport sets new clip region
561
> pushViewport(viewport(width=0.5, height=0.5, clip=TRUE))
562
> grid.lines(gp=gpar(col="grey", lwd=3))
61435 ripley 563
> # Return to original viewport;  get
56186 murdoch 564
> # clip region from previous grid.clip()
565
> # (NOT from previous viewport clip region)
566
> popViewport()
567
> grid.lines(gp=gpar(col="black"))
568
> 
569
> 
570
> 
571
> cleanEx()
572
> nameEx("grid.convert")
573
> ### * grid.convert
574
> 
575
> flush(stderr()); flush(stdout())
576
> 
577
> ### Name: grid.convert
578
> ### Title: Convert Between Different grid Coordinate Systems
63940 murrell 579
> ### Aliases: convertUnit convertX convertY convertWidth convertHeight
56186 murdoch 580
> ### Keywords: dplot
581
> 
582
> ### ** Examples
583
> 
584
> ## A tautology
585
> convertX(unit(1, "inches"), "inches")
586
[1] 1inches
587
> ## The physical units
588
> convertX(unit(2.54, "cm"), "inches")
589
[1] 1inches
590
> convertX(unit(25.4, "mm"), "inches")
591
[1] 1inches
592
> convertX(unit(72.27, "points"), "inches")
593
[1] 1inches
594
> convertX(unit(1/12*72.27, "picas"), "inches")
595
[1] 1inches
596
> convertX(unit(72, "bigpts"), "inches")
597
[1] 1inches
598
> convertX(unit(1157/1238*72.27, "dida"), "inches")
599
[1] 1inches
600
> convertX(unit(1/12*1157/1238*72.27, "cicero"), "inches")
601
[1] 1inches
602
> convertX(unit(65536*72.27, "scaledpts"), "inches")
603
[1] 1inches
604
> convertX(unit(1/2.54, "inches"), "cm")
605
[1] 1cm
606
> convertX(unit(1/25.4, "inches"), "mm")
607
[1] 1mm
608
> convertX(unit(1/72.27, "inches"), "points")
609
[1] 1points
610
> convertX(unit(1/(1/12*72.27), "inches"), "picas")
611
[1] 1picas
612
> convertX(unit(1/72, "inches"), "bigpts")
613
[1] 1bigpts
614
> convertX(unit(1/(1157/1238*72.27), "inches"), "dida")
615
[1] 1dida
616
> convertX(unit(1/(1/12*1157/1238*72.27), "inches"), "cicero")
617
[1] 1cicero
618
> convertX(unit(1/(65536*72.27), "inches"), "scaledpts")
619
[1] 1scaledpts
620
> 
621
> pushViewport(viewport(width=unit(1, "inches"),
622
+                        height=unit(2, "inches"),
623
+                        xscale=c(0, 1),
624
+                        yscale=c(1, 3)))
625
>   ## Location versus dimension
626
>   convertY(unit(2, "native"), "inches")
627
[1] 1inches
628
>   convertHeight(unit(2, "native"), "inches")
629
[1] 2inches
630
>   ## From "x" to "y" (the conversion is via "inches")
631
>   convertUnit(unit(1, "native"), "native",
632
+                axisFrom="x", axisTo="y")
633
[1] 2native
634
>   ## Convert several values at once
635
>   convertX(unit(c(0.5, 2.54), c("npc", "cm")),
636
+                 c("inches", "native"))
637
[1] 0.5inches 1native  
638
> popViewport()
639
> ## Convert a complex unit
640
> convertX(unit(1, "strwidth", "Hello"), "native")
641
[1] 0.0558333333333333native
642
> 
643
> 
644
> 
645
> cleanEx()
646
> nameEx("grid.curve")
647
> ### * grid.curve
648
> 
649
> flush(stderr()); flush(stdout())
650
> 
651
> ### Name: grid.curve
652
> ### Title: Draw a Curve Between Locations
653
> ### Aliases: grid.curve curveGrob arcCurvature
654
> ### Keywords: dplot
655
> 
656
> ### ** Examples
657
> 
658
> curveTest <- function(i, j, ...) {
659
+   pushViewport(viewport(layout.pos.col=j, layout.pos.row=i))
660
+   do.call("grid.curve", c(list(x1=.25, y1=.25, x2=.75, y2=.75), list(...)))
661
+   grid.text(sub("list\\((.*)\\)", "\\1",
662
+                 deparse(substitute(list(...)))),
663
+             y=unit(1, "npc"))
664
+   popViewport()
665
+ }
666
> # grid.newpage()
667
> pushViewport(plotViewport(c(0, 0, 1, 0),
668
+                           layout=grid.layout(2, 1, heights=c(2, 1))))
669
> pushViewport(viewport(layout.pos.row=1,
670
+                       layout=grid.layout(3, 3, respect=TRUE)))
671
> curveTest(1, 1)
672
> curveTest(1, 2, inflect=TRUE)
673
> curveTest(1, 3, angle=135)
674
> curveTest(2, 1, arrow=arrow())
675
> curveTest(2, 2, ncp=8)
676
> curveTest(2, 3, shape=0)
677
> curveTest(3, 1, curvature=-1)
678
> curveTest(3, 2, square=FALSE)
679
> curveTest(3, 3, debug=TRUE)
680
> popViewport()
681
> pushViewport(viewport(layout.pos.row=2,
682
+                       layout=grid.layout(3, 3)))
683
> curveTest(1, 1)
684
> curveTest(1, 2, inflect=TRUE)
685
> curveTest(1, 3, angle=135)
686
> curveTest(2, 1, arrow=arrow())
687
> curveTest(2, 2, ncp=8)
688
> curveTest(2, 3, shape=0)
689
> curveTest(3, 1, curvature=-1)
690
> curveTest(3, 2, square=FALSE)
691
> curveTest(3, 3, debug=TRUE)
692
> popViewport(2)
693
> 
694
> 
695
> 
696
> cleanEx()
61044 murrell 697
> nameEx("grid.delay")
698
> ### * grid.delay
699
> 
700
> flush(stderr()); flush(stdout())
701
> 
702
> ### Name: grid.delay
703
> ### Title: Encapsulate calculations and generating a grob
704
> ### Aliases: grid.delay delayGrob
705
> ### Keywords: dplot
706
> 
707
> ### ** Examples
708
> 
709
> grid.delay({
710
+               w <- convertWidth(unit(1, "inches"), "npc")
711
+               rectGrob(width=w)
712
+             },
713
+             list())
714
> 
715
> 
716
> 
717
> cleanEx()
56186 murdoch 718
> nameEx("grid.draw")
719
> ### * grid.draw
720
> 
721
> flush(stderr()); flush(stdout())
722
> 
723
> ### Name: grid.draw
724
> ### Title: Draw a grid grob
725
> ### Aliases: grid.draw
726
> ### Keywords: dplot
727
> 
728
> ### ** Examples
729
> 
730
> grid.newpage()
731
> ## Create a graphical object, but don't draw it
732
> l <- linesGrob()
733
> ## Draw it
734
> grid.draw(l)
735
> 
736
> 
737
> 
738
> cleanEx()
739
> nameEx("grid.edit")
740
> ### * grid.edit
741
> 
742
> flush(stderr()); flush(stdout())
743
> 
744
> ### Name: grid.edit
745
> ### Title: Edit the Description of a Grid Graphical Object
746
> ### Aliases: grid.edit grid.gedit editGrob
747
> ### Keywords: dplot
748
> 
749
> ### ** Examples
750
> 
751
> grid.newpage()
752
> grid.xaxis(name = "xa", vp = viewport(width=.5, height=.5))
753
> grid.edit("xa", gp = gpar(col="red"))
754
> # won't work because no ticks (at is NULL)
755
> try(grid.edit(gPath("xa", "ticks"), gp = gpar(col="green")))
756
Error in editDLfromGPath(gPath, specs, strict, grep, global, redraw) : 
757
  'gPath' (xa::ticks) not found
758
> grid.edit("xa", at = 1:4/5)
759
> # Now it should work
760
> try(grid.edit(gPath("xa", "ticks"), gp = gpar(col="green")))
761
> 
762
> 
763
> 
764
> cleanEx()
61044 murrell 765
> nameEx("grid.force")
766
> ### * grid.force
767
> 
768
> flush(stderr()); flush(stdout())
769
> 
770
> ### Name: grid.force
771
> ### Title: Force a grob into its components
63911 murrell 772
> ### Aliases: grid.force grid.force.default grid.force.gPath grid.force.grob
64207 murrell 773
> ###   forceGrob grid.revert grid.revert.gPath grid.revert.grob
61044 murrell 774
> ### Keywords: dplot
775
> 
776
> ### ** Examples
777
> 
778
> grid.newpage()
779
> pushViewport(viewport(width=.5, height=.5))
63911 murrell 780
> # Draw xaxis
781
> grid.xaxis(name="xax")
61044 murrell 782
> grid.ls()
81257 murrell 783
GRID.text.261
63911 murrell 784
xax
785
> # Force xaxis
61044 murrell 786
> grid.force()
787
> grid.ls()
81257 murrell 788
GRID.text.261
63911 murrell 789
xax
61044 murrell 790
  major
791
  ticks
792
  labels
63911 murrell 793
> # Revert xaxis
61044 murrell 794
> grid.revert()
795
> grid.ls()
81257 murrell 796
GRID.text.261
63911 murrell 797
xax
798
> # Draw and force yaxis
799
> grid.force(yaxisGrob(), draw=TRUE)
81257 murrell 800
forcedgrob[GRID.yaxis.262] 
63911 murrell 801
> grid.ls()
81257 murrell 802
GRID.text.261
63911 murrell 803
xax
81257 murrell 804
GRID.yaxis.262
63911 murrell 805
  major
806
  ticks
807
  labels
808
> # Revert yaxis
809
> grid.revert()
810
> grid.ls()
81257 murrell 811
GRID.text.261
63911 murrell 812
xax
81257 murrell 813
GRID.yaxis.262
63911 murrell 814
> # Force JUST xaxis
815
> grid.force("xax")
816
> grid.ls()
81257 murrell 817
GRID.text.261
63911 murrell 818
xax
819
  major
820
  ticks
821
  labels
81257 murrell 822
GRID.yaxis.262
63911 murrell 823
> # Force ALL
824
> grid.force()
825
> grid.ls()
81257 murrell 826
GRID.text.261
63911 murrell 827
xax
828
  major
829
  ticks
830
  labels
81257 murrell 831
GRID.yaxis.262
63911 murrell 832
  major
833
  ticks
834
  labels
835
> # Revert JUST xaxis
836
> grid.revert("xax")
837
> grid.ls()
81257 murrell 838
GRID.text.261
63911 murrell 839
xax
81257 murrell 840
GRID.yaxis.262
63911 murrell 841
  major
842
  ticks
843
  labels
61044 murrell 844
> 
845
> 
846
> 
847
> cleanEx()
56186 murdoch 848
> nameEx("grid.frame")
849
> ### * grid.frame
850
> 
851
> flush(stderr()); flush(stdout())
852
> 
853
> ### Name: grid.frame
854
> ### Title: Create a Frame for Packing Objects
855
> ### Aliases: grid.frame frameGrob
856
> ### Keywords: dplot
857
> 
858
> ### ** Examples
859
> 
860
> grid.newpage()
861
> grid.frame(name="gf", draw=TRUE)
862
> grid.pack("gf", rectGrob(gp=gpar(fill="grey")), width=unit(1, "null"))
863
> grid.pack("gf", textGrob("hi there"), side="right")
864
> 
865
> 
866
> 
867
> cleanEx()
868
> nameEx("grid.function")
869
> ### * grid.function
870
> 
871
> flush(stderr()); flush(stdout())
872
> 
873
> ### Name: grid.function
874
> ### Title: Draw a curve representing a function
875
> ### Aliases: grid.function functionGrob grid.abline
876
> ### Keywords: dplot
877
> 
878
> ### ** Examples
879
> 
880
>     # abline
881
>     # NOTE: in ROOT viewport on screen, (0, 0) at top-left
882
>     #       and "native" is pixels!
883
>     grid.function(function(x) list(x=x, y=0 + 1*x))
884
>     # a more "normal" viewport with default normalized "native" coords
885
>     grid.newpage()
886
>     pushViewport(viewport())
887
>     grid.function(function(x) list(x=x, y=0 + 1*x))
888
>     # slightly simpler
889
>     grid.newpage()
890
>     pushViewport(viewport())
891
>     grid.abline()
892
>     # sine curve
893
>     grid.newpage()
894
>     pushViewport(viewport(xscale=c(0, 2*pi), yscale=c(-1, 1)))
895
>     grid.function(function(x) list(x=x, y=sin(x)))
896
>     # constrained sine curve
897
>     grid.newpage()
898
>     pushViewport(viewport(xscale=c(0, 2*pi), yscale=c(-1, 1)))
899
>     grid.function(function(x) list(x=x, y=sin(x)),
900
+                   range=0:1)
901
>     # inverse sine curve
902
>     grid.newpage()
903
>     pushViewport(viewport(xscale=c(-1, 1), yscale=c(0, 2*pi)))
904
>     grid.function(function(y) list(x=sin(y), y=y),
905
+                   range="y")
906
>     # parametric function
907
>     grid.newpage()
908
>     pushViewport(viewport(xscale=c(-1, 1), yscale=c(-1, 1)))
909
>     grid.function(function(t) list(x=cos(t), y=sin(t)),
910
+                   range=c(0, 9*pi/5))
911
>     # physical abline
912
>     grid.newpage()
913
>     grid.function(function(x) list(x=x, y=0 + 1*x),
914
+                   units="in")
915
> 
916
> 
917
> 
918
> cleanEx()
919
> nameEx("grid.get")
920
> ### * grid.get
921
> 
922
> flush(stderr()); flush(stdout())
923
> 
924
> ### Name: grid.get
925
> ### Title: Get a Grid Graphical Object
926
> ### Aliases: grid.get grid.gget getGrob
927
> ### Keywords: dplot
928
> 
929
> ### ** Examples
930
> 
931
> grid.xaxis(name="xa")
932
> grid.get("xa")
933
xaxis[xa] 
934
> grid.get(gPath("xa", "ticks"))
935
NULL
936
> 
937
> grid.draw(gTree(name="gt", children=gList(xaxisGrob(name="axis"))))
938
> grid.get(gPath("gt", "axis", "ticks"))
939
NULL
940
> 
941
> 
942
> 
943
> cleanEx()
944
> nameEx("grid.grab")
945
> ### * grid.grab
946
> 
947
> flush(stderr()); flush(stdout())
948
> 
949
> ### Name: grid.grab
950
> ### Title: Grab the current grid output
951
> ### Aliases: grid.grab grid.grabExpr
952
> ### Keywords: dplot
953
> 
954
> ### ** Examples
955
> 
80081 hornik 956
> pushViewport(viewport(width=.5, height=.5))
56186 murdoch 957
> grid.rect()
958
> grid.points(stats::runif(10), stats::runif(10))
959
> popViewport()
960
> grab <- grid.grab()
961
> grid.newpage()
962
> grid.draw(grab)
963
> 
964
> 
965
> 
966
> cleanEx()
63911 murrell 967
> nameEx("grid.grep")
968
> ### * grid.grep
969
> 
970
> flush(stderr()); flush(stdout())
971
> 
972
> ### Name: grid.grep
80415 murrell 973
> ### Title: Search for Grobs and/or Viewports
63911 murrell 974
> ### Aliases: grid.grep
975
> ### Keywords: dplot
976
> 
977
> ### ** Examples
978
> 
979
> # A gTree, called "grandparent", with child gTree,
980
> # called "parent", with childrenvp vpStack (vp2 within vp1)
981
> # and child grob, called "child", with vp vpPath (down to vp2)
982
> sampleGTree <- gTree(name="grandparent",
983
+                      children=gList(gTree(name="parent",
984
+                           children=gList(grob(name="child", vp="vp1::vp2")),
985
+                           childrenvp=vpStack(viewport(name="vp1"),
986
+                                              viewport(name="vp2")))))
987
> # Searching for grobs
988
> grid.grep("parent", sampleGTree)
989
grandparent::parent 
990
> grid.grep("parent", sampleGTree, strict=TRUE)
991
character(0)
992
> grid.grep("grandparent", sampleGTree, strict=TRUE)
993
grandparent 
994
> grid.grep("grandparent::parent", sampleGTree)
995
grandparent::parent 
996
> grid.grep("parent::child", sampleGTree)
997
grandparent::parent::child 
998
> grid.grep("[a-z]", sampleGTree, grep=TRUE)
999
grandparent 
1000
> grid.grep("[a-z]", sampleGTree, grep=TRUE, global=TRUE)
1001
[[1]]
1002
grandparent 
1003
 
1004
[[2]]
1005
grandparent::parent 
1006
 
1007
[[3]]
1008
grandparent::parent::child 
1009
 
1010
> # Searching for viewports
1011
> grid.grep("vp1", sampleGTree, viewports=TRUE)
1012
vp1 
1013
> grid.grep("vp2", sampleGTree, viewports=TRUE)
1014
vp1::vp2 
1015
> grid.grep("vp", sampleGTree, viewports=TRUE, grep=TRUE)
1016
vp1 
1017
> grid.grep("vp2", sampleGTree, viewports=TRUE, strict=TRUE)
1018
character(0)
1019
> grid.grep("vp1::vp2", sampleGTree, viewports=TRUE)
1020
vp1::vp2 
1021
> # Searching for both
1022
> grid.grep("[a-z]", sampleGTree, viewports=TRUE, grep=TRUE, global=TRUE)
1023
[[1]]
1024
grandparent 
1025
 
1026
[[2]]
1027
grandparent::parent 
1028
 
1029
[[3]]
1030
vp1 
1031
 
1032
[[4]]
1033
vp1::vp2 
1034
 
1035
[[5]]
1036
grandparent::parent::child 
1037
 
1038
> 
1039
> 
1040
> 
1041
> cleanEx()
81097 murrell 1042
> nameEx("grid.group")
1043
> ### * grid.group
1044
> 
1045
> flush(stderr()); flush(stdout())
1046
> 
1047
> ### Name: grid.group
1048
> ### Title: Draw a Group
1049
> ### Aliases: grid.group groupGrob grid.define defineGrob grid.use useGrob
1050
> ### Keywords: dplot
1051
> 
1052
> ### ** Examples
1053
> 
1054
> ## NOTE: on devices without support for groups (or masks or patterns),
1055
> ##       there will only be two overlapping opaque circles 
1056
> grid.newpage()
1057
> pat <- pattern(rasterGrob(matrix(c(.5, 1, 1, .5), nrow=2),
1058
+                           width=unit(1, "cm"),
1059
+                           height=unit(1, "cm"),
1060
+                           interpolate=FALSE),
1061
+                width=unit(1, "cm"), height=unit(1, "cm"),
1062
+                extend="repeat")
1063
> grid.rect(gp=gpar(col=NA, fill=pat))
83917 murrell 1064
> masks <- dev.capabilities()$masks
1065
> if (is.character(masks) && "luminance" %in% masks) {
1066
+   mask <- as.mask(rectGrob(gp=gpar(col=NA, fill="grey50")), type="luminance")
1067
+ } else {
1068
+   mask <- rectGrob(gp=gpar(col=NA, fill=rgb(0,0,0,.5)))
1069
+ }
81097 murrell 1070
> pushViewport(viewport(mask=mask))
1071
> pushViewport(viewport(y=.5, height=.5, just="bottom"))
1072
> grid.circle(1:2/3, r=.45, gp=gpar(fill=2:3))
1073
> popViewport()
1074
> pushViewport(viewport(y=0, height=.5, just="bottom"))
1075
> grid.group(circleGrob(1:2/3, r=.45, gp=gpar(fill=2:3)))
1076
> popViewport()
1077
> 
1078
> 
1079
> 
1080
> cleanEx()
56186 murdoch 1081
> nameEx("grid.layout")
1082
> ### * grid.layout
1083
> 
1084
> flush(stderr()); flush(stdout())
1085
> 
1086
> ### Name: grid.layout
1087
> ### Title: Create a Grid Layout
1088
> ### Aliases: grid.layout
1089
> ### Keywords: dplot
1090
> 
1091
> ### ** Examples
1092
> 
1093
> ## A variety of layouts (some a bit mid-bending ...)
1094
> layout.torture()
1095
> ## Demonstration of layout justification
1096
> grid.newpage()
1097
> testlay <- function(just="centre") {
1098
+   pushViewport(viewport(layout=grid.layout(1, 1, widths=unit(1, "inches"),
1099
+                           heights=unit(0.25, "npc"),
1100
+                           just=just)))
1101
+   pushViewport(viewport(layout.pos.col=1, layout.pos.row=1))
1102
+   grid.rect()
1103
+   grid.text(paste(just, collapse="-"))
1104
+   popViewport(2)
1105
+ }
1106
> testlay()
1107
> testlay(c("left", "top"))
1108
> testlay(c("right", "top"))
1109
> testlay(c("right", "bottom"))
1110
> testlay(c("left", "bottom"))
1111
> testlay(c("left"))
1112
> testlay(c("right"))
1113
> testlay(c("bottom"))
1114
> testlay(c("top"))
1115
> 
1116
> 
1117
> 
1118
> cleanEx()
1119
> nameEx("grid.lines")
1120
> ### * grid.lines
1121
> 
1122
> flush(stderr()); flush(stdout())
1123
> 
1124
> ### Name: grid.lines
1125
> ### Title: Draw Lines in a Grid Viewport
1126
> ### Aliases: grid.lines linesGrob grid.polyline polylineGrob
1127
> ### Keywords: dplot
1128
> 
1129
> ### ** Examples
1130
> 
1131
> grid.lines()
1132
> # Using id (NOTE: locations are not in consecutive blocks)
1133
> grid.newpage()
1134
> grid.polyline(x=c((0:4)/10, rep(.5, 5), (10:6)/10, rep(.5, 5)),
1135
+              y=c(rep(.5, 5), (10:6/10), rep(.5, 5), (0:4)/10),
1136
+              id=rep(1:5, 4),
1137
+              gp=gpar(col=1:5, lwd=3))
1138
> # Using id.lengths
1139
> grid.newpage()
1140
> grid.polyline(x=outer(c(0, .5, 1, .5), 5:1/5),
1141
+              y=outer(c(.5, 1, .5, 0), 5:1/5),
1142
+              id.lengths=rep(4, 5),
1143
+              gp=gpar(col=1:5, lwd=3))
1144
> 
1145
> 
1146
> 
1147
> cleanEx()
1148
> nameEx("grid.locator")
1149
> ### * grid.locator
1150
> 
1151
> flush(stderr()); flush(stdout())
1152
> 
1153
> ### Name: grid.locator
1154
> ### Title: Capture a Mouse Click
1155
> ### Aliases: grid.locator
1156
> ### Keywords: dplot
1157
> 
1158
> ### ** Examples
1159
> 
72569 ripley 1160
> if (dev.interactive()) {
56186 murdoch 1161
+   ## Need to write a more sophisticated unit as.character method
1162
+   unittrim <- function(unit) {
1163
+     sub("^([0-9]+|[0-9]+[.][0-9])[0-9]*", "\\1", as.character(unit))
1164
+   }
1165
+   do.click <- function(unit) {
1166
+     click.locn <- grid.locator(unit)
1167
+     grid.segments(unit.c(click.locn$x, unit(0, "npc")),
1168
+                   unit.c(unit(0, "npc"), click.locn$y),
1169
+                   click.locn$x, click.locn$y,
1170
+                   gp=gpar(lty="dashed", col="grey"))
1171
+     grid.points(click.locn$x, click.locn$y, pch=16, size=unit(1, "mm"))
1172
+     clickx <- unittrim(click.locn$x)
1173
+     clicky <- unittrim(click.locn$y)
61157 ripley 1174
+     grid.text(paste0("(", clickx, ", ", clicky, ")"),
56186 murdoch 1175
+               click.locn$x + unit(2, "mm"), click.locn$y,
1176
+               just="left")
1177
+   }
72569 ripley 1178
+ 
1179
+   grid.newpage() # (empty slate)
1180
+   ## device
56186 murdoch 1181
+   do.click("inches")
72569 ripley 1182
+   Sys.sleep(1)
1183
+ 
56186 murdoch 1184
+   pushViewport(viewport(width=0.5, height=0.5,
72569 ripley 1185
+                         xscale=c(0, 100), yscale=c(0, 10)))
56186 murdoch 1186
+   grid.rect()
1187
+   grid.xaxis()
1188
+   grid.yaxis()
1189
+   do.click("native")
61435 ripley 1190
+   popViewport()
56186 murdoch 1191
+ }
1192
> 
1193
> 
1194
> 
1195
> cleanEx()
1196
> nameEx("grid.ls")
1197
> ### * grid.ls
1198
> 
1199
> flush(stderr()); flush(stdout())
1200
> 
1201
> ### Name: grid.ls
1202
> ### Title: List the names of grobs or viewports
1203
> ### Aliases: grid.ls nestedListing pathListing grobPathListing
1204
> ### Keywords: dplot
1205
> 
1206
> ### ** Examples
1207
> 
1208
> # A gTree, called "parent", with childrenvp vpTree (vp2 within vp1)
1209
> # and child grob, called "child", with vp vpPath (down to vp2)
1210
> sampleGTree <- gTree(name="parent",
1211
+                      children=gList(grob(name="child", vp="vp1::vp2")),
1212
+                      childrenvp=vpTree(parent=viewport(name="vp1"),
1213
+                                        children=vpList(viewport(name="vp2"))))
1214
> grid.ls(sampleGTree)
1215
parent
1216
  child
1217
> # Show viewports too
80081 hornik 1218
> grid.ls(sampleGTree, viewports=TRUE)
56186 murdoch 1219
parent
1220
  vp1
1221
    vp2
1222
      2
1223
  vp1
1224
    vp2
1225
      child
1226
      2
1227
> # Only show viewports
80081 hornik 1228
> grid.ls(sampleGTree, viewports=TRUE, grobs=FALSE)
56186 murdoch 1229
vp1
1230
  vp2
1231
    2
1232
vp1
1233
  vp2
1234
    2
1235
> # Alternate displays
1236
> # nested listing, custom indent
80081 hornik 1237
> grid.ls(sampleGTree, viewports=TRUE, print=nestedListing, gindent="--")
56186 murdoch 1238
parent
1239
--vp1
1240
----vp2
1241
------2
1242
--vp1
1243
----vp2
1244
------child
1245
------2
1246
> # path listing
80081 hornik 1247
> grid.ls(sampleGTree, viewports=TRUE, print=pathListing)
56186 murdoch 1248
            | parent
1249
vp1
1250
vp1::vp2
1251
vp1::vp2::2
1252
vp1
1253
vp1::vp2
1254
vp1::vp2    | parent::child
1255
vp1::vp2::2
1256
> # path listing, without grobs aligned
80081 hornik 1257
> grid.ls(sampleGTree, viewports=TRUE, print=pathListing, gAlign=FALSE)
56186 murdoch 1258
 | parent
1259
vp1
1260
vp1::vp2
1261
vp1::vp2::2
1262
vp1
1263
vp1::vp2
1264
vp1::vp2 | parent::child
1265
vp1::vp2::2
61435 ripley 1266
> # grob path listing
80081 hornik 1267
> grid.ls(sampleGTree, viewports=TRUE, print=grobPathListing)
56186 murdoch 1268
         | parent
1269
vp1::vp2 | parent::child
1270
> # path listing, grobs only
1271
> grid.ls(sampleGTree, print=pathListing)
1272
 | parent
1273
 | parent::child
1274
> # path listing, viewports only
80081 hornik 1275
> grid.ls(sampleGTree, viewports=TRUE, grobs=FALSE, print=pathListing)
56186 murdoch 1276
vp1
1277
vp1::vp2
1278
vp1::vp2::2
1279
vp1
1280
vp1::vp2
1281
vp1::vp2::2
1282
> # raw flat listing
80081 hornik 1283
> str(grid.ls(sampleGTree, viewports=TRUE, print=FALSE))
56186 murdoch 1284
List of 6
1285
 $ name   : chr [1:8] "parent" "vp1" "vp2" "2" ...
1286
 $ gDepth : num [1:8] 0 1 1 1 1 1 1 1
1287
 $ vpDepth: num [1:8] 0 0 1 2 0 1 2 2
1288
 $ gPath  : chr [1:8] "" "parent" "parent" "parent" ...
1289
 $ vpPath : chr [1:8] "" "" "vp1" "vp1::vp2" ...
60841 ripley 1290
 $ type   : chr [1:8] "gTreeListing" "vpListing" "vpListing" "vpUpListing" ...
56186 murdoch 1291
 - attr(*, "class")= chr "flatGridListing"
1292
> 
1293
> 
1294
> 
1295
> cleanEx()
1296
> nameEx("grid.move.to")
1297
> ### * grid.move.to
1298
> 
1299
> flush(stderr()); flush(stdout())
1300
> 
1301
> ### Name: grid.move.to
1302
> ### Title: Move or Draw to a Specified Position
1303
> ### Aliases: grid.move.to grid.line.to moveToGrob lineToGrob
1304
> ### Keywords: dplot
1305
> 
1306
> ### ** Examples
1307
> 
1308
> grid.newpage()
1309
> grid.move.to(0.5, 0.5)
1310
> grid.line.to(1, 1)
1311
> grid.line.to(0.5, 0)
80081 hornik 1312
> pushViewport(viewport(x=0, y=0, width=0.25, height=0.25, just=c("left", "bottom")))
56186 murdoch 1313
> grid.rect()
1314
> grid.grill()
1315
> grid.line.to(0.5, 0.5)
1316
> popViewport()
1317
> 
1318
> 
1319
> 
1320
> cleanEx()
1321
> nameEx("grid.null")
1322
> ### * grid.null
1323
> 
1324
> flush(stderr()); flush(stdout())
1325
> 
1326
> ### Name: grid.null
1327
> ### Title: Null Graphical Object
1328
> ### Aliases: grid.null nullGrob
1329
> ### Keywords: dplot
1330
> 
1331
> ### ** Examples
1332
> 
1333
> grid.newpage()
1334
> grid.null(name="ref")
1335
> grid.rect(height=grobHeight("ref"))
1336
> grid.segments(0, 0, grobX("ref", 0), grobY("ref", 0))
1337
> 
1338
> 
1339
> 
1340
> cleanEx()
1341
> nameEx("grid.path")
1342
> ### * grid.path
1343
> 
1344
> flush(stderr()); flush(stdout())
1345
> 
1346
> ### Name: grid.path
1347
> ### Title: Draw a Path
1348
> ### Aliases: grid.path pathGrob
1349
> ### Keywords: dplot
1350
> 
1351
> ### ** Examples
1352
> 
56281 ripley 1353
> pathSample <- function(x, y, rule, gp = gpar()) {
56186 murdoch 1354
+     if (is.na(rule))
56281 ripley 1355
+         grid.path(x, y, id = rep(1:2, each = 4), gp = gp)
61435 ripley 1356
+     else
56281 ripley 1357
+         grid.path(x, y, id = rep(1:2, each = 4), rule = rule, gp = gp)
56186 murdoch 1358
+     if (!is.na(rule))
56281 ripley 1359
+         grid.text(paste("Rule:", rule), y = 0, just = "bottom")
56186 murdoch 1360
+ }
1361
> 
1362
> pathTriplet <- function(x, y, title) {
56281 ripley 1363
+     pushViewport(viewport(height = 0.9, layout = grid.layout(1, 3),
1364
+                           gp = gpar(cex = .7)))
1365
+     grid.rect(y = 1, height = unit(1, "char"), just = "top",
1366
+               gp = gpar(col = NA, fill = "grey"))
1367
+     grid.text(title, y = 1, just = "top")
1368
+     pushViewport(viewport(layout.pos.col = 1))
1369
+     pathSample(x, y, rule = "winding",
1370
+                gp = gpar(fill = "grey"))
56186 murdoch 1371
+     popViewport()
56281 ripley 1372
+     pushViewport(viewport(layout.pos.col = 2))
1373
+     pathSample(x, y, rule = "evenodd",
1374
+                gp = gpar(fill = "grey"))
56186 murdoch 1375
+     popViewport()
56281 ripley 1376
+     pushViewport(viewport(layout.pos.col = 3))
1377
+     pathSample(x, y, rule = NA)
56186 murdoch 1378
+     popViewport()
1379
+     popViewport()
1380
+ }
1381
> 
1382
> pathTest <- function() {
1383
+     grid.newpage()
56281 ripley 1384
+     pushViewport(viewport(layout = grid.layout(5, 1)))
1385
+     pushViewport(viewport(layout.pos.row = 1))
1386
+     pathTriplet(c(.1, .1, .9, .9, .2, .2, .8, .8),
1387
+                 c(.1, .9, .9, .1, .2, .8, .8, .2),
1388
+                 "Nested rectangles, both clockwise")
56186 murdoch 1389
+     popViewport()
56281 ripley 1390
+     pushViewport(viewport(layout.pos.row = 2))
1391
+     pathTriplet(c(.1, .1, .9, .9, .2, .8, .8, .2),
1392
+                 c(.1, .9, .9, .1, .2, .2, .8, .8),
1393
+                 "Nested rectangles, outer clockwise, inner anti-clockwise")
56186 murdoch 1394
+     popViewport()
56281 ripley 1395
+     pushViewport(viewport(layout.pos.row = 3))
1396
+     pathTriplet(c(.1, .1, .4, .4, .6, .9, .9, .6),
1397
+                 c(.1, .4, .4, .1, .6, .6, .9, .9),
1398
+                 "Disjoint rectangles")
56186 murdoch 1399
+     popViewport()
56281 ripley 1400
+     pushViewport(viewport(layout.pos.row = 4))
1401
+     pathTriplet(c(.1, .1, .6, .6, .4, .4, .9, .9),
1402
+                 c(.1, .6, .6, .1, .4, .9, .9, .4),
1403
+                 "Overlapping rectangles, both clockwise")
56186 murdoch 1404
+     popViewport()
56281 ripley 1405
+     pushViewport(viewport(layout.pos.row = 5))
1406
+     pathTriplet(c(.1, .1, .6, .6, .4, .9, .9, .4),
1407
+                 c(.1, .6, .6, .1, .4, .4, .9, .9),
1408
+                 "Overlapping rectangles, one clockwise, other anti-clockwise")
56186 murdoch 1409
+     popViewport()
1410
+     popViewport()
1411
+ }
1412
> 
1413
> pathTest()
1414
> 
76069 murrell 1415
> # Drawing multiple paths at once
1416
> holed_rect <- cbind(c(.15, .15, -.15, -.15, .1, .1, -.1, -.1), 
1417
+                     c(.15, -.15, -.15, .15, .1, -.1, -.1, .1))
1418
> holed_rects <- rbind(
1419
+     holed_rect + matrix(c(.7, .2), nrow = 8, ncol = 2, byrow = TRUE),
1420
+     holed_rect + matrix(c(.7, .8), nrow = 8, ncol = 2, byrow = TRUE),
1421
+     holed_rect + matrix(c(.2, .5), nrow = 8, ncol = 2, byrow = TRUE)
1422
+ )
1423
> grid.newpage()
1424
> grid.path(x = holed_rects[, 1], y = holed_rects[, 2], 
1425
+           id = rep(1:6, each = 4), pathId = rep(1:3, each = 8),
1426
+           gp = gpar(fill = c('red', 'blue', 'green')),
1427
+           rule = 'evenodd')
56186 murdoch 1428
> 
76069 murrell 1429
> # Not specifying pathId will treat all points as part of the same path, thus 
1430
> # having same fill
1431
> grid.newpage()
1432
> grid.path(x = holed_rects[, 1], y = holed_rects[, 2], 
1433
+           id = rep(1:6, each = 4),
1434
+           gp = gpar(fill = c('red', 'blue', 'green')),
1435
+           rule = 'evenodd')
56186 murdoch 1436
> 
76069 murrell 1437
> 
1438
> 
56186 murdoch 1439
> cleanEx()
1440
> nameEx("grid.plot.and.legend")
1441
> ### * grid.plot.and.legend
1442
> 
1443
> flush(stderr()); flush(stdout())
1444
> 
1445
> ### Name: grid.plot.and.legend
1446
> ### Title: A Simple Plot and Legend Demo
1447
> ### Aliases: grid.plot.and.legend
1448
> ### Keywords: dplot
1449
> 
1450
> ### ** Examples
1451
> 
1452
> grid.plot.and.legend()
1453
> 
1454
> 
1455
> 
1456
> cleanEx()
1457
> nameEx("grid.polygon")
1458
> ### * grid.polygon
1459
> 
1460
> flush(stderr()); flush(stdout())
1461
> 
1462
> ### Name: grid.polygon
1463
> ### Title: Draw a Polygon
1464
> ### Aliases: grid.polygon polygonGrob
1465
> ### Keywords: dplot
1466
> 
1467
> ### ** Examples
1468
> 
1469
> grid.polygon()
1470
> # Using id (NOTE: locations are not in consecutive blocks)
1471
> grid.newpage()
1472
> grid.polygon(x=c((0:4)/10, rep(.5, 5), (10:6)/10, rep(.5, 5)),
1473
+              y=c(rep(.5, 5), (10:6/10), rep(.5, 5), (0:4)/10),
1474
+              id=rep(1:5, 4),
1475
+              gp=gpar(fill=1:5))
1476
> # Using id.lengths
1477
> grid.newpage()
1478
> grid.polygon(x=outer(c(0, .5, 1, .5), 5:1/5),
1479
+              y=outer(c(.5, 1, .5, 0), 5:1/5),
1480
+              id.lengths=rep(4, 5),
1481
+              gp=gpar(fill=1:5))
1482
> 
1483
> 
1484
> 
1485
> cleanEx()
1486
> nameEx("grid.raster")
1487
> ### * grid.raster
1488
> 
1489
> flush(stderr()); flush(stdout())
1490
> 
1491
> ### Name: grid.raster
1492
> ### Title: Render a raster object
1493
> ### Aliases: grid.raster rasterGrob
1494
> ### Keywords: dplot
1495
> 
1496
> ### ** Examples
1497
> 
1498
> redGradient <- matrix(hcl(0, 80, seq(50, 80, 10)),
1499
+                       nrow=4, ncol=5)
61435 ripley 1500
> # interpolated
56186 murdoch 1501
> grid.newpage()
1502
> grid.raster(redGradient)
1503
> # blocky
1504
> grid.newpage()
1505
> grid.raster(redGradient, interpolate=FALSE)
1506
> # blocky and stretched
1507
> grid.newpage()
1508
> grid.raster(redGradient, interpolate=FALSE, height=unit(1, "npc"))
1509
> 
1510
> # The same raster drawn several times
1511
> grid.newpage()
80081 hornik 1512
> grid.raster(0, x=1:3/4, y=1:3/4, width=.1, interpolate=FALSE)
56186 murdoch 1513
> 
1514
> 
1515
> 
1516
> cleanEx()
1517
> nameEx("grid.record")
1518
> ### * grid.record
1519
> 
1520
> flush(stderr()); flush(stdout())
1521
> 
1522
> ### Name: grid.record
1523
> ### Title: Encapsulate calculations and drawing
1524
> ### Aliases: grid.record recordGrob
1525
> ### Keywords: dplot
1526
> 
1527
> ### ** Examples
1528
> 
1529
> grid.record({
1530
+               w <- convertWidth(unit(1, "inches"), "npc")
1531
+               grid.rect(width=w)
1532
+             },
1533
+             list())
1534
> 
1535
> 
1536
> 
1537
> cleanEx()
60969 ripley 1538
> nameEx("grid.reorder")
1539
> ### * grid.reorder
1540
> 
1541
> flush(stderr()); flush(stdout())
1542
> 
1543
> ### Name: grid.reorder
1544
> ### Title: Reorder the children of a gTree
1545
> ### Aliases: grid.reorder reorderGrob
1546
> ### Keywords: dplot
1547
> 
1548
> ### ** Examples
1549
> 
1550
> # gTree with two children, "red-rect" and "blue-rect" (in that order)
1551
> gt <- gTree(children=gList(
1552
+                 rectGrob(gp=gpar(col=NA, fill="red"),
1553
+                          width=.8, height=.2, name="red-rect"),
1554
+                 rectGrob(gp=gpar(col=NA, fill="blue"),
1555
+                          width=.2, height=.8, name="blue-rect")),
1556
+             name="gt")
1557
> grid.newpage()
1558
> grid.draw(gt)
1559
> # Spec entire order as numeric (blue-rect, red-rect)
1560
> grid.reorder("gt", 2:1)
1561
> # Spec entire order as character
1562
> grid.reorder("gt", c("red-rect", "blue-rect"))
1563
> # Only spec the one I want behind as character
1564
> grid.reorder("gt", "blue-rect")
1565
> # Only spec the one I want in front as character
1566
> grid.reorder("gt", "blue-rect", back=FALSE)
1567
> 
1568
> 
1569
> 
1570
> cleanEx()
56186 murdoch 1571
> nameEx("grid.roundrect")
1572
> ### * grid.roundrect
1573
> 
1574
> flush(stderr()); flush(stdout())
1575
> 
1576
> ### Name: roundrect
1577
> ### Title: Draw a rectangle with rounded corners
1578
> ### Aliases: roundrect grid.roundrect roundrectGrob
1579
> ### Keywords: dplot
1580
> 
1581
> ### ** Examples
1582
> 
1583
> grid.roundrect(width=.5, height=.5, name="rr")
80081 hornik 1584
> theta <- seq(0, 360, length.out=50)
61435 ripley 1585
> for (i in 1:50)
56186 murdoch 1586
+     grid.circle(x=grobX("rr", theta[i]),
1587
+                 y=grobY("rr", theta[i]),
1588
+                 r=unit(1, "mm"),
1589
+                 gp=gpar(fill="black"))
1590
> 
1591
> 
1592
> 
1593
> cleanEx()
1594
> nameEx("grid.show.layout")
1595
> ### * grid.show.layout
1596
> 
1597
> flush(stderr()); flush(stdout())
1598
> 
1599
> ### Name: grid.show.layout
1600
> ### Title: Draw a Diagram of a Grid Layout
1601
> ### Aliases: grid.show.layout
1602
> ### Keywords: dplot
1603
> 
1604
> ### ** Examples
1605
> 
61435 ripley 1606
> ## Diagram of a simple layout
56186 murdoch 1607
> grid.show.layout(grid.layout(4,2,
1608
+                      heights=unit(rep(1, 4),
1609
+                                   c("lines", "lines", "lines", "null")),
1610
+                      widths=unit(c(1, 1), "inches")))
1611
> 
1612
> 
1613
> 
1614
> cleanEx()
1615
> nameEx("grid.show.viewport")
1616
> ### * grid.show.viewport
1617
> 
1618
> flush(stderr()); flush(stdout())
1619
> 
1620
> ### Name: grid.show.viewport
1621
> ### Title: Draw a Diagram of a Grid Viewport
1622
> ### Aliases: grid.show.viewport
1623
> ### Keywords: dplot
1624
> 
1625
> ### ** Examples
1626
> 
1627
> ## Diagram of a sample viewport
1628
> grid.show.viewport(viewport(x=0.6, y=0.6,
80081 hornik 1629
+                             width=unit(1, "inches"), height=unit(1, "inches")))
56186 murdoch 1630
> grid.show.viewport(viewport(layout.pos.row=2, layout.pos.col=2:3),
1631
+                    grid.layout(3, 4))
1632
> 
1633
> 
1634
> 
1635
> cleanEx()
81097 murrell 1636
> nameEx("grid.stroke")
1637
> ### * grid.stroke
1638
> 
1639
> flush(stderr()); flush(stdout())
1640
> 
1641
> ### Name: grid.stroke
1642
> ### Title: Stroke or Fill a Path
1643
> ### Aliases: grid.stroke strokeGrob strokeGrob.grob strokeGrob.GridPath
1644
> ###   grid.fill fillGrob fillGrob.grob fillGrob.GridPath grid.fillStroke
1645
> ###   fillStrokeGrob fillStrokeGrob.grob fillStrokeGrob.GridPath as.path
1646
> ### Keywords: dplot
1647
> 
1648
> ### ** Examples
1649
> 
1650
> ## NOTE: on devices without support for stroking and filling
1651
> ##       nothing will be drawn
1652
> grid.newpage()
1653
> grid.stroke(textGrob("hello", gp=gpar(cex=10)))
1654
> grid.fill(circleGrob(1:2/3, r=.3), gp=gpar(fill=rgb(1,0,0,.5)))
1655
> 
1656
> 
1657
> 
1658
> cleanEx()
56186 murdoch 1659
> nameEx("grid.text")
1660
> ### * grid.text
1661
> 
1662
> flush(stderr()); flush(stdout())
1663
> 
1664
> ### Name: grid.text
1665
> ### Title: Draw Text
1666
> ### Aliases: grid.text textGrob
1667
> ### Keywords: dplot
1668
> 
1669
> ### ** Examples
1670
> 
1671
> grid.newpage()
1672
> x <- stats::runif(20)
1673
> y <- stats::runif(20)
1674
> rot <- stats::runif(20, 0, 360)
1675
> grid.text("SOMETHING NICE AND BIG", x=x, y=y, rot=rot,
1676
+           gp=gpar(fontsize=20, col="grey"))
1677
> grid.text("SOMETHING NICE AND BIG", x=x, y=y, rot=rot,
80081 hornik 1678
+           gp=gpar(fontsize=20), check.overlap=TRUE)
83475 maechler 1679
> 
1680
> grid.newpage() ## plotmath example
1681
> grid.text(quote(frac(e^{-x^2/2}, sqrt(2*pi))), x=x, y=y, rot=stats::runif(20, -45,45),
1682
+           gp=gpar(fontsize=17, col=4), check.overlap=TRUE)
1683
> 
56186 murdoch 1684
> grid.newpage()
1685
> draw.text <- function(just, i, j) {
1686
+   grid.text("ABCD", x=x[j], y=y[i], just=just)
1687
+   grid.text(deparse(substitute(just)), x=x[j], y=y[i] + unit(2, "lines"),
1688
+             gp=gpar(col="grey", fontsize=8))
1689
+ }
1690
> x <- unit(1:4/5, "npc")
1691
> y <- unit(1:4/5, "npc")
1692
> grid.grill(h=y, v=x, gp=gpar(col="grey"))
1693
> draw.text(c("bottom"), 1, 1)
1694
> draw.text(c("left", "bottom"), 2, 1)
1695
> draw.text(c("right", "bottom"), 3, 1)
1696
> draw.text(c("centre", "bottom"), 4, 1)
1697
> draw.text(c("centre"), 1, 2)
1698
> draw.text(c("left", "centre"), 2, 2)
1699
> draw.text(c("right", "centre"), 3, 2)
1700
> draw.text(c("centre", "centre"), 4, 2)
1701
> draw.text(c("top"), 1, 3)
1702
> draw.text(c("left", "top"), 2, 3)
1703
> draw.text(c("right", "top"), 3, 3)
1704
> draw.text(c("centre", "top"), 4, 3)
1705
> draw.text(c(), 1, 4)
1706
> draw.text(c("left"), 2, 4)
1707
> draw.text(c("right"), 3, 4)
1708
> draw.text(c("centre"), 4, 4)
1709
> 
1710
> 
1711
> 
1712
> cleanEx()
1713
> nameEx("grid.xspline")
1714
> ### * grid.xspline
1715
> 
1716
> flush(stderr()); flush(stdout())
1717
> 
1718
> ### Name: grid.xspline
1719
> ### Title: Draw an Xspline
1720
> ### Aliases: grid.xspline xsplineGrob
1721
> ### Keywords: dplot
1722
> 
1723
> ### ** Examples
1724
> 
1725
> x <- c(0.25, 0.25, 0.75, 0.75)
1726
> y <- c(0.25, 0.75, 0.75, 0.25)
1727
> 
1728
> xsplineTest <- function(s, i, j, open) {
1729
+   pushViewport(viewport(layout.pos.col=j, layout.pos.row=i))
1730
+   grid.points(x, y, default.units="npc", pch=16, size=unit(2, "mm"))
1731
+   grid.xspline(x, y, shape=s, open=open, gp=gpar(fill="grey"))
1732
+   grid.text(s, gp=gpar(col="grey"),
1733
+             x=unit(x, "npc") + unit(c(-1, -1, 1, 1), "mm"),
1734
+             y=unit(y, "npc") + unit(c(-1, 1, 1, -1), "mm"),
1735
+             hjust=c(1, 1, 0, 0),
1736
+             vjust=c(1, 0, 0, 1))
1737
+   popViewport()
1738
+ }
1739
> 
1740
> pushViewport(viewport(width=.5, x=0, just="left",
1741
+                       layout=grid.layout(3, 3, respect=TRUE)))
1742
> pushViewport(viewport(layout.pos.row=1))
1743
> grid.text("Open Splines", y=1, just="bottom")
1744
> popViewport()
1745
> xsplineTest(c(0, -1, -1, 0), 1, 1, TRUE)
1746
> xsplineTest(c(0, -1,  0, 0), 1, 2, TRUE)
1747
> xsplineTest(c(0, -1,  1, 0), 1, 3, TRUE)
1748
> xsplineTest(c(0,  0, -1, 0), 2, 1, TRUE)
1749
> xsplineTest(c(0,  0,  0, 0), 2, 2, TRUE)
1750
> xsplineTest(c(0,  0,  1, 0), 2, 3, TRUE)
1751
> xsplineTest(c(0,  1, -1, 0), 3, 1, TRUE)
1752
> xsplineTest(c(0,  1,  0, 0), 3, 2, TRUE)
1753
> xsplineTest(c(0,  1,  1, 0), 3, 3, TRUE)
1754
> popViewport()
1755
> pushViewport(viewport(width=.5, x=1, just="right",
1756
+                       layout=grid.layout(3, 3, respect=TRUE)))
1757
> pushViewport(viewport(layout.pos.row=1))
1758
> grid.text("Closed Splines", y=1, just="bottom")
1759
> popViewport()
1760
> xsplineTest(c(-1, -1, -1, -1), 1, 1, FALSE)
1761
> xsplineTest(c(-1, -1,  0, -1), 1, 2, FALSE)
1762
> xsplineTest(c(-1, -1,  1, -1), 1, 3, FALSE)
1763
> xsplineTest(c( 0,  0, -1,  0), 2, 1, FALSE)
1764
> xsplineTest(c( 0,  0,  0,  0), 2, 2, FALSE)
1765
> xsplineTest(c( 0,  0,  1,  0), 2, 3, FALSE)
1766
> xsplineTest(c( 1,  1, -1,  1), 3, 1, FALSE)
1767
> xsplineTest(c( 1,  1,  0,  1), 3, 2, FALSE)
1768
> xsplineTest(c( 1,  1,  1,  1), 3, 3, FALSE)
1769
> popViewport()
1770
> 
1771
> 
1772
> 
1773
> cleanEx()
64168 ripley 1774
> nameEx("legendGrob")
1775
> ### * legendGrob
1776
> 
1777
> flush(stderr()); flush(stdout())
1778
> 
1779
> ### Name: legendGrob
1780
> ### Title: Constructing a Legend Grob
1781
> ### Aliases: legendGrob grid.legend
1782
> ### Keywords: aplot
1783
> 
1784
> ### ** Examples
1785
> 
65071 maechler 1786
>   ## Data:
1787
>   n <- 10
1788
>   x <- stats::runif(n) ; y1 <- stats::runif(n) ; y2 <- stats::runif(n)
1789
>   ## Construct the grobs :
1790
>   plot <- gTree(children=gList(rectGrob(),
1791
+                   pointsGrob(x, y1, pch=21, gp=gpar(col=2, fill="gray")),
1792
+                   pointsGrob(x, y2, pch=22, gp=gpar(col=3, fill="gray")),
1793
+                   xaxisGrob(),
1794
+                   yaxisGrob()))
1795
>   legd <- legendGrob(c("Girls", "Boys", "Other"), pch=21:23,
1796
+                      gp=gpar(col = 2:4, fill = "gray"))
1797
>   gg <- packGrob(packGrob(frameGrob(), plot),
1798
+                  legd, height=unit(1,"null"), side="right")
64168 ripley 1799
> 
65071 maechler 1800
>   ## Now draw it on a new device page:
1801
>   grid.newpage()
1802
>   pushViewport(viewport(width=0.8, height=0.8))
1803
>   grid.draw(gg)
64168 ripley 1804
> 
1805
> 
65071 maechler 1806
> 
64168 ripley 1807
> cleanEx()
63911 murrell 1808
> nameEx("resolveRasterSize")
1809
> ### * resolveRasterSize
1810
> 
1811
> flush(stderr()); flush(stdout())
1812
> 
1813
> ### Name: resolveRasterSize
1814
> ### Title: Utility function to resolve the size of a raster grob
1815
> ### Aliases: resolveRasterSize
1816
> ### Keywords: dplot
1817
> 
1818
> ### ** Examples
1819
> 
1820
> # Square raster
1821
> rg <- rasterGrob(matrix(0))
1822
> # Fill the complete page (if page is square)
1823
> grid.newpage()
1824
> resolveRasterSize(rg)$height
1825
[1] 6.8inches
1826
> grid.draw(rg)
1827
> # Forced to fit tall thin region
1828
> grid.newpage()
1829
> pushViewport(viewport(width=.1))
1830
> resolveRasterSize(rg)$height
1831
[1] 0.68inches
1832
> grid.draw(rg)
1833
> 
1834
> 
1835
> 
1836
> cleanEx()
56186 murdoch 1837
> nameEx("showGrob")
1838
> ### * showGrob
1839
> 
1840
> flush(stderr()); flush(stdout())
1841
> 
1842
> ### Name: showGrob
84536 smeyer 1843
> ### Title: Label grid grobs
56186 murdoch 1844
> ### Aliases: showGrob
1845
> ### Keywords: dplot
1846
> 
1847
> ### ** Examples
1848
> 
1849
>     grid.newpage()
1850
>     gt <- gTree(childrenvp=vpStack(
1851
+                   viewport(x=0, width=.5, just="left", name="vp"),
1852
+                   viewport(y=.5, height=.5, just="bottom", name="vp2")),
1853
+                 children=gList(rectGrob(vp="vp::vp2", name="child")),
1854
+                 name="parent")
1855
>     grid.draw(gt)
1856
>     showGrob()
1857
>     showGrob(gPath="child")
1858
>     showGrob(recurse=FALSE)
1859
>     showGrob(depth=1)
1860
>     showGrob(depth=2)
1861
>     showGrob(depth=1:2)
1862
>     showGrob(gt)
1863
>     showGrob(gt, gPath="child")
1864
>     showGrob(just="left", gp=gpar(col="red", cex=.5), rot=45)
1865
>     showGrob(labelfun=function(grob, ...) {
1866
+         x <- grobX(grob, "west")
1867
+         y <- grobY(grob, "north")
1868
+         gTree(children=gList(rectGrob(x=x, y=y,
1869
+                 width=stringWidth(grob$name) + unit(2, "mm"),
1870
+                 height=stringHeight(grob$name) + unit(2, "mm"),
1871
+                 gp=gpar(col=NA, fill=rgb(1, 0, 0, .5)),
1872
+                 just=c("left", "top")),
1873
+                 textGrob(grob$name,
1874
+                          x=x + unit(1, "mm"), y=y - unit(1, "mm"),
1875
+                          just=c("left", "top"))))
1876
+     })
1877
> 
1878
> ## Not run: 
1879
> ##D     # Examples from higher-level packages
1880
> ##D 
1881
> ##D     library(lattice)
1882
> ##D     # Ctrl-c after first example
1883
> ##D     example(histogram)
1884
> ##D     showGrob()
1885
> ##D     showGrob(gPath="plot_01.ylab")
61435 ripley 1886
> ##D 
56186 murdoch 1887
> ##D     library(ggplot2)
1888
> ##D     # Ctrl-c after first example
1889
> ##D     example(qplot)
1890
> ##D     showGrob()
1891
> ##D     showGrob(recurse=FALSE)
1892
> ##D     showGrob(gPath="panel-3-3")
1893
> ##D     showGrob(gPath="axis.title", grep=TRUE)
1894
> ##D     showGrob(depth=2)
1895
> ## End(Not run)
1896
> 
1897
> 
1898
> 
1899
> cleanEx()
1900
> nameEx("showViewport")
1901
> ### * showViewport
1902
> 
1903
> flush(stderr()); flush(stdout())
1904
> 
1905
> ### Name: showViewport
84536 smeyer 1906
> ### Title: Display grid viewports
56186 murdoch 1907
> ### Aliases: showViewport
1908
> ### Keywords: dplot
1909
> 
1910
> ### ** Examples
1911
> 
61044 murrell 1912
> showViewport(viewport(width=.5, height=.5, name="vp"))
56186 murdoch 1913
> 
69002 ripley 1914
> grid.newpage()
1915
> pushViewport(viewport(width=.5, height=.5, name="vp"))
1916
> upViewport()
1917
> showViewport(vpPath("vp"))
1918
> 
61044 murrell 1919
> showViewport(vpStack(viewport(width=.5, height=.5, name="vp1"),
1920
+                      viewport(width=.5, height=.5, name="vp2")),
56186 murdoch 1921
+              newpage=TRUE)
1922
> 
61044 murrell 1923
> showViewport(vpStack(viewport(width=.5, height=.5, name="vp1"),
1924
+                      viewport(width=.5, height=.5, name="vp2")),
56186 murdoch 1925
+              fill=rgb(1:0, 0:1, 0, .1),
1926
+              newpage=TRUE)
1927
> 
1928
> 
1929
> 
1930
> cleanEx()
1931
> nameEx("unit")
1932
> ### * unit
1933
> 
1934
> flush(stderr()); flush(stdout())
1935
> 
1936
> ### Name: unit
1937
> ### Title: Function to Create a Unit Object
83781 murrell 1938
> ### Aliases: unit is.unit
56186 murdoch 1939
> ### Keywords: dplot
1940
> 
1941
> ### ** Examples
1942
> 
1943
> unit(1, "npc")
1944
[1] 1npc
1945
> unit(1:3/4, "npc")
1946
[1] 0.25npc 0.5npc  0.75npc
1947
> unit(1:3/4, "npc") + unit(1, "inches")
77889 murrell 1948
[1] sum(0.25npc, 1inches) sum(0.5npc, 1inches)  sum(0.75npc, 1inches)
56186 murdoch 1949
> min(unit(0.5, "npc"), unit(1, "inches"))
1950
[1] min(0.5npc, 1inches)
1951
> unit.c(unit(0.5, "npc"), unit(2, "inches") + unit(1:3/4, "npc"),
1952
+        unit(1, "strwidth", "hi there"))
77889 murrell 1953
[1] 0.5npc                sum(2inches, 0.25npc) sum(2inches, 0.5npc) 
1954
[4] sum(2inches, 0.75npc) 1strwidth            
70284 murrell 1955
> x <- unit(1:5, "npc")
1956
> x[2:4]
1957
[1] 2npc 3npc 4npc
1958
> x[2:4] <- unit(1, "mm")
1959
> x
1960
[1] 1npc 1mm  1mm  1mm  5npc
56186 murdoch 1961
> 
1962
> 
1963
> 
1964
> cleanEx()
1965
> nameEx("unit.length")
1966
> ### * unit.length
1967
> 
1968
> flush(stderr()); flush(stdout())
1969
> 
1970
> ### Name: unit.length
1971
> ### Title: Length of a Unit Object
1972
> ### Aliases: unit.length
1973
> ### Keywords: dplot
1974
> 
1975
> ### ** Examples
1976
> 
1977
> length(unit(1:3, "npc"))
1978
[1] 3
1979
> length(unit(1:3, "npc") + unit(1, "inches"))
1980
[1] 3
1981
> length(max(unit(1:3, "npc") + unit(1, "inches")))
1982
[1] 1
1983
> length(max(unit(1:3, "npc") + unit(1, "strwidth", "a"))*4)
1984
[1] 1
1985
> length(unit(1:3, "npc") + unit(1, "strwidth", "a")*4)
1986
[1] 3
1987
> 
1988
> 
1989
> 
1990
> cleanEx()
1991
> nameEx("unit.pmin")
1992
> ### * unit.pmin
1993
> 
1994
> flush(stderr()); flush(stdout())
1995
> 
1996
> ### Name: unit.pmin
1997
> ### Title: Parallel Unit Minima and Maxima
77889 murrell 1998
> ### Aliases: unit.pmin unit.pmax unit.psum
56186 murdoch 1999
> ### Keywords: dplot
2000
> 
2001
> ### ** Examples
2002
> 
2003
> max(unit(1:3, "cm"), unit(0.5, "npc"))
2004
[1] max(1cm, 2cm, 3cm, 0.5npc)
2005
> unit.pmax(unit(1:3, "cm"), unit(0.5, "npc"))
2006
[1] max(1cm, 0.5npc) max(2cm, 0.5npc) max(3cm, 0.5npc)
2007
> 
2008
> 
2009
> 
2010
> cleanEx()
2011
> nameEx("unit.rep")
2012
> ### * unit.rep
2013
> 
2014
> flush(stderr()); flush(stdout())
2015
> 
2016
> ### Name: unit.rep
2017
> ### Title: Replicate Elements of Unit Objects
2018
> ### Aliases: unit.rep
2019
> ### Keywords: dplot
2020
> 
2021
> ### ** Examples
2022
> 
2023
> rep(unit(1:3, "npc"), 3)
2024
[1] 1npc 2npc 3npc 1npc 2npc 3npc 1npc 2npc 3npc
2025
> rep(unit(1:3, "npc"), 1:3)
2026
[1] 1npc 2npc 2npc 3npc 3npc 3npc
2027
> rep(unit(1:3, "npc") + unit(1, "inches"), 3)
77889 murrell 2028
[1] sum(1npc, 1inches) sum(2npc, 1inches) sum(3npc, 1inches) sum(1npc, 1inches)
2029
[5] sum(2npc, 1inches) sum(3npc, 1inches) sum(1npc, 1inches) sum(2npc, 1inches)
2030
[9] sum(3npc, 1inches)
56186 murdoch 2031
> rep(max(unit(1:3, "npc") + unit(1, "inches")), 3)
77889 murrell 2032
[1] max(sum(1npc, 1inches), sum(2npc, 1inches), sum(3npc, 1inches))
2033
[2] max(sum(1npc, 1inches), sum(2npc, 1inches), sum(3npc, 1inches))
2034
[3] max(sum(1npc, 1inches), sum(2npc, 1inches), sum(3npc, 1inches))
56186 murdoch 2035
> rep(max(unit(1:3, "npc") + unit(1, "strwidth", "a"))*4, 3)
77889 murrell 2036
[1] 4*max(sum(1npc, 1strwidth), sum(2npc, 1strwidth), sum(3npc, 1strwidth))
2037
[2] 4*max(sum(1npc, 1strwidth), sum(2npc, 1strwidth), sum(3npc, 1strwidth))
2038
[3] 4*max(sum(1npc, 1strwidth), sum(2npc, 1strwidth), sum(3npc, 1strwidth))
56186 murdoch 2039
> rep(unit(1:3, "npc") + unit(1, "strwidth", "a")*4, 3)
77889 murrell 2040
[1] sum(1npc, 4strwidth) sum(2npc, 4strwidth) sum(3npc, 4strwidth)
2041
[4] sum(1npc, 4strwidth) sum(2npc, 4strwidth) sum(3npc, 4strwidth)
2042
[7] sum(1npc, 4strwidth) sum(2npc, 4strwidth) sum(3npc, 4strwidth)
56186 murdoch 2043
> 
2044
> 
2045
> 
2046
> cleanEx()
77325 murrell 2047
> nameEx("unitType")
2048
> ### * unitType
2049
> 
2050
> flush(stderr()); flush(stdout())
2051
> 
2052
> ### Name: unitType
2053
> ### Title: Return the Units of a Unit Object
2054
> ### Aliases: unitType
2055
> ### Keywords: dplot
2056
> 
2057
> ### ** Examples
2058
> 
77889 murrell 2059
> u <- unit(1:5, c("cm", "mm", "in", "pt", "null"))
2060
> 
2061
> unitType(u)
2062
[1] "cm"     "mm"     "inches" "points" "null"  
77325 murrell 2063
> unitType(unit(1, "npc"))
2064
[1] "npc"
2065
> unitType(unit(1:3/4, "npc"))
2066
[1] "npc" "npc" "npc"
2067
> unitType(unit(1:3/4, "npc") + unit(1, "inches"))
2068
[1] "sum" "sum" "sum"
2069
> unitType(min(unit(0.5, "npc"), unit(1, "inches")))
2070
[1] "min"
2071
> unitType(unit.c(unit(0.5, "npc"), unit(2, "inches") + unit(1:3/4, "npc"),
2072
+                 unit(1, "strwidth", "hi there")))
2073
[1] "npc"      "sum"      "sum"      "sum"      "strwidth"
77889 murrell 2074
> unitType(min(unit(1, "in"), unit(1, "npc") + unit(1, "mm")))
2075
[1] "min"
77325 murrell 2076
> 
77889 murrell 2077
> unitType(u, recurse=TRUE)
2078
$cm
2079
[1] "cm"
2080
 
2081
$mm
2082
[1] "mm"
2083
 
2084
$inches
2085
[1] "inches"
2086
 
2087
$points
2088
[1] "points"
2089
 
2090
$null
2091
[1] "null"
2092
 
2093
> unitType(unit(1, "npc"), recurse=TRUE)
2094
$npc
2095
[1] "npc"
2096
 
2097
> unitType(unit(1:3/4, "npc"), recurse=TRUE)
2098
$npc
2099
[1] "npc"
2100
 
2101
$npc
2102
[1] "npc"
2103
 
2104
$npc
2105
[1] "npc"
2106
 
2107
> unitType(unit(1:3/4, "npc") + unit(1, "inches"), recurse=TRUE)
2108
$sum
2109
$sum$npc
2110
[1] "npc"
2111
 
2112
$sum$inches
2113
[1] "inches"
2114
 
2115
 
2116
$sum
2117
$sum$npc
2118
[1] "npc"
2119
 
2120
$sum$inches
2121
[1] "inches"
2122
 
2123
 
2124
$sum
2125
$sum$npc
2126
[1] "npc"
2127
 
2128
$sum$inches
2129
[1] "inches"
2130
 
2131
 
2132
> unitType(min(unit(0.5, "npc"), unit(1, "inches")), recurse=TRUE)
2133
$min
2134
$min$npc
2135
[1] "npc"
2136
 
2137
$min$inches
2138
[1] "inches"
2139
 
2140
 
2141
> unitType(unit.c(unit(0.5, "npc"), unit(2, "inches") + unit(1:3/4, "npc"),
2142
+                 unit(1, "strwidth", "hi there")), recurse=TRUE)
2143
$npc
2144
[1] "npc"
2145
 
2146
$sum
2147
$sum$inches
2148
[1] "inches"
2149
 
2150
$sum$npc
2151
[1] "npc"
2152
 
2153
 
2154
$sum
2155
$sum$inches
2156
[1] "inches"
2157
 
2158
$sum$npc
2159
[1] "npc"
2160
 
2161
 
2162
$sum
2163
$sum$inches
2164
[1] "inches"
2165
 
2166
$sum$npc
2167
[1] "npc"
2168
 
2169
 
2170
$strwidth
2171
[1] "strwidth"
2172
 
2173
> unitType(min(unit(1, "in"), unit(1, "npc") + unit(1, "mm")), recurse=TRUE)
2174
$min
2175
$min$inches
2176
[1] "inches"
2177
 
2178
$min$sum
2179
$min$sum$npc
2180
[1] "npc"
2181
 
2182
$min$sum$mm
2183
[1] "mm"
2184
 
2185
 
2186
 
2187
> unlist(unitType(min(unit(1, "in"), unit(1, "npc") + unit(1, "mm")),
2188
+                 recurse=TRUE))
2189
 min.inches min.sum.npc  min.sum.mm 
2190
   "inches"       "npc"        "mm" 
77325 murrell 2191
> 
2192
> 
77889 murrell 2193
> 
77325 murrell 2194
> cleanEx()
56186 murdoch 2195
> nameEx("viewport")
2196
> ### * viewport
2197
> 
2198
> flush(stderr()); flush(stdout())
2199
> 
2200
> ### Name: Grid Viewports
2201
> ### Title: Create a Grid Viewport
2202
> ### Aliases: viewport vpList vpStack vpTree
2203
> ### Keywords: dplot
2204
> 
2205
> ### ** Examples
2206
> 
2207
> # Diagram of a sample viewport
2208
> grid.show.viewport(viewport(x=0.6, y=0.6,
80081 hornik 2209
+                    width=unit(1, "inches"), height=unit(1, "inches")))
56186 murdoch 2210
> # Demonstrate viewport clipping
2211
> clip.demo <- function(i, j, clip1, clip2) {
2212
+   pushViewport(viewport(layout.pos.col=i,
2213
+                          layout.pos.row=j))
2214
+   pushViewport(viewport(width=0.6, height=0.6, clip=clip1))
2215
+   grid.rect(gp=gpar(fill="white"))
2216
+   grid.circle(r=0.55, gp=gpar(col="red", fill="pink"))
2217
+   popViewport()
2218
+   pushViewport(viewport(width=0.6, height=0.6, clip=clip2))
2219
+   grid.polygon(x=c(0.5, 1.1, 0.6, 1.1, 0.5, -0.1, 0.4, -0.1),
2220
+                y=c(0.6, 1.1, 0.5, -0.1, 0.4, -0.1, 0.5, 1.1),
2221
+                gp=gpar(col="blue", fill="light blue"))
2222
+   popViewport(2)
2223
+ }
2224
> 
2225
> grid.newpage()
2226
> grid.rect(gp=gpar(fill="grey"))
2227
> pushViewport(viewport(layout=grid.layout(2, 2)))
2228
> clip.demo(1, 1, FALSE, FALSE)
2229
> clip.demo(1, 2, TRUE, FALSE)
2230
> clip.demo(2, 1, FALSE, TRUE)
2231
> clip.demo(2, 2, TRUE, TRUE)
2232
> popViewport()
2233
> # Demonstrate turning clipping off
2234
> grid.newpage()
80081 hornik 2235
> pushViewport(viewport(width=.5, height=.5, clip="on"))
56186 murdoch 2236
> grid.rect()
2237
> grid.circle(r=.6, gp=gpar(lwd=10))
2238
> pushViewport(viewport(clip="inherit"))
2239
> grid.circle(r=.6, gp=gpar(lwd=5, col="grey"))
2240
> pushViewport(viewport(clip="off"))
2241
> grid.circle(r=.6)
2242
> popViewport(3)
2243
> # Demonstrate vpList, vpStack, and vpTree
2244
> grid.newpage()
80081 hornik 2245
> tree <- vpTree(viewport(width=0.8, height=0.8, name="A"),
2246
+                vpList(vpStack(viewport(x=0.1, y=0.1, width=0.5, height=0.5,
56186 murdoch 2247
+                                        just=c("left", "bottom"), name="B"),
80081 hornik 2248
+                               viewport(x=0.1, y=0.1, width=0.5, height=0.5,
56186 murdoch 2249
+                                        just=c("left", "bottom"), name="C"),
80081 hornik 2250
+                               viewport(x=0.1, y=0.1, width=0.5, height=0.5,
56186 murdoch 2251
+                                        just=c("left", "bottom"), name="D")),
80081 hornik 2252
+                       viewport(x=0.5, width=0.4, height=0.9,
56186 murdoch 2253
+                                just="left", name="E")))
2254
> pushViewport(tree)
2255
> for (i in LETTERS[1:5]) {
2256
+   seekViewport(i)
2257
+   grid.rect()
2258
+   grid.text(current.vpTree(FALSE),
2259
+             x=unit(1, "mm"), y=unit(1, "npc") - unit(1, "mm"),
2260
+             just=c("left", "top"),
2261
+             gp=gpar(fontsize=8))
2262
+ }
2263
> 
2264
> 
2265
> 
2266
> cleanEx()
81097 murrell 2267
> nameEx("viewportTransform")
2268
> ### * viewportTransform
2269
> 
2270
> flush(stderr()); flush(stdout())
2271
> 
2272
> ### Name: viewportTransform
2273
> ### Title: Define a Group Transformation
2274
> ### Aliases: viewportTransform viewportTranslate viewportScale
2275
> ###   viewportRotate defnTranslate defnScale defnRotate useTranslate
2276
> ###   useScale useRotate groupTranslate groupScale groupRotate groupShear
81107 murrell 2277
> ###   groupFlip
81097 murrell 2278
> ### Keywords: dplot
2279
> 
2280
> ### ** Examples
2281
> 
2282
> ## NOTE: on devices without support for groups nothing will be drawn
2283
> grid.newpage()
2284
> ## Define and use group in same viewport
2285
> pushViewport(viewport(width=.2, height=.2))
2286
> grid.define(circleGrob(gp=gpar(lwd=5)), name="circle")
2287
> grid.use("circle")
2288
> popViewport()
2289
> ## Use group in viewport that is translated and scaled
2290
> pushViewport(viewport(x=.2, y=.2, width=.1, height=.1))
2291
> grid.use("circle")
2292
> popViewport()
2293
> ## Use group in viewport that is translated and scaled
2294
> ## BUT only make use of the translation
2295
> pushViewport(viewport(x=.2, y=.8, width=.1, height=.1))
2296
> grid.use("circle", transform=viewportTranslate)
2297
> popViewport()
2298
> ## Use group in viewport that is translated and scaled
2299
> ## unevenly (distorted)
2300
> pushViewport(viewport(x=.8, y=.7, width=.2, height=.4))
2301
> grid.use("circle")
2302
> popViewport()
2303
> 
2304
> 
2305
> 
2306
> cleanEx()
56186 murdoch 2307
> nameEx("viewports")
2308
> ### * viewports
2309
> 
2310
> flush(stderr()); flush(stdout())
2311
> 
2312
> ### Name: Working with Viewports
2313
> ### Title: Maintaining and Navigating the Grid Viewport Tree
2314
> ### Aliases: pushViewport downViewport seekViewport popViewport upViewport
2315
> ### Keywords: dplot
2316
> 
2317
> ### ** Examples
2318
> 
2319
> # push the same viewport several times
2320
> grid.newpage()
2321
> vp <- viewport(width=0.5, height=0.5)
2322
> pushViewport(vp)
2323
> grid.rect(gp=gpar(col="blue"))
2324
> grid.text("Quarter of the device",
2325
+   y=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue"))
2326
> pushViewport(vp)
2327
> grid.rect(gp=gpar(col="red"))
2328
> grid.text("Quarter of the parent viewport",
2329
+   y=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="red"))
2330
> popViewport(2)
2331
> # push several viewports then navigate amongst them
2332
> grid.newpage()
2333
> grid.rect(gp=gpar(col="grey"))
2334
> grid.text("Top-level viewport",
2335
+   y=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="grey"))
2336
> if (interactive()) Sys.sleep(1.0)
2337
> pushViewport(viewport(width=0.8, height=0.7, name="A"))
2338
> grid.rect(gp=gpar(col="blue"))
2339
> grid.text("1. Push Viewport A",
2340
+   y=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue"))
2341
> if (interactive()) Sys.sleep(1.0)
2342
> pushViewport(viewport(x=0.1, width=0.3, height=0.6,
2343
+   just="left", name="B"))
2344
> grid.rect(gp=gpar(col="red"))
2345
> grid.text("2. Push Viewport B (in A)",
2346
+   y=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="red"))
2347
> if (interactive()) Sys.sleep(1.0)
2348
> upViewport(1)
2349
> grid.text("3. Up from B to A",
2350
+   y=unit(1, "npc") - unit(2, "lines"), gp=gpar(col="blue"))
2351
> if (interactive()) Sys.sleep(1.0)
2352
> pushViewport(viewport(x=0.5, width=0.4, height=0.8,
2353
+   just="left", name="C"))
2354
> grid.rect(gp=gpar(col="green"))
2355
> grid.text("4. Push Viewport C (in A)",
2356
+   y=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="green"))
2357
> if (interactive()) Sys.sleep(1.0)
2358
> pushViewport(viewport(width=0.8, height=0.6, name="D"))
2359
> grid.rect()
2360
> grid.text("5. Push Viewport D (in C)",
2361
+   y=unit(1, "npc") - unit(1, "lines"))
2362
> if (interactive()) Sys.sleep(1.0)
2363
> upViewport(0)
2364
> grid.text("6. Up from D to top-level",
2365
+   y=unit(1, "npc") - unit(2, "lines"), gp=gpar(col="grey"))
2366
> if (interactive()) Sys.sleep(1.0)
2367
> downViewport("D")
2368
> grid.text("7. Down from top-level to D",
2369
+   y=unit(1, "npc") - unit(2, "lines"))
2370
> if (interactive()) Sys.sleep(1.0)
2371
> seekViewport("B")
2372
> grid.text("8. Seek from D to B",
2373
+   y=unit(1, "npc") - unit(2, "lines"), gp=gpar(col="red"))
2374
> pushViewport(viewport(width=0.9, height=0.5, name="A"))
2375
> grid.rect()
2376
> grid.text("9. Push Viewport A (in B)",
2377
+   y=unit(1, "npc") - unit(1, "lines"))
2378
> if (interactive()) Sys.sleep(1.0)
2379
> seekViewport("A")
2380
> grid.text("10. Seek from B to A (in ROOT)",
2381
+   y=unit(1, "npc") - unit(3, "lines"), gp=gpar(col="blue"))
2382
> if (interactive()) Sys.sleep(1.0)
2383
> seekViewport(vpPath("B", "A"))
2384
> grid.text("11. Seek from\nA (in ROOT)\nto A (in B)")
2385
> popViewport(0)
2386
> 
2387
> 
2388
> 
2389
> cleanEx()
2390
> nameEx("vpPath")
2391
> ### * vpPath
2392
> 
2393
> flush(stderr()); flush(stdout())
2394
> 
2395
> ### Name: vpPath
2396
> ### Title: Concatenate Viewport Names
2397
> ### Aliases: vpPath
2398
> ### Keywords: dplot
2399
> 
2400
> ### ** Examples
2401
> 
2402
> vpPath("vp1", "vp2")
2403
vp1::vp2 
2404
> 
2405
> 
2406
> 
2407
> cleanEx()
2408
> nameEx("xsplinePoints")
2409
> ### * xsplinePoints
2410
> 
2411
> flush(stderr()); flush(stdout())
2412
> 
2413
> ### Name: xsplinePoints
85945 ripley 2414
> ### Title: Return the points that would be used to draw an xspline (or a
84536 smeyer 2415
> ###   Bezier curve)
57725 murrell 2416
> ### Aliases: xsplinePoints bezierPoints
56186 murdoch 2417
> ### Keywords: dplot
2418
> 
2419
> ### ** Examples
2420
> 
2421
> grid.newpage()
2422
> xsg <- xsplineGrob(c(.1, .1, .9, .9), c(.1, .9, .9, .1), shape=1)
2423
> grid.draw(xsg)
2424
> trace <- xsplinePoints(xsg)
2425
> grid.circle(trace$x, trace$y, default.units="inches", r=unit(.5, "mm"))
2426
> 
57725 murrell 2427
> grid.newpage()
2428
> vp <- viewport(width=.5)
2429
> xg <- xsplineGrob(x=c(0, .2, .4, .2, .5, .7, .9, .7),
2430
+                   y=c(.5, 1, .5, 0, .5, 1, .5, 0),
2431
+                   id=rep(1:2, each=4),
2432
+                   shape=1,
2433
+                   vp=vp)
2434
> grid.draw(xg)
2435
> trace <- xsplinePoints(xg)
2436
> pushViewport(vp)
61044 murrell 2437
> invisible(lapply(trace, function(t) grid.lines(t$x, t$y, gp=gpar(col="red"))))
57725 murrell 2438
> popViewport()
56186 murdoch 2439
> 
57725 murrell 2440
> grid.newpage()
2441
> bg <- bezierGrob(c(.2, .2, .8, .8), c(.2, .8, .8, .2))
2442
> grid.draw(bg)
2443
> trace <- bezierPoints(bg)
2444
> grid.circle(trace$x, trace$y, default.units="inches", r=unit(.5, "mm"))
56186 murdoch 2445
> 
57725 murrell 2446
> 
2447
> 
56186 murdoch 2448
> ### * <FOOTER>
2449
> ###
73819 hornik 2450
> cleanEx()
62439 ripley 2451
> options(digits = 7L)
61787 ripley 2452
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
85945 ripley 2453
Time elapsed:  0.464 0.026 0.493 0 0 
56186 murdoch 2454
> grDevices::dev.off()
2455
null device 
2456
          1 
2457
> ###
2458
> ### Local variables: ***
2459
> ### mode: outline-minor ***
2460
> ### outline-regexp: "\\(> \\)?### [*]+" ***
2461
> ### End: ***
2462
> quit('no')