The R Project SVN R

Rev

Rev 77447 | Rev 77499 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
56186 murdoch 1
 
77448 maechler 2
R Under development (unstable) (2019-11-22 r77447) -- "Unsuffered Consequences"
75937 ripley 3
Copyright (C) 2019 The R Foundation for Statistical Computing
77431 ripley 4
Platform: x86_64-pc-linux-gnu (64-bit)
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
  Natural language support but running in an English locale
11
 
12
R is a collaborative project with many contributors.
13
Type 'contributors()' for more information and
14
'citation()' on how to cite R or R packages in publications.
15
 
16
Type 'demo()' for some demos, 'help()' for on-line help, or
17
'help.start()' for an HTML browser interface to help.
18
Type 'q()' to quit R.
19
 
20
> pkgname <- "grDevices"
21
> source(file.path(R.home("share"), "R", "examples-header.R"))
22
> options(warn = 1)
23
> library('grDevices')
24
> 
61787 ripley 25
> base::assign(".oldSearch", base::search(), pos = 'CheckExEnv')
73819 hornik 26
> base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv')
56186 murdoch 27
> cleanEx()
28
> nameEx("Devices")
29
> ### * Devices
30
> 
31
> flush(stderr()); flush(stdout())
32
> 
33
> ### Name: Devices
34
> ### Title: List of Graphical Devices
35
> ### Aliases: Devices device
36
> ### Keywords: device
37
> 
38
> ### ** Examples
39
> ## Not run: 
40
> ##D ## open the default screen device on this platform if no device is
41
> ##D ## open
42
> ##D if(dev.cur() == 1) dev.new()
43
> ## End(Not run)
44
> 
45
> 
46
> cleanEx()
47
> nameEx("Hershey")
48
> ### * Hershey
49
> 
50
> flush(stderr()); flush(stdout())
51
> 
52
> ### Name: Hershey
53
> ### Title: Hershey Vector Fonts in R
54
> ### Aliases: Hershey
55
> ### Keywords: aplot
56
> 
57
> ### ** Examples
58
> 
59
> Hershey
60
$typeface
61
[1] "serif"             "sans serif"        "script"           
62
[4] "gothic english"    "gothic german"     "gothic italian"   
63
[7] "serif symbol"      "sans serif symbol"
64
 
65
$fontindex
66
[1] "plain"            "italic"           "bold"             "bold italic"     
67
[5] "cyrillic"         "oblique cyrillic" "EUC"             
68
 
69
$allowed
70
      [,1] [,2]
71
 [1,]    1    1
72
 [2,]    1    2
73
 [3,]    1    3
74
 [4,]    1    4
75
 [5,]    1    5
76
 [6,]    1    6
77
 [7,]    1    7
78
 [8,]    2    1
79
 [9,]    2    2
80
[10,]    2    3
81
[11,]    2    4
82
[12,]    3    1
83
[13,]    3    2
84
[14,]    3    3
85
[15,]    4    1
86
[16,]    5    1
87
[17,]    6    1
88
[18,]    7    1
89
[19,]    7    2
90
[20,]    7    3
91
[21,]    7    4
92
[22,]    8    1
93
[23,]    8    2
94
 
95
> 
96
> ## for tables of examples, see demo(Hershey)
97
> 
98
> 
99
> 
100
> cleanEx()
101
> nameEx("Japanese")
102
> ### * Japanese
103
> 
104
> flush(stderr()); flush(stdout())
105
> 
106
> ### Name: Japanese
107
> ### Title: Japanese characters in R
108
> ### Aliases: Japanese
109
> ### Keywords: aplot
110
> 
111
> ### ** Examples
112
> 
113
> require(graphics)
114
> 
61157 ripley 115
> plot(1:9, type = "n", axes = FALSE, frame = TRUE, ylab = "",
116
+      main = "example(Japanese)", xlab = "using Hershey fonts")
117
> par(cex = 3)
56186 murdoch 118
> Vf <- c("serif", "plain")
62738 murdoch 119
> text(4, 2, "\\#J244b\\#J245b\\#J2473", vfont = Vf)
120
> text(4, 4, "\\#J2538\\#J2563\\#J2551\\#J2573", vfont = Vf)
56186 murdoch 121
> text(4, 6, "\\#J467c\\#J4b5c", vfont = Vf)
122
> text(4, 8, "Japan", vfont = Vf)
61157 ripley 123
> par(cex = 1)
56186 murdoch 124
> text(8, 2, "Hiragana")
125
> text(8, 4, "Katakana")
126
> text(8, 6, "Kanji")
127
> text(8, 8, "English")
128
> 
129
> 
130
> 
131
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
132
> cleanEx()
133
> nameEx("Type1Font")
134
> ### * Type1Font
135
> 
136
> flush(stderr()); flush(stdout())
137
> 
138
> ### Name: Type1Font
139
> ### Title: Type 1 and CID Fonts
140
> ### Aliases: Type1Font CIDFont
141
> ### Keywords: device
142
> 
143
> ### ** Examples
144
> 
145
> ## This duplicates "ComputerModernItalic".
146
> CMitalic <- Type1Font("ComputerModern2",
147
+                       c("CM_regular_10.afm", "CM_boldx_10.afm",
148
+                         "cmti10.afm", "cmbxti10.afm",
149
+                         "CM_symbol_10.afm"),
150
+                       encoding = "TeXtext.enc")
151
> 
152
> ## Not run: 
153
> ##D ## This could be used by
154
> ##D postscript(family = CMitalic)
155
> ##D ## or
156
> ##D postscriptFonts(CMitalic = CMitalic)  # once in a session
157
> ##D postscript(family = "CMitalic", encoding = "TeXtext.enc")
158
> ## End(Not run)
159
> 
160
> 
161
> cleanEx()
162
> nameEx("adjustcolor")
163
> ### * adjustcolor
164
> 
165
> flush(stderr()); flush(stdout())
166
> 
167
> ### Name: adjustcolor
168
> ### Title: Adjust Colors in One or More Directions Conveniently.
169
> ### Aliases: adjustcolor
170
> 
171
> ### ** Examples
172
> 
173
> ## Illustrative examples :
174
> opal <- palette("default")
175
> stopifnot(identical(adjustcolor(1:8,       0.75),
176
+                     adjustcolor(palette(), 0.75)))
177
> cbind(palette(), adjustcolor(1:8, 0.75))
178
     [,1]      [,2]       
179
[1,] "black"   "#000000BF"
77336 murrell 180
[2,] "#DF536B" "#DF536BBF"
181
[3,] "#61D04F" "#61D04FBF"
77438 murrell 182
[4,] "#2297E6" "#2297E6BF"
183
[5,] "#28E2E5" "#28E2E5BF"
77336 murrell 184
[6,] "#D03AF5" "#D03AF5BF"
185
[7,] "#EEC21F" "#EEC21FBF"
186
[8,] "#656565" "#656565BF"
56186 murdoch 187
> 
188
> ##  alpha = 1/2 * previous alpha --> opaque colors
189
> x <- palette(adjustcolor(palette(), 0.5))
190
> 
191
> sines <- outer(1:20, 1:4, function(x, y) sin(x / 20 * pi * y))
192
> matplot(sines, type = "b", pch = 21:23, col = 2:5, bg = 2:5,
193
+         main = "Using an 'opaque ('translucent') color palette")
194
> 
61169 ripley 195
> x. <- adjustcolor(x, offset = c(0.5, 0.5, 0.5, 0), # <- "more white"
61157 ripley 196
+                   transform = diag(c(.7, .7, .7, 0.6)))
56186 murdoch 197
> cbind(x, x.)
198
     x         x.         
199
[1,] "black"   "#80808099"
77336 murrell 200
[2,] "#DF536B" "#FFBACA99"
201
[3,] "#61D04F" "#C3FFB799"
77438 murrell 202
[4,] "#2297E6" "#97E9FF99"
203
[5,] "#28E2E5" "#9BFFFF99"
77336 murrell 204
[6,] "#D03AF5" "#FFA8FF99"
205
[7,] "#EEC21F" "#FFFF9599"
206
[8,] "#656565" "#C6C6C699"
61169 ripley 207
> op <- par(bg = adjustcolor("goldenrod", offset = -rep(.4, 4)), xpd = NA)
208
> plot(0:9, 0:9, type = "n", axes = FALSE, xlab = "", ylab = "",
61157 ripley 209
+      main = "adjustcolor() -> translucent")
210
> text(1:8, labels = paste0(x,"++"), col = x., cex = 8)
56186 murdoch 211
> par(op)
212
> 
213
> ## and
214
> 
61169 ripley 215
> (M <- cbind( rbind( matrix(1/3, 3, 3), 0), c(0, 0, 0, 1)))
56186 murdoch 216
          [,1]      [,2]      [,3] [,4]
217
[1,] 0.3333333 0.3333333 0.3333333    0
218
[2,] 0.3333333 0.3333333 0.3333333    0
219
[3,] 0.3333333 0.3333333 0.3333333    0
220
[4,] 0.0000000 0.0000000 0.0000000    1
221
> adjustcolor(x, transform = M)
77438 murrell 222
[1] "#000000FF" "#8A8A8AFF" "#808080FF" "#8A8A8AFF" "#A5A5A5FF" "#AAAAAAFF"
77336 murrell 223
[7] "#9A9A9AFF" "#656565FF"
56186 murdoch 224
> 
225
> ## revert to previous palette: active
226
> palette(opal)
227
> 
228
> 
229
> 
230
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
231
> cleanEx()
232
> nameEx("as.raster")
233
> ### * as.raster
234
> 
235
> flush(stderr()); flush(stdout())
236
> 
237
> ### Name: as.raster
238
> ### Title: Create a Raster Object
239
> ### Aliases: is.raster as.raster as.raster.logical as.raster.numeric
69134 maechler 240
> ###   as.raster.raw as.raster.character as.raster.matrix as.raster.array
56186 murdoch 241
> ### Keywords: dplot
242
> 
243
> ### ** Examples
244
> 
245
> # A red gradient
246
> as.raster(matrix(hcl(0, 80, seq(50, 80, 10)),
61157 ripley 247
+                  nrow = 4, ncol = 5))
56186 murdoch 248
     [,1]      [,2]      [,3]      [,4]      [,5]     
249
[1,] "#C54E6D" "#C54E6D" "#C54E6D" "#C54E6D" "#C54E6D"
250
[2,] "#E16A86" "#E16A86" "#E16A86" "#E16A86" "#E16A86"
251
[3,] "#FE86A1" "#FE86A1" "#FE86A1" "#FE86A1" "#FE86A1"
252
[4,] "#FFA2BC" "#FFA2BC" "#FFA2BC" "#FFA2BC" "#FFA2BC"
253
> 
254
> # Vectors are 1-column matrices ...
255
> #   character vectors are color names ...
256
> as.raster(hcl(0, 80, seq(50, 80, 10)))
257
     [,1]     
258
[1,] "#C54E6D"
259
[2,] "#E16A86"
260
[3,] "#FE86A1"
261
[4,] "#FFA2BC"
262
> #   numeric vectors are greyscale ...
61157 ripley 263
> as.raster(1:5, max = 5)
56186 murdoch 264
     [,1]     
265
[1,] "#333333"
266
[2,] "#666666"
267
[3,] "#999999"
268
[4,] "#CCCCCC"
269
[5,] "#FFFFFF"
69134 maechler 270
> #   logical vectors are black and white ...
56186 murdoch 271
> as.raster(1:10 %% 2 == 0)
272
      [,1]     
273
 [1,] "#000000"
274
 [2,] "#FFFFFF"
275
 [3,] "#000000"
276
 [4,] "#FFFFFF"
277
 [5,] "#000000"
278
 [6,] "#FFFFFF"
279
 [7,] "#000000"
280
 [8,] "#FFFFFF"
281
 [9,] "#000000"
282
[10,] "#FFFFFF"
283
> 
284
> # ... unless nrow/ncol are supplied ...
61157 ripley 285
> as.raster(1:10 %% 2 == 0, nrow = 1)
56186 murdoch 286
     [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]     
287
[1,] "#000000" "#FFFFFF" "#000000" "#FFFFFF" "#000000" "#FFFFFF" "#000000"
288
     [,8]      [,9]      [,10]    
289
[1,] "#FFFFFF" "#000000" "#FFFFFF"
290
> 
69134 maechler 291
> # Matrix can also be logical or numeric (or raw) ...
61157 ripley 292
> as.raster(matrix(c(TRUE, FALSE), nrow = 3, ncol = 2))
56186 murdoch 293
     [,1]      [,2]     
294
[1,] "#FFFFFF" "#000000"
295
[2,] "#000000" "#FFFFFF"
296
[3,] "#FFFFFF" "#000000"
61157 ripley 297
> as.raster(matrix(1:3/4, nrow = 3, ncol = 4))
56186 murdoch 298
     [,1]      [,2]      [,3]      [,4]     
299
[1,] "#404040" "#404040" "#404040" "#404040"
300
[2,] "#808080" "#808080" "#808080" "#808080"
301
[3,] "#BFBFBF" "#BFBFBF" "#BFBFBF" "#BFBFBF"
302
> 
303
> # An array can be 3-plane numeric (R, G, B planes) ...
304
> as.raster(array(c(0:1, rep(0.5, 4)), c(2, 1, 3)))
305
     [,1]     
306
[1,] "#008080"
307
[2,] "#FF8080"
308
> 
309
> # ... or 4-plane numeric (R, G, B, A planes)
310
> as.raster(array(c(0:1, rep(0.5, 6)), c(2, 1, 4)))
311
     [,1]       
312
[1,] "#00808080"
313
[2,] "#FF808080"
314
> 
315
> # subsetting
61157 ripley 316
> r <- as.raster(matrix(colors()[1:100], ncol = 10))
56186 murdoch 317
> r[, 2]
318
      [,1]         
319
 [1,] "aquamarine3"
320
 [2,] "aquamarine4"
321
 [3,] "azure"      
322
 [4,] "azure1"     
323
 [5,] "azure2"     
324
 [6,] "azure3"     
325
 [7,] "azure4"     
326
 [8,] "beige"      
327
 [9,] "bisque"     
328
[10,] "bisque1"    
329
> r[2:4, 2:5]
330
     [,1]          [,2]      [,3]     [,4]        
331
[1,] "aquamarine4" "bisque3" "brown"  "cadetblue" 
332
[2,] "azure"       "bisque4" "brown1" "cadetblue1"
333
[3,] "azure1"      "black"   "brown2" "cadetblue2"
334
> 
335
> # assigning to subset
336
> r[2:4, 2:5] <- "white"
337
> 
338
> # comparison
339
> r == "white"
340
       [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10]
341
 [1,]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
342
 [2,] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
343
 [3,] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
344
 [4,] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
345
 [5,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
346
 [6,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
347
 [7,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
348
 [8,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
349
 [9,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
350
[10,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
351
> 
352
> ## Don't show: 
353
> stopifnot(r[] == r,
354
+           identical(r[3:5], colors()[3:5]))
355
> r[2:4] <- "black"
61169 ripley 356
> stopifnot(identical(r[1:4, 1], as.raster(c("white", rep("black", 3)))))
66943 maechler 357
> ## End(Don't show)
56186 murdoch 358
> 
359
> 
360
> 
361
> cleanEx()
57122 maechler 362
> nameEx("axisTicks")
363
> ### * axisTicks
364
> 
365
> flush(stderr()); flush(stdout())
366
> 
367
> ### Name: axisTicks
368
> ### Title: Compute Pretty Axis Tick Scales
369
> ### Aliases: axisTicks .axisPars
370
> ### Keywords: dplot
371
> 
372
> ### ** Examples
373
> 
374
> ##--- Demonstrating correspondence between graphics'
375
> ##--- axis() and the graphics-engine agnostic  axisTicks() :
376
> 
377
> require("graphics")
378
> plot(10*(0:10)); (pu <- par("usr"))
379
[1]   0.6  11.4  -4.0 104.0
380
> aX <- function(side, at, ...)
62642 hornik 381
+     axis(side, at = at, labels = FALSE, lwd.ticks = 2, col.ticks = 2,
382
+          tck = 0.05, ...)
61169 ripley 383
> aX(1, print(xa <- axisTicks(pu[1:2], log = FALSE)))  # x axis
57122 maechler 384
[1]  2  4  6  8 10
61169 ripley 385
> aX(2, print(ya <- axisTicks(pu[3:4], log = FALSE)))  # y axis
57122 maechler 386
[1]   0  20  40  60  80 100
387
> 
61157 ripley 388
> axisTicks(pu[3:4], log = FALSE, n = 10)
57122 maechler 389
 [1]   0  10  20  30  40  50  60  70  80  90 100
390
> 
61157 ripley 391
> plot(10*(0:10), log = "y"); (pu <- par("usr"))
57122 maechler 392
Warning in xy.coords(x, y, xlabel, ylabel, log) :
393
  1 y value <= 0 omitted from logarithmic plot
394
[1]  0.60 11.40  0.96  2.04
61169 ripley 395
> aX(2, print(ya <- axisTicks(pu[3:4], log = TRUE)))  # y axis
57122 maechler 396
[1]  10  20  50 100
397
> 
61157 ripley 398
> plot(2^(0:9), log = "y"); (pu <- par("usr"))
57122 maechler 399
[1]  0.6400000 10.3600000 -0.1083708  2.8176408
61169 ripley 400
> aX(2, print(ya <- axisTicks(pu[3:4], log = TRUE)))  # y axis
57122 maechler 401
[1]   1   2   5  10  20  50 100 200 500
402
> 
403
> 
404
> 
405
> 
406
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
407
> cleanEx()
56186 murdoch 408
> nameEx("boxplot.stats")
409
> ### * boxplot.stats
410
> 
411
> flush(stderr()); flush(stdout())
412
> 
413
> ### Name: boxplot.stats
414
> ### Title: Box Plot Statistics
415
> ### Aliases: boxplot.stats
416
> ### Keywords: dplot
417
> 
418
> ### ** Examples
419
> 
420
> require(stats)
421
> x <- c(1:100, 1000)
422
> (b1 <- boxplot.stats(x))
423
$stats
424
[1]   1  26  51  76 100
425
 
426
$n
427
[1] 101
428
 
429
$conf
430
[1] 43.13921 58.86079
431
 
432
$out
433
[1] 1000
434
 
61157 ripley 435
> (b2 <- boxplot.stats(x, do.conf = FALSE, do.out = FALSE))
56186 murdoch 436
$stats
437
[1]   1  26  51  76 100
438
 
439
$n
440
[1] 101
441
 
442
$conf
443
NULL
444
 
445
$out
446
numeric(0)
447
 
61157 ripley 448
> stopifnot(b1 $ stats == b2 $ stats) # do.out = FALSE is still robust
449
> boxplot.stats(x, coef = 3, do.conf = FALSE)
56186 murdoch 450
$stats
451
[1]   1  26  51  76 100
452
 
453
$n
454
[1] 101
455
 
456
$conf
457
NULL
458
 
459
$out
460
[1] 1000
461
 
462
> ## no outlier treatment:
463
> boxplot.stats(x, coef = 0)
464
$stats
465
[1]    1   26   51   76 1000
466
 
467
$n
468
[1] 101
469
 
470
$conf
471
[1] 43.13921 58.86079
472
 
473
$out
474
numeric(0)
475
 
476
> 
477
> boxplot.stats(c(x, NA)) # slight change : n is 101
478
$stats
479
[1]   1  26  51  76 100
480
 
481
$n
482
[1] 101
483
 
484
$conf
485
[1] 43.13921 58.86079
486
 
487
$out
488
[1] 1000
489
 
490
> (r <- boxplot.stats(c(x, -1:1/0)))
491
$stats
492
[1]   1.0  25.5  51.0  76.5 100.0
493
 
494
$n
495
[1] 103
496
 
497
$conf
498
[1] 43.06022 58.93978
499
 
500
$out
501
[1] 1000 -Inf  Inf
502
 
503
> stopifnot(r$out == c(1000, -Inf, Inf))
504
> 
505
> ## Don't show: 
506
>  ## Difference between quartiles and hinges :
507
>  nn <- 1:17 ;  n4 <- nn %% 4
508
>  hin <- sapply(sapply(nn, seq), function(x) boxplot.stats(x)$stats[c(2,4)])
509
>  q13 <- sapply(sapply(nn, seq), quantile, probs = c(1,3)/4, names = FALSE)
510
>  m <- t(rbind(q13,hin))[, c(1,3,2,4)]
511
>  dimnames(m) <- list(paste(nn), c("q1","lH", "q3","uH"))
61169 ripley 512
>  stopifnot(m[n4 == 1, 1:2] == (nn[n4 == 1] + 3)/4,   # quart. = hinge
61157 ripley 513
+            m[n4 == 1, 3:4] == (3*nn[n4 == 1] + 1)/4,
56186 murdoch 514
+            m[,"lH"] == ( (nn+3) %/% 2) / 2,
515
+            m[,"uH"] == ((3*nn+2)%/% 2) / 2)
516
>  cm <- noquote(format(m))
517
>  cm[m[,2] == m[,1], 2] <- " = "
518
>  cm[m[,4] == m[,3], 4] <- " = "
519
>  cm
520
   q1    lH    q3    uH   
521
1   1.00  =     1.00  =   
522
2   1.25  1.00  1.75  2.00
523
3   1.50  =     2.50  =   
524
4   1.75  1.50  3.25  3.50
525
5   2.00  =     4.00  =   
526
6   2.25  2.00  4.75  5.00
527
7   2.50  =     5.50  =   
528
8   2.75  2.50  6.25  6.50
529
9   3.00  =     7.00  =   
530
10  3.25  3.00  7.75  8.00
531
11  3.50  =     8.50  =   
532
12  3.75  3.50  9.25  9.50
533
13  4.00  =    10.00  =   
534
14  4.25  4.00 10.75 11.00
535
15  4.50  =    11.50  =   
536
16  4.75  4.50 12.25 12.50
537
17  5.00  =    13.00  =   
66943 maechler 538
> ## End(Don't show)
56186 murdoch 539
> 
540
> 
541
> 
542
> 
543
> cleanEx()
544
> nameEx("check.options")
545
> ### * check.options
546
> 
547
> flush(stderr()); flush(stdout())
548
> 
549
> ### Name: check.options
550
> ### Title: Set Options with Consistency Checks
551
> ### Aliases: check.options
552
> ### Keywords: utilities programming
553
> 
554
> ### ** Examples
555
> 
61157 ripley 556
> (L1 <- list(a = 1:3, b = pi, ch = "CH"))
56186 murdoch 557
$a
558
[1] 1 2 3
559
 
560
$b
561
[1] 3.141593
562
 
563
$ch
564
[1] "CH"
565
 
61157 ripley 566
> check.options(list(a = 0:2), name.opt = "L1")
56186 murdoch 567
$a
568
[1] 0 1 2
569
 
570
$b
571
[1] 3.141593
572
 
573
$ch
574
[1] "CH"
575
 
576
> check.options(NULL, reset = TRUE, name.opt = "L1")
577
$a
578
[1] 1 2 3
579
 
580
$b
581
[1] 3.141593
582
 
583
$ch
584
[1] "CH"
585
 
586
> 
587
> 
588
> 
589
> cleanEx()
590
> nameEx("chull")
591
> ### * chull
592
> 
593
> flush(stderr()); flush(stdout())
594
> 
595
> ### Name: chull
596
> ### Title: Compute Convex Hull of a Set of Points
597
> ### Aliases: chull
598
> ### Keywords: graphs
599
> 
600
> ### ** Examples
601
> 
62213 ripley 602
> X <- matrix(stats::rnorm(2000), ncol = 2)
56186 murdoch 603
> chull(X)
604
 [1]  61 442 165 899 697 446 975 656 232 557 938 295 495
605
> ## Not run: 
606
> ##D   # Example usage from graphics package
607
> ##D   plot(X, cex = 0.5)
608
> ##D   hpts <- chull(X)
609
> ##D   hpts <- c(hpts, hpts[1])
610
> ##D   lines(X[hpts, ])
611
> ## End(Not run)
612
> 
613
> 
614
> 
615
> cleanEx()
616
> nameEx("cm")
617
> ### * cm
618
> 
619
> flush(stderr()); flush(stdout())
620
> 
621
> ### Name: cm
622
> ### Title: Unit Transformation
623
> ### Aliases: cm
624
> ### Keywords: dplot
625
> 
626
> ### ** Examples
627
> 
61169 ripley 628
> cm(1)  # = 2.54
56186 murdoch 629
[1] 2.54
630
> 
631
> ## Translate *from* cm *to* inches:
632
> 
633
> 10 / cm(1) # -> 10cm  are 3.937 inches
634
[1] 3.937008
635
> 
636
> 
637
> 
638
> cleanEx()
639
> nameEx("col2rgb")
640
> ### * col2rgb
641
> 
642
> flush(stderr()); flush(stdout())
643
> 
644
> ### Name: col2rgb
645
> ### Title: Color to RGB Conversion
646
> ### Aliases: col2rgb
647
> ### Keywords: color dplot
648
> 
649
> ### ** Examples
650
> 
651
> col2rgb("peachpuff")
652
      [,1]
653
red    255
654
green  218
655
blue   185
61255 ripley 656
> col2rgb(c(blu = "royalblue", reddish = "tomato"))  # note: colnames
56186 murdoch 657
      blu reddish
658
red    65     255
659
green 105      99
660
blue  225      71
661
> 
61255 ripley 662
> col2rgb(1:8)  # the ones from the palette() (if the default)
56186 murdoch 663
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
77438 murrell 664
red      0  223   97   34   40  208  238  101
665
green    0   83  208  151  226   58  194  101
666
blue     0  107   79  230  229  245   31  101
56186 murdoch 667
> 
61157 ripley 668
> col2rgb(paste0("gold", 1:4))
56186 murdoch 669
      [,1] [,2] [,3] [,4]
670
red    255  238  205  139
671
green  215  201  173  117
672
blue     0    0    0    0
673
> 
674
> col2rgb("#08a0ff")
675
      [,1]
676
red      8
677
green  160
678
blue   255
61300 ripley 679
> ## all three kinds of color specifications:
680
> col2rgb(c(red = "red", hex = "#abcdef"))
681
      red hex
682
red   255 171
683
green   0 205
684
blue    0 239
685
> col2rgb(c(palette = 1:3))
686
      palette1 palette2 palette3
77336 murrell 687
red          0      223       97
688
green        0       83      208
689
blue         0      107       79
56186 murdoch 690
> 
691
> ##-- NON-INTRODUCTORY examples --
692
> 
61157 ripley 693
> grC <- col2rgb(paste0("gray", 0:100))
61169 ripley 694
> table(print(diff(grC["red",])))  # '2' or '3': almost equidistant
56186 murdoch 695
  [1] 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2
696
 [38] 3 2 3 3 2 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 3 2 3 2 3
697
 [75] 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3
698
 
699
 2  3 
700
45 55 
701
> ## The 'named' grays are in between {"slate gray" is not gray, strictly}
61157 ripley 702
> col2rgb(c(g66 = "gray66", darkg =  "dark gray", g67 = "gray67",
703
+           g74 = "gray74", gray  =       "gray", g75 = "gray75",
704
+           g82 = "gray82", light = "light gray", g83 = "gray83"))
56186 murdoch 705
      g66 darkg g67 g74 gray g75 g82 light g83
706
red   168   169 171 189  190 191 209   211 212
707
green 168   169 171 189  190 191 209   211 212
708
blue  168   169 171 189  190 191 209   211 212
709
> 
710
> crgb <- col2rgb(cc <- colors())
711
> colnames(crgb) <- cc
61169 ripley 712
> t(crgb)  # The whole table
56186 murdoch 713
                     red green blue
714
white                255   255  255
715
aliceblue            240   248  255
716
antiquewhite         250   235  215
717
antiquewhite1        255   239  219
718
antiquewhite2        238   223  204
719
antiquewhite3        205   192  176
720
antiquewhite4        139   131  120
721
aquamarine           127   255  212
722
aquamarine1          127   255  212
723
aquamarine2          118   238  198
724
aquamarine3          102   205  170
725
aquamarine4           69   139  116
726
azure                240   255  255
727
azure1               240   255  255
728
azure2               224   238  238
729
azure3               193   205  205
730
azure4               131   139  139
731
beige                245   245  220
732
bisque               255   228  196
733
bisque1              255   228  196
734
bisque2              238   213  183
735
bisque3              205   183  158
736
bisque4              139   125  107
737
black                  0     0    0
738
blanchedalmond       255   235  205
739
blue                   0     0  255
740
blue1                  0     0  255
741
blue2                  0     0  238
742
blue3                  0     0  205
743
blue4                  0     0  139
744
blueviolet           138    43  226
745
brown                165    42   42
746
brown1               255    64   64
747
brown2               238    59   59
748
brown3               205    51   51
749
brown4               139    35   35
750
burlywood            222   184  135
751
burlywood1           255   211  155
752
burlywood2           238   197  145
753
burlywood3           205   170  125
754
burlywood4           139   115   85
755
cadetblue             95   158  160
756
cadetblue1           152   245  255
757
cadetblue2           142   229  238
758
cadetblue3           122   197  205
759
cadetblue4            83   134  139
760
chartreuse           127   255    0
761
chartreuse1          127   255    0
762
chartreuse2          118   238    0
763
chartreuse3          102   205    0
764
chartreuse4           69   139    0
765
chocolate            210   105   30
766
chocolate1           255   127   36
767
chocolate2           238   118   33
768
chocolate3           205   102   29
769
chocolate4           139    69   19
770
coral                255   127   80
771
coral1               255   114   86
772
coral2               238   106   80
773
coral3               205    91   69
774
coral4               139    62   47
775
cornflowerblue       100   149  237
776
cornsilk             255   248  220
777
cornsilk1            255   248  220
778
cornsilk2            238   232  205
779
cornsilk3            205   200  177
780
cornsilk4            139   136  120
781
cyan                   0   255  255
782
cyan1                  0   255  255
783
cyan2                  0   238  238
784
cyan3                  0   205  205
785
cyan4                  0   139  139
786
darkblue               0     0  139
787
darkcyan               0   139  139
788
darkgoldenrod        184   134   11
789
darkgoldenrod1       255   185   15
790
darkgoldenrod2       238   173   14
791
darkgoldenrod3       205   149   12
792
darkgoldenrod4       139   101    8
793
darkgray             169   169  169
794
darkgreen              0   100    0
795
darkgrey             169   169  169
796
darkkhaki            189   183  107
797
darkmagenta          139     0  139
798
darkolivegreen        85   107   47
799
darkolivegreen1      202   255  112
800
darkolivegreen2      188   238  104
801
darkolivegreen3      162   205   90
802
darkolivegreen4      110   139   61
803
darkorange           255   140    0
804
darkorange1          255   127    0
805
darkorange2          238   118    0
806
darkorange3          205   102    0
807
darkorange4          139    69    0
808
darkorchid           153    50  204
809
darkorchid1          191    62  255
810
darkorchid2          178    58  238
811
darkorchid3          154    50  205
812
darkorchid4          104    34  139
813
darkred              139     0    0
814
darksalmon           233   150  122
815
darkseagreen         143   188  143
816
darkseagreen1        193   255  193
817
darkseagreen2        180   238  180
818
darkseagreen3        155   205  155
819
darkseagreen4        105   139  105
820
darkslateblue         72    61  139
821
darkslategray         47    79   79
822
darkslategray1       151   255  255
823
darkslategray2       141   238  238
824
darkslategray3       121   205  205
825
darkslategray4        82   139  139
826
darkslategrey         47    79   79
827
darkturquoise          0   206  209
828
darkviolet           148     0  211
829
deeppink             255    20  147
830
deeppink1            255    20  147
831
deeppink2            238    18  137
832
deeppink3            205    16  118
833
deeppink4            139    10   80
834
deepskyblue            0   191  255
835
deepskyblue1           0   191  255
836
deepskyblue2           0   178  238
837
deepskyblue3           0   154  205
838
deepskyblue4           0   104  139
839
dimgray              105   105  105
840
dimgrey              105   105  105
841
dodgerblue            30   144  255
842
dodgerblue1           30   144  255
843
dodgerblue2           28   134  238
844
dodgerblue3           24   116  205
845
dodgerblue4           16    78  139
846
firebrick            178    34   34
847
firebrick1           255    48   48
848
firebrick2           238    44   44
849
firebrick3           205    38   38
850
firebrick4           139    26   26
851
floralwhite          255   250  240
852
forestgreen           34   139   34
853
gainsboro            220   220  220
854
ghostwhite           248   248  255
855
gold                 255   215    0
856
gold1                255   215    0
857
gold2                238   201    0
858
gold3                205   173    0
859
gold4                139   117    0
860
goldenrod            218   165   32
861
goldenrod1           255   193   37
862
goldenrod2           238   180   34
863
goldenrod3           205   155   29
864
goldenrod4           139   105   20
865
gray                 190   190  190
866
gray0                  0     0    0
867
gray1                  3     3    3
868
gray2                  5     5    5
869
gray3                  8     8    8
870
gray4                 10    10   10
871
gray5                 13    13   13
872
gray6                 15    15   15
873
gray7                 18    18   18
874
gray8                 20    20   20
875
gray9                 23    23   23
876
gray10                26    26   26
877
gray11                28    28   28
878
gray12                31    31   31
879
gray13                33    33   33
880
gray14                36    36   36
881
gray15                38    38   38
882
gray16                41    41   41
883
gray17                43    43   43
884
gray18                46    46   46
885
gray19                48    48   48
886
gray20                51    51   51
887
gray21                54    54   54
888
gray22                56    56   56
889
gray23                59    59   59
890
gray24                61    61   61
891
gray25                64    64   64
892
gray26                66    66   66
893
gray27                69    69   69
894
gray28                71    71   71
895
gray29                74    74   74
896
gray30                77    77   77
897
gray31                79    79   79
898
gray32                82    82   82
899
gray33                84    84   84
900
gray34                87    87   87
901
gray35                89    89   89
902
gray36                92    92   92
903
gray37                94    94   94
904
gray38                97    97   97
905
gray39                99    99   99
906
gray40               102   102  102
907
gray41               105   105  105
908
gray42               107   107  107
909
gray43               110   110  110
910
gray44               112   112  112
911
gray45               115   115  115
912
gray46               117   117  117
913
gray47               120   120  120
914
gray48               122   122  122
915
gray49               125   125  125
916
gray50               127   127  127
917
gray51               130   130  130
918
gray52               133   133  133
919
gray53               135   135  135
920
gray54               138   138  138
921
gray55               140   140  140
922
gray56               143   143  143
923
gray57               145   145  145
924
gray58               148   148  148
925
gray59               150   150  150
926
gray60               153   153  153
927
gray61               156   156  156
928
gray62               158   158  158
929
gray63               161   161  161
930
gray64               163   163  163
931
gray65               166   166  166
932
gray66               168   168  168
933
gray67               171   171  171
934
gray68               173   173  173
935
gray69               176   176  176
936
gray70               179   179  179
937
gray71               181   181  181
938
gray72               184   184  184
939
gray73               186   186  186
940
gray74               189   189  189
941
gray75               191   191  191
942
gray76               194   194  194
943
gray77               196   196  196
944
gray78               199   199  199
945
gray79               201   201  201
946
gray80               204   204  204
947
gray81               207   207  207
948
gray82               209   209  209
949
gray83               212   212  212
950
gray84               214   214  214
951
gray85               217   217  217
952
gray86               219   219  219
953
gray87               222   222  222
954
gray88               224   224  224
955
gray89               227   227  227
956
gray90               229   229  229
957
gray91               232   232  232
958
gray92               235   235  235
959
gray93               237   237  237
960
gray94               240   240  240
961
gray95               242   242  242
962
gray96               245   245  245
963
gray97               247   247  247
964
gray98               250   250  250
965
gray99               252   252  252
966
gray100              255   255  255
967
green                  0   255    0
968
green1                 0   255    0
969
green2                 0   238    0
970
green3                 0   205    0
971
green4                 0   139    0
972
greenyellow          173   255   47
973
grey                 190   190  190
974
grey0                  0     0    0
975
grey1                  3     3    3
976
grey2                  5     5    5
977
grey3                  8     8    8
978
grey4                 10    10   10
979
grey5                 13    13   13
980
grey6                 15    15   15
981
grey7                 18    18   18
982
grey8                 20    20   20
983
grey9                 23    23   23
984
grey10                26    26   26
985
grey11                28    28   28
986
grey12                31    31   31
987
grey13                33    33   33
988
grey14                36    36   36
989
grey15                38    38   38
990
grey16                41    41   41
991
grey17                43    43   43
992
grey18                46    46   46
993
grey19                48    48   48
994
grey20                51    51   51
995
grey21                54    54   54
996
grey22                56    56   56
997
grey23                59    59   59
998
grey24                61    61   61
999
grey25                64    64   64
1000
grey26                66    66   66
1001
grey27                69    69   69
1002
grey28                71    71   71
1003
grey29                74    74   74
1004
grey30                77    77   77
1005
grey31                79    79   79
1006
grey32                82    82   82
1007
grey33                84    84   84
1008
grey34                87    87   87
1009
grey35                89    89   89
1010
grey36                92    92   92
1011
grey37                94    94   94
1012
grey38                97    97   97
1013
grey39                99    99   99
1014
grey40               102   102  102
1015
grey41               105   105  105
1016
grey42               107   107  107
1017
grey43               110   110  110
1018
grey44               112   112  112
1019
grey45               115   115  115
1020
grey46               117   117  117
1021
grey47               120   120  120
1022
grey48               122   122  122
1023
grey49               125   125  125
1024
grey50               127   127  127
1025
grey51               130   130  130
1026
grey52               133   133  133
1027
grey53               135   135  135
1028
grey54               138   138  138
1029
grey55               140   140  140
1030
grey56               143   143  143
1031
grey57               145   145  145
1032
grey58               148   148  148
1033
grey59               150   150  150
1034
grey60               153   153  153
1035
grey61               156   156  156
1036
grey62               158   158  158
1037
grey63               161   161  161
1038
grey64               163   163  163
1039
grey65               166   166  166
1040
grey66               168   168  168
1041
grey67               171   171  171
1042
grey68               173   173  173
1043
grey69               176   176  176
1044
grey70               179   179  179
1045
grey71               181   181  181
1046
grey72               184   184  184
1047
grey73               186   186  186
1048
grey74               189   189  189
1049
grey75               191   191  191
1050
grey76               194   194  194
1051
grey77               196   196  196
1052
grey78               199   199  199
1053
grey79               201   201  201
1054
grey80               204   204  204
1055
grey81               207   207  207
1056
grey82               209   209  209
1057
grey83               212   212  212
1058
grey84               214   214  214
1059
grey85               217   217  217
1060
grey86               219   219  219
1061
grey87               222   222  222
1062
grey88               224   224  224
1063
grey89               227   227  227
1064
grey90               229   229  229
1065
grey91               232   232  232
1066
grey92               235   235  235
1067
grey93               237   237  237
1068
grey94               240   240  240
1069
grey95               242   242  242
1070
grey96               245   245  245
1071
grey97               247   247  247
1072
grey98               250   250  250
1073
grey99               252   252  252
1074
grey100              255   255  255
1075
honeydew             240   255  240
1076
honeydew1            240   255  240
1077
honeydew2            224   238  224
1078
honeydew3            193   205  193
1079
honeydew4            131   139  131
1080
hotpink              255   105  180
1081
hotpink1             255   110  180
1082
hotpink2             238   106  167
1083
hotpink3             205    96  144
1084
hotpink4             139    58   98
1085
indianred            205    92   92
1086
indianred1           255   106  106
1087
indianred2           238    99   99
1088
indianred3           205    85   85
1089
indianred4           139    58   58
1090
ivory                255   255  240
1091
ivory1               255   255  240
1092
ivory2               238   238  224
1093
ivory3               205   205  193
1094
ivory4               139   139  131
1095
khaki                240   230  140
1096
khaki1               255   246  143
1097
khaki2               238   230  133
1098
khaki3               205   198  115
1099
khaki4               139   134   78
1100
lavender             230   230  250
1101
lavenderblush        255   240  245
1102
lavenderblush1       255   240  245
1103
lavenderblush2       238   224  229
1104
lavenderblush3       205   193  197
1105
lavenderblush4       139   131  134
1106
lawngreen            124   252    0
1107
lemonchiffon         255   250  205
1108
lemonchiffon1        255   250  205
1109
lemonchiffon2        238   233  191
1110
lemonchiffon3        205   201  165
1111
lemonchiffon4        139   137  112
1112
lightblue            173   216  230
1113
lightblue1           191   239  255
1114
lightblue2           178   223  238
1115
lightblue3           154   192  205
1116
lightblue4           104   131  139
1117
lightcoral           240   128  128
1118
lightcyan            224   255  255
1119
lightcyan1           224   255  255
1120
lightcyan2           209   238  238
1121
lightcyan3           180   205  205
1122
lightcyan4           122   139  139
1123
lightgoldenrod       238   221  130
1124
lightgoldenrod1      255   236  139
1125
lightgoldenrod2      238   220  130
1126
lightgoldenrod3      205   190  112
1127
lightgoldenrod4      139   129   76
1128
lightgoldenrodyellow 250   250  210
1129
lightgray            211   211  211
1130
lightgreen           144   238  144
1131
lightgrey            211   211  211
1132
lightpink            255   182  193
1133
lightpink1           255   174  185
1134
lightpink2           238   162  173
1135
lightpink3           205   140  149
1136
lightpink4           139    95  101
1137
lightsalmon          255   160  122
1138
lightsalmon1         255   160  122
1139
lightsalmon2         238   149  114
1140
lightsalmon3         205   129   98
1141
lightsalmon4         139    87   66
1142
lightseagreen         32   178  170
1143
lightskyblue         135   206  250
1144
lightskyblue1        176   226  255
1145
lightskyblue2        164   211  238
1146
lightskyblue3        141   182  205
1147
lightskyblue4         96   123  139
1148
lightslateblue       132   112  255
1149
lightslategray       119   136  153
1150
lightslategrey       119   136  153
1151
lightsteelblue       176   196  222
1152
lightsteelblue1      202   225  255
1153
lightsteelblue2      188   210  238
1154
lightsteelblue3      162   181  205
1155
lightsteelblue4      110   123  139
1156
lightyellow          255   255  224
1157
lightyellow1         255   255  224
1158
lightyellow2         238   238  209
1159
lightyellow3         205   205  180
1160
lightyellow4         139   139  122
1161
limegreen             50   205   50
1162
linen                250   240  230
1163
magenta              255     0  255
1164
magenta1             255     0  255
1165
magenta2             238     0  238
1166
magenta3             205     0  205
1167
magenta4             139     0  139
1168
maroon               176    48   96
1169
maroon1              255    52  179
1170
maroon2              238    48  167
1171
maroon3              205    41  144
1172
maroon4              139    28   98
1173
mediumaquamarine     102   205  170
1174
mediumblue             0     0  205
1175
mediumorchid         186    85  211
1176
mediumorchid1        224   102  255
1177
mediumorchid2        209    95  238
1178
mediumorchid3        180    82  205
1179
mediumorchid4        122    55  139
1180
mediumpurple         147   112  219
1181
mediumpurple1        171   130  255
1182
mediumpurple2        159   121  238
1183
mediumpurple3        137   104  205
1184
mediumpurple4         93    71  139
1185
mediumseagreen        60   179  113
1186
mediumslateblue      123   104  238
1187
mediumspringgreen      0   250  154
1188
mediumturquoise       72   209  204
1189
mediumvioletred      199    21  133
1190
midnightblue          25    25  112
1191
mintcream            245   255  250
1192
mistyrose            255   228  225
1193
mistyrose1           255   228  225
1194
mistyrose2           238   213  210
1195
mistyrose3           205   183  181
1196
mistyrose4           139   125  123
1197
moccasin             255   228  181
1198
navajowhite          255   222  173
1199
navajowhite1         255   222  173
1200
navajowhite2         238   207  161
1201
navajowhite3         205   179  139
1202
navajowhite4         139   121   94
1203
navy                   0     0  128
1204
navyblue               0     0  128
1205
oldlace              253   245  230
1206
olivedrab            107   142   35
1207
olivedrab1           192   255   62
1208
olivedrab2           179   238   58
1209
olivedrab3           154   205   50
1210
olivedrab4           105   139   34
1211
orange               255   165    0
1212
orange1              255   165    0
1213
orange2              238   154    0
1214
orange3              205   133    0
1215
orange4              139    90    0
1216
orangered            255    69    0
1217
orangered1           255    69    0
1218
orangered2           238    64    0
1219
orangered3           205    55    0
1220
orangered4           139    37    0
1221
orchid               218   112  214
1222
orchid1              255   131  250
1223
orchid2              238   122  233
1224
orchid3              205   105  201
1225
orchid4              139    71  137
1226
palegoldenrod        238   232  170
1227
palegreen            152   251  152
1228
palegreen1           154   255  154
1229
palegreen2           144   238  144
1230
palegreen3           124   205  124
1231
palegreen4            84   139   84
1232
paleturquoise        175   238  238
1233
paleturquoise1       187   255  255
1234
paleturquoise2       174   238  238
1235
paleturquoise3       150   205  205
1236
paleturquoise4       102   139  139
1237
palevioletred        219   112  147
1238
palevioletred1       255   130  171
1239
palevioletred2       238   121  159
1240
palevioletred3       205   104  137
1241
palevioletred4       139    71   93
1242
papayawhip           255   239  213
1243
peachpuff            255   218  185
1244
peachpuff1           255   218  185
1245
peachpuff2           238   203  173
1246
peachpuff3           205   175  149
1247
peachpuff4           139   119  101
1248
peru                 205   133   63
1249
pink                 255   192  203
1250
pink1                255   181  197
1251
pink2                238   169  184
1252
pink3                205   145  158
1253
pink4                139    99  108
1254
plum                 221   160  221
1255
plum1                255   187  255
1256
plum2                238   174  238
1257
plum3                205   150  205
1258
plum4                139   102  139
1259
powderblue           176   224  230
1260
purple               160    32  240
1261
purple1              155    48  255
1262
purple2              145    44  238
1263
purple3              125    38  205
1264
purple4               85    26  139
1265
red                  255     0    0
1266
red1                 255     0    0
1267
red2                 238     0    0
1268
red3                 205     0    0
1269
red4                 139     0    0
1270
rosybrown            188   143  143
1271
rosybrown1           255   193  193
1272
rosybrown2           238   180  180
1273
rosybrown3           205   155  155
1274
rosybrown4           139   105  105
1275
royalblue             65   105  225
1276
royalblue1            72   118  255
1277
royalblue2            67   110  238
1278
royalblue3            58    95  205
1279
royalblue4            39    64  139
1280
saddlebrown          139    69   19
1281
salmon               250   128  114
1282
salmon1              255   140  105
1283
salmon2              238   130   98
1284
salmon3              205   112   84
1285
salmon4              139    76   57
1286
sandybrown           244   164   96
1287
seagreen              46   139   87
1288
seagreen1             84   255  159
1289
seagreen2             78   238  148
1290
seagreen3             67   205  128
1291
seagreen4             46   139   87
1292
seashell             255   245  238
1293
seashell1            255   245  238
1294
seashell2            238   229  222
1295
seashell3            205   197  191
1296
seashell4            139   134  130
1297
sienna               160    82   45
1298
sienna1              255   130   71
1299
sienna2              238   121   66
1300
sienna3              205   104   57
1301
sienna4              139    71   38
1302
skyblue              135   206  235
1303
skyblue1             135   206  255
1304
skyblue2             126   192  238
1305
skyblue3             108   166  205
1306
skyblue4              74   112  139
1307
slateblue            106    90  205
1308
slateblue1           131   111  255
1309
slateblue2           122   103  238
1310
slateblue3           105    89  205
1311
slateblue4            71    60  139
1312
slategray            112   128  144
1313
slategray1           198   226  255
1314
slategray2           185   211  238
1315
slategray3           159   182  205
1316
slategray4           108   123  139
1317
slategrey            112   128  144
1318
snow                 255   250  250
1319
snow1                255   250  250
1320
snow2                238   233  233
1321
snow3                205   201  201
1322
snow4                139   137  137
1323
springgreen            0   255  127
1324
springgreen1           0   255  127
1325
springgreen2           0   238  118
1326
springgreen3           0   205  102
1327
springgreen4           0   139   69
1328
steelblue             70   130  180
1329
steelblue1            99   184  255
1330
steelblue2            92   172  238
1331
steelblue3            79   148  205
1332
steelblue4            54   100  139
1333
tan                  210   180  140
1334
tan1                 255   165   79
1335
tan2                 238   154   73
1336
tan3                 205   133   63
1337
tan4                 139    90   43
1338
thistle              216   191  216
1339
thistle1             255   225  255
1340
thistle2             238   210  238
1341
thistle3             205   181  205
1342
thistle4             139   123  139
1343
tomato               255    99   71
1344
tomato1              255    99   71
1345
tomato2              238    92   66
1346
tomato3              205    79   57
1347
tomato4              139    54   38
1348
turquoise             64   224  208
1349
turquoise1             0   245  255
1350
turquoise2             0   229  238
1351
turquoise3             0   197  205
1352
turquoise4             0   134  139
1353
violet               238   130  238
1354
violetred            208    32  144
1355
violetred1           255    62  150
1356
violetred2           238    58  140
1357
violetred3           205    50  120
1358
violetred4           139    34   82
1359
wheat                245   222  179
1360
wheat1               255   231  186
1361
wheat2               238   216  174
1362
wheat3               205   186  150
1363
wheat4               139   126  102
1364
whitesmoke           245   245  245
1365
yellow               255   255    0
1366
yellow1              255   255    0
1367
yellow2              238   238    0
1368
yellow3              205   205    0
1369
yellow4              139   139    0
1370
yellowgreen          154   205   50
1371
> 
61169 ripley 1372
> ccodes <- c(256^(2:0) %*% crgb)  # = internal codes
56186 murdoch 1373
> ## How many names are 'aliases' of each other:
1374
> table(tcc <- table(ccodes))
1375
 
1376
  1   2   3   4 
1377
352 146   3   1 
1378
> length(uc <- unique(sort(ccodes))) # 502
1379
[1] 502
1380
> ## All the multiply named colors:
1381
> mult <- uc[tcc >= 2]
1382
> cl <- lapply(mult, function(m) cc[ccodes == m])
1383
> names(cl) <- apply(col2rgb(sapply(cl, function(x)x[1])),
61157 ripley 1384
+                    2, function(n)paste(n, collapse = ","))
56186 murdoch 1385
> utils::str(cl)
1386
List of 150
1387
 $ 0,0,0      : chr [1:3] "black" "gray0" "grey0"
1388
 $ 0,0,128    : chr [1:2] "navy" "navyblue"
1389
 $ 0,0,139    : chr [1:2] "blue4" "darkblue"
1390
 $ 0,0,205    : chr [1:2] "blue3" "mediumblue"
1391
 $ 0,0,255    : chr [1:2] "blue" "blue1"
1392
 $ 0,139,139  : chr [1:2] "cyan4" "darkcyan"
1393
 $ 0,191,255  : chr [1:2] "deepskyblue" "deepskyblue1"
1394
 $ 0,255,0    : chr [1:2] "green" "green1"
1395
 $ 0,255,127  : chr [1:2] "springgreen" "springgreen1"
1396
 $ 0,255,255  : chr [1:2] "cyan" "cyan1"
1397
 $ 3,3,3      : chr [1:2] "gray1" "grey1"
1398
 $ 5,5,5      : chr [1:2] "gray2" "grey2"
1399
 $ 8,8,8      : chr [1:2] "gray3" "grey3"
1400
 $ 10,10,10   : chr [1:2] "gray4" "grey4"
1401
 $ 13,13,13   : chr [1:2] "gray5" "grey5"
1402
 $ 15,15,15   : chr [1:2] "gray6" "grey6"
1403
 $ 18,18,18   : chr [1:2] "gray7" "grey7"
1404
 $ 20,20,20   : chr [1:2] "gray8" "grey8"
1405
 $ 23,23,23   : chr [1:2] "gray9" "grey9"
1406
 $ 26,26,26   : chr [1:2] "gray10" "grey10"
1407
 $ 28,28,28   : chr [1:2] "gray11" "grey11"
1408
 $ 30,144,255 : chr [1:2] "dodgerblue" "dodgerblue1"
1409
 $ 31,31,31   : chr [1:2] "gray12" "grey12"
1410
 $ 33,33,33   : chr [1:2] "gray13" "grey13"
1411
 $ 36,36,36   : chr [1:2] "gray14" "grey14"
1412
 $ 38,38,38   : chr [1:2] "gray15" "grey15"
1413
 $ 41,41,41   : chr [1:2] "gray16" "grey16"
1414
 $ 43,43,43   : chr [1:2] "gray17" "grey17"
1415
 $ 46,46,46   : chr [1:2] "gray18" "grey18"
1416
 $ 46,139,87  : chr [1:2] "seagreen" "seagreen4"
1417
 $ 47,79,79   : chr [1:2] "darkslategray" "darkslategrey"
1418
 $ 48,48,48   : chr [1:2] "gray19" "grey19"
1419
 $ 51,51,51   : chr [1:2] "gray20" "grey20"
1420
 $ 54,54,54   : chr [1:2] "gray21" "grey21"
1421
 $ 56,56,56   : chr [1:2] "gray22" "grey22"
1422
 $ 59,59,59   : chr [1:2] "gray23" "grey23"
1423
 $ 61,61,61   : chr [1:2] "gray24" "grey24"
1424
 $ 64,64,64   : chr [1:2] "gray25" "grey25"
1425
 $ 66,66,66   : chr [1:2] "gray26" "grey26"
1426
 $ 69,69,69   : chr [1:2] "gray27" "grey27"
1427
 $ 71,71,71   : chr [1:2] "gray28" "grey28"
1428
 $ 74,74,74   : chr [1:2] "gray29" "grey29"
1429
 $ 77,77,77   : chr [1:2] "gray30" "grey30"
1430
 $ 79,79,79   : chr [1:2] "gray31" "grey31"
1431
 $ 82,82,82   : chr [1:2] "gray32" "grey32"
1432
 $ 84,84,84   : chr [1:2] "gray33" "grey33"
1433
 $ 87,87,87   : chr [1:2] "gray34" "grey34"
1434
 $ 89,89,89   : chr [1:2] "gray35" "grey35"
1435
 $ 92,92,92   : chr [1:2] "gray36" "grey36"
1436
 $ 94,94,94   : chr [1:2] "gray37" "grey37"
1437
 $ 97,97,97   : chr [1:2] "gray38" "grey38"
1438
 $ 99,99,99   : chr [1:2] "gray39" "grey39"
1439
 $ 102,102,102: chr [1:2] "gray40" "grey40"
1440
 $ 102,205,170: chr [1:2] "aquamarine3" "mediumaquamarine"
1441
 $ 105,105,105: chr [1:4] "dimgray" "dimgrey" "gray41" "grey41"
1442
 $ 107,107,107: chr [1:2] "gray42" "grey42"
1443
 $ 110,110,110: chr [1:2] "gray43" "grey43"
1444
 $ 112,112,112: chr [1:2] "gray44" "grey44"
1445
 $ 112,128,144: chr [1:2] "slategray" "slategrey"
1446
 $ 115,115,115: chr [1:2] "gray45" "grey45"
1447
 $ 117,117,117: chr [1:2] "gray46" "grey46"
1448
 $ 119,136,153: chr [1:2] "lightslategray" "lightslategrey"
1449
 $ 120,120,120: chr [1:2] "gray47" "grey47"
1450
 $ 122,122,122: chr [1:2] "gray48" "grey48"
1451
 $ 125,125,125: chr [1:2] "gray49" "grey49"
1452
 $ 127,127,127: chr [1:2] "gray50" "grey50"
1453
 $ 127,255,0  : chr [1:2] "chartreuse" "chartreuse1"
1454
 $ 127,255,212: chr [1:2] "aquamarine" "aquamarine1"
1455
 $ 130,130,130: chr [1:2] "gray51" "grey51"
1456
 $ 133,133,133: chr [1:2] "gray52" "grey52"
1457
 $ 135,135,135: chr [1:2] "gray53" "grey53"
1458
 $ 138,138,138: chr [1:2] "gray54" "grey54"
1459
 $ 139,0,0    : chr [1:2] "darkred" "red4"
1460
 $ 139,0,139  : chr [1:2] "darkmagenta" "magenta4"
1461
 $ 139,69,19  : chr [1:2] "chocolate4" "saddlebrown"
1462
 $ 140,140,140: chr [1:2] "gray55" "grey55"
1463
 $ 143,143,143: chr [1:2] "gray56" "grey56"
1464
 $ 144,238,144: chr [1:2] "lightgreen" "palegreen2"
1465
 $ 145,145,145: chr [1:2] "gray57" "grey57"
1466
 $ 148,148,148: chr [1:2] "gray58" "grey58"
1467
 $ 150,150,150: chr [1:2] "gray59" "grey59"
1468
 $ 153,153,153: chr [1:2] "gray60" "grey60"
1469
 $ 154,205,50 : chr [1:2] "olivedrab3" "yellowgreen"
1470
 $ 156,156,156: chr [1:2] "gray61" "grey61"
1471
 $ 158,158,158: chr [1:2] "gray62" "grey62"
1472
 $ 161,161,161: chr [1:2] "gray63" "grey63"
1473
 $ 163,163,163: chr [1:2] "gray64" "grey64"
1474
 $ 166,166,166: chr [1:2] "gray65" "grey65"
1475
 $ 168,168,168: chr [1:2] "gray66" "grey66"
1476
 $ 169,169,169: chr [1:2] "darkgray" "darkgrey"
1477
 $ 171,171,171: chr [1:2] "gray67" "grey67"
1478
 $ 173,173,173: chr [1:2] "gray68" "grey68"
1479
 $ 176,176,176: chr [1:2] "gray69" "grey69"
1480
 $ 179,179,179: chr [1:2] "gray70" "grey70"
1481
 $ 181,181,181: chr [1:2] "gray71" "grey71"
1482
 $ 184,184,184: chr [1:2] "gray72" "grey72"
1483
 $ 186,186,186: chr [1:2] "gray73" "grey73"
1484
 $ 189,189,189: chr [1:2] "gray74" "grey74"
1485
 $ 190,190,190: chr [1:2] "gray" "grey"
1486
  [list output truncated]
1487
> ## Not run: 
1488
> ##D  if(require(xgobi)) { ## Look at the color cube dynamically :
1489
> ##D    tc <- t(crgb[, !duplicated(ccodes)])
61169 ripley 1490
> ##D    table(is.gray <- tc[,1] == tc[,2] & tc[,2] == tc[,3])  # (397, 105)
56186 murdoch 1491
> ##D    xgobi(tc, color = c("gold", "gray")[1 + is.gray])
1492
> ##D  }
1493
> ## End(Not run)
1494
> 
1495
> 
1496
> 
1497
> cleanEx()
1498
> nameEx("colorRamp")
1499
> ### * colorRamp
1500
> 
1501
> flush(stderr()); flush(stdout())
1502
> 
1503
> ### Name: colorRamp
1504
> ### Title: Color interpolation
1505
> ### Aliases: colorRamp colorRampPalette
1506
> ### Keywords: color
1507
> 
1508
> ### ** Examples
1509
> 
58989 maechler 1510
> ## Both return a *function* :
61169 ripley 1511
> colorRamp(c("red", "green"))( (0:4)/4 ) ## (x) , x in [0,1]
58989 maechler 1512
       [,1]   [,2] [,3]
1513
[1,] 255.00   0.00    0
1514
[2,] 191.25  63.75    0
1515
[3,] 127.50 127.50    0
1516
[4,]  63.75 191.25    0
1517
[5,]   0.00 255.00    0
61169 ripley 1518
> colorRampPalette(c("blue", "red"))( 4 ) ## (n)
58989 maechler 1519
[1] "#0000FF" "#5500AA" "#AA0055" "#FF0000"
63408 ripley 1520
> ## a ramp in opacity of blue values
64967 ripley 1521
> colorRampPalette(c(rgb(0,0,1,1), rgb(0,0,1,0)), alpha = TRUE)(8)
1522
[1] "#0000FFFF" "#0000FFDA" "#0000FFB6" "#0000FF91" "#0000FF6D" "#0000FF48"
1523
[7] "#0000FF24" "#0000FF00"
63408 ripley 1524
> 
56186 murdoch 1525
> require(graphics)
1526
> 
1527
> ## Here space="rgb" gives palettes that vary only in saturation,
1528
> ## as intended.
1529
> ## With space="Lab" the steps are more uniform, but the hues
1530
> ## are slightly purple.
1531
> filled.contour(volcano,
1532
+                color.palette =
1533
+                    colorRampPalette(c("red", "white", "blue")),
1534
+                asp = 1)
1535
> filled.contour(volcano,
1536
+                color.palette =
1537
+                    colorRampPalette(c("red", "white", "blue"),
1538
+                                     space = "Lab"),
1539
+                asp = 1)
1540
> 
1541
> ## Interpolating a 'sequential' ColorBrewer palette
1542
> YlOrBr <- c("#FFFFD4", "#FED98E", "#FE9929", "#D95F0E", "#993404")
1543
> filled.contour(volcano,
1544
+                color.palette = colorRampPalette(YlOrBr, space = "Lab"),
1545
+                asp = 1)
1546
> filled.contour(volcano,
1547
+                color.palette = colorRampPalette(YlOrBr, space = "Lab",
1548
+                                                 bias = 0.5),
1549
+                asp = 1)
1550
> 
1551
> ## 'jet.colors' is "as in Matlab"
1552
> ## (and hurting the eyes by over-saturation)
1553
> jet.colors <-
1554
+   colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan",
1555
+                      "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
1556
> filled.contour(volcano, color = jet.colors, asp = 1)
1557
> 
1558
> ## space="Lab" helps when colors don't form a natural sequence
1559
> m <- outer(1:20,1:20,function(x,y) sin(sqrt(x*y)/3))
1560
> rgb.palette <- colorRampPalette(c("red", "orange", "blue"),
1561
+                                 space = "rgb")
1562
> Lab.palette <- colorRampPalette(c("red", "orange", "blue"),
1563
+                                 space = "Lab")
1564
> filled.contour(m, col = rgb.palette(20))
1565
> filled.contour(m, col = Lab.palette(20))
1566
> 
1567
> 
1568
> 
1569
> cleanEx()
1570
> nameEx("colors")
1571
> ### * colors
1572
> 
1573
> flush(stderr()); flush(stdout())
1574
> 
1575
> ### Name: colors
1576
> ### Title: Color Names
1577
> ### Aliases: colors colours
1578
> ### Keywords: color dplot sysdata
1579
> 
1580
> ### ** Examples
1581
> 
1582
> cl <- colors()
1583
> length(cl); cl[1:20]
1584
[1] 657
1585
 [1] "white"         "aliceblue"     "antiquewhite"  "antiquewhite1"
1586
 [5] "antiquewhite2" "antiquewhite3" "antiquewhite4" "aquamarine"   
1587
 [9] "aquamarine1"   "aquamarine2"   "aquamarine3"   "aquamarine4"  
1588
[13] "azure"         "azure1"        "azure2"        "azure3"       
1589
[17] "azure4"        "beige"         "bisque"        "bisque1"      
1590
> 
61127 maechler 1591
> length(cl. <- colors(TRUE))
1592
[1] 502
1593
> ## only 502 of the 657 named ones
1594
> 
1595
> ## ----------- Show all named colors and more:
1596
> demo("colors")
1597
 
1598
 
1599
	demo(colors)
1600
	---- ~~~~~~
1601
 
57782 maechler 1602
> ### ----------- Show (almost) all named colors ---------------------
56186 murdoch 1603
> 
57782 maechler 1604
> ## 1) with traditional 'graphics' package:
1605
> showCols1 <- function(bg = "gray", cex = 0.75, srt = 30) {
1606
+     m <- ceiling(sqrt(n <- length(cl <- colors())))
1607
+     length(cl) <- m*m; cm <- matrix(cl, m)
1608
+     ##
1609
+     require("graphics")
1610
+     op <- par(mar=rep(0,4), ann=FALSE, bg = bg); on.exit(par(op))
1611
+     plot(1:m,1:m, type="n", axes=FALSE)
1612
+     text(col(cm), rev(row(cm)), cm,  col = cl, cex=cex, srt=srt)
1613
+ }
61127 maechler 1614
 
57782 maechler 1615
> showCols1()
61127 maechler 1616
 
57782 maechler 1617
> ## 2) with 'grid' package:
1618
> showCols2 <- function(bg = "grey", cex = 0.75, rot = 30) {
1619
+     m <- ceiling(sqrt(n <- length(cl <- colors())))
1620
+     length(cl) <- m*m; cm <- matrix(cl, m)
1621
+     ##
1622
+     require("grid")
1623
+     grid.newpage(); vp <- viewport(w = .92, h = .92)
1624
+     grid.rect(gp=gpar(fill=bg))
1625
+     grid.text(cm, x = col(cm)/m, y = rev(row(cm))/m, rot = rot,
1626
+               vp=vp, gp=gpar(cex = cex, col = cm))
1627
+ }
61127 maechler 1628
 
57782 maechler 1629
> showCols2()
1630
Loading required package: grid
61127 maechler 1631
 
57782 maechler 1632
> showCols2(bg = "gray33")
61127 maechler 1633
 
1634
> ###
57782 maechler 1635
> 
61127 maechler 1636
> ##' @title Comparing Colors
1637
> ##' @param col
1638
> ##' @param nrow
1639
> ##' @param ncol
1640
> ##' @param txt.col
1641
> ##' @return the grid layout, invisibly
1642
> ##' @author Marius Hofert, originally
1643
> plotCol <- function(col, nrow=1, ncol=ceiling(length(col) / nrow),
1644
+                     txt.col="black") {
1645
+     stopifnot(nrow >= 1, ncol >= 1)
1646
+     if(length(col) > nrow*ncol)
1647
+         warning("some colors will not be shown")
1648
+     require(grid)
1649
+     grid.newpage()
1650
+     gl <- grid.layout(nrow, ncol)
1651
+     pushViewport(viewport(layout=gl))
1652
+     ic <- 1
1653
+     for(i in 1:nrow) {
1654
+         for(j in 1:ncol) {
1655
+             pushViewport(viewport(layout.pos.row=i, layout.pos.col=j))
1656
+             grid.rect(gp= gpar(fill=col[ic]))
1657
+             grid.text(col[ic], gp=gpar(col=txt.col))
1658
+             upViewport()
1659
+             ic <- ic+1
1660
+         }
1661
+     }
1662
+     upViewport()
1663
+     invisible(gl)
1664
+ }
1665
 
1666
> ## A Chocolate Bar of colors:
1667
> plotCol(c("#CC8C3C", paste0("chocolate", 2:4),
1668
+           paste0("darkorange", c("",1:2)), paste0("darkgoldenrod", 1:2),
1669
+           "orange", "orange1", "sandybrown", "tan1", "tan2"),
1670
+         nrow=2)
1671
 
1672
> ##' Find close R colors() to a given color {original by Marius Hofert)
1673
> ##' using Euclidean norm in (HSV / RGB / ...) color space
1674
> nearRcolor <- function(rgb, cSpace = c("hsv", "rgb255", "Luv", "Lab"),
1675
+                        dist = switch(cSpace, "hsv" = 0.10, "rgb255" = 30,
1676
+                        "Luv" = 15, "Lab" = 12))
1677
+ {
1678
+     if(is.character(rgb)) rgb <- col2rgb(rgb)
1679
+     stopifnot(length(rgb <- as.vector(rgb)) == 3)
1680
+     Rcol <- col2rgb(.cc <- colors())
1681
+     uniqC <- !duplicated(t(Rcol)) # gray9 == grey9 (etc)
1682
+     Rcol <- Rcol[, uniqC] ; .cc <- .cc[uniqC]
1683
+     cSpace <- match.arg(cSpace)
1684
+     convRGB2 <- function(Rgb, to)
1685
+         t(convertColor(t(Rgb), from="sRGB", to=to, scale.in=255))
1686
+     ## the transformation,  rgb{0..255} --> cSpace :
1687
+     TransF <- switch(cSpace,
1688
+                      "rgb255" = identity,
1689
+                      "hsv" = rgb2hsv,
1690
+                      "Luv" = function(RGB) convRGB2(RGB, "Luv"),
1691
+                      "Lab" = function(RGB) convRGB2(RGB, "Lab"))
1692
+     d <- sqrt(colSums((TransF(Rcol) - as.vector(TransF(rgb)))^2))
1693
+     iS <- sort.list(d[near <- d <= dist])# sorted: closest first
76415 ripley 1694
+     setNames(.cc[near][iS], format(zapsmall(d[near][iS]), digits=3))
61127 maechler 1695
+ }
1696
 
1697
> nearRcolor(col2rgb("tan2"), "rgb")
1698
         0.0         21.1         25.8         29.5 
1699
      "tan2"       "tan1" "sandybrown"    "sienna1" 
1700
 
1701
> nearRcolor(col2rgb("tan2"), "hsv")
1702
      0.0000       0.0410       0.0618       0.0638       0.0667       0.0766 
1703
      "tan2"    "sienna2"     "coral2"    "tomato2"       "tan1"      "coral" 
1704
      0.0778       0.0900       0.0912       0.0918 
1705
   "sienna1" "sandybrown"     "coral1"     "tomato" 
1706
 
1707
> nearRcolor(col2rgb("tan2"), "Luv")
1708
        0.00         7.42         7.48        12.41        13.69 
1709
      "tan2"       "tan1" "sandybrown"    "orange3"    "orange2" 
1710
 
1711
> nearRcolor(col2rgb("tan2"), "Lab")
1712
        0.00         5.56         8.08        11.31 
1713
      "tan2"       "tan1" "sandybrown"       "peru" 
1714
 
1715
> nearRcolor("#334455")
1716
         0.0867 
1717
"darkslategray" 
1718
 
1719
> ## Now, consider choosing a color by looking in the
1720
> ## neighborhood of one you know :
57782 maechler 1721
> 
61127 maechler 1722
> plotCol(nearRcolor("deepskyblue", "rgb", dist=50))
1723
 
1724
> plotCol(nearRcolor("deepskyblue", dist=.1))
1725
 
1726
> plotCol(nearRcolor("tomato", "rgb", dist= 50), nrow=3)
1727
 
1728
> plotCol(nearRcolor("tomato", "hsv", dist=.12), nrow=3)
1729
 
1730
> plotCol(nearRcolor("tomato", "Luv", dist= 25), nrow=3)
1731
 
1732
> plotCol(nearRcolor("tomato", "Lab", dist= 18), nrow=3)
1733
> ## -----------
57782 maechler 1734
> 
61127 maechler 1735
> 
1736
> 
56186 murdoch 1737
> cleanEx()
57782 maechler 1738
 
1739
detaching ‘package:grid’
1740
 
56186 murdoch 1741
> nameEx("contourLines")
1742
> ### * contourLines
1743
> 
1744
> flush(stderr()); flush(stdout())
1745
> 
1746
> ### Name: contourLines
1747
> ### Title: Calculate Contour Lines
1748
> ### Aliases: contourLines
1749
> ### Keywords: dplot
1750
> 
1751
> ### ** Examples
1752
> 
1753
> x <- 10*1:nrow(volcano)
1754
> y <- 10*1:ncol(volcano)
77350 maechler 1755
> cl <- contourLines(x, y, volcano)
1756
> ## summarize the sizes of each the contour lines :
1757
> cbind(lev = vapply(cl, `[[`, .5, "level"),
1758
+        n  = vapply(cl, function(l) length(l$x), 1))
1759
      lev   n
1760
 [1,] 100  47
1761
 [2,] 100  16
1762
 [3,] 100  11
1763
 [4,] 110  45
1764
 [5,] 110  48
1765
 [6,] 110 126
1766
 [7,] 110  14
1767
 [8,] 120 270
1768
 [9,] 130 259
1769
[10,] 140 245
1770
[11,] 150 207
1771
[12,] 150  13
1772
[13,] 160 165
1773
[14,] 160  31
1774
[15,] 170 169
1775
[16,] 170   5
1776
[17,] 170  21
1777
[18,] 180 105
1778
[19,] 180  15
1779
[20,] 190  49
56186 murdoch 1780
> 
77350 maechler 1781
> z <- outer(-9:25, -9:25)
1782
> pretty(range(z), 10) # -300 -200 ... 600 700
1783
 [1] -300 -200 -100    0  100  200  300  400  500  600  700
1784
> utils::str(c2 <- contourLines(z))
1785
List of 12
1786
 $ :List of 3
1787
  ..$ level: num -200
1788
  ..$ x    : num [1:4] 0 0.00895 0.01961 0.02844
1789
  ..$ y    : num [1:4] 0.918 0.941 0.971 1
1790
 $ :List of 3
1791
  ..$ level: num -200
1792
  ..$ x    : num [1:4] 0.918 0.941 0.971 1
1793
  ..$ y    : num [1:4] 0 0.00895 0.01961 0.02844
1794
 $ :List of 3
1795
  ..$ level: num -100
1796
  ..$ x    : num [1:19] 0 0.0196 0.0294 0.0385 0.0546 ...
1797
  ..$ y    : num [1:19] 0.592 0.618 0.632 0.647 0.676 ...
1798
 $ :List of 3
1799
  ..$ level: num -100
1800
  ..$ x    : num [1:19] 0.592 0.618 0.632 0.647 0.676 ...
1801
  ..$ y    : num [1:19] 0 0.0196 0.0294 0.0385 0.0546 ...
1802
 $ :List of 3
1803
  ..$ level: num 0
1804
  ..$ x    : num [1:34] 0 0.0294 0.0588 0.0882 0.1176 ...
1805
  ..$ y    : num [1:34] 0.267 0.268 0.268 0.268 0.269 ...
1806
 $ :List of 3
1807
  ..$ level: num 0
1808
  ..$ x    : num [1:34] 0.267 0.268 0.268 0.268 0.269 ...
1809
  ..$ y    : num [1:34] 0 0.0294 0.0588 0.0882 0.1176 ...
1810
 $ :List of 3
1811
  ..$ level: num 100
1812
  ..$ x    : num [1:44] 1 0.995 0.971 0.941 0.912 ...
1813
  ..$ y    : num [1:44] 0.381 0.382 0.387 0.393 0.398 ...
1814
 $ :List of 3
1815
  ..$ level: num 200
1816
  ..$ x    : num [1:36] 1 0.997 0.971 0.941 0.918 ...
1817
  ..$ y    : num [1:36] 0.499 0.5 0.51 0.52 0.529 ...
1818
 $ :List of 3
1819
  ..$ level: num 300
1820
  ..$ x    : num [1:28] 1 0.998 0.971 0.943 0.941 ...
1821
  ..$ y    : num [1:28] 0.617 0.618 0.632 0.647 0.648 ...
1822
 $ :List of 3
1823
  ..$ level: num 400
1824
  ..$ x    : num [1:20] 1 0.999 0.971 0.957 0.941 ...
1825
  ..$ y    : num [1:20] 0.734 0.735 0.755 0.765 0.776 ...
1826
 $ :List of 3
1827
  ..$ level: num 500
1828
  ..$ x    : num [1:12] 1 0.999 0.971 0.965 0.941 ...
1829
  ..$ y    : num [1:12] 0.852 0.853 0.877 0.882 0.904 ...
1830
 $ :List of 3
1831
  ..$ level: num 600
1832
  ..$ x    : num [1:4] 1 0.999 0.971 0.97
1833
  ..$ y    : num [1:4] 0.97 0.971 0.999 1
1834
>    # no segments for {-300, 700};
1835
>    #  2 segments for {-200, -100, 0}
1836
>    #  1 segment  for  100:600
56186 murdoch 1837
> 
1838
> 
77350 maechler 1839
> 
56186 murdoch 1840
> cleanEx()
1841
> nameEx("convertColor")
1842
> ### * convertColor
1843
> 
1844
> flush(stderr()); flush(stdout())
1845
> 
1846
> ### Name: convertColor
1847
> ### Title: Convert between Colour Spaces
1848
> ### Aliases: convertColor colorspaces
1849
> ### Keywords: color
1850
> 
1851
> ### ** Examples
1852
> 
61127 maechler 1853
> ## The displayable colors from four planes of Lab space
76000 murrell 1854
> ab <- expand.grid(a = (-10:15)*10,
1855
+                   b = (-15:10)*10)
56186 murdoch 1856
> require(graphics); require(stats) # for na.omit
61157 ripley 1857
> par(mfrow = c(2, 2), mar = .1+c(3, 3, 3, .5), mgp = c(2,  .8,  0))
56186 murdoch 1858
> 
61157 ripley 1859
> Lab <- cbind(L = 20, ab)
1860
> srgb <- convertColor(Lab, from = "Lab", to = "sRGB", clip = NA)
1861
> clipped <- attr(na.omit(srgb), "na.action")
1862
> srgb[clipped, ] <- 0
1863
> cols <- rgb(srgb[, 1], srgb[, 2], srgb[, 3])
1864
> image((-10:15)*10, (-15:10)*10, matrix(1:(26*26), ncol = 26), col = cols,
1865
+   xlab = "a", ylab = "b", main = "Lab: L=20")
56186 murdoch 1866
> 
61157 ripley 1867
> Lab <- cbind(L = 40, ab)
1868
> srgb <- convertColor(Lab, from = "Lab", to = "sRGB", clip = NA)
1869
> clipped <- attr(na.omit(srgb), "na.action")
1870
> srgb[clipped, ] <- 0
1871
> cols <- rgb(srgb[, 1], srgb[, 2], srgb[, 3])
1872
> image((-10:15)*10, (-15:10)*10, matrix(1:(26*26), ncol = 26), col = cols,
1873
+   xlab = "a", ylab = "b", main = "Lab: L=40")
56186 murdoch 1874
> 
61157 ripley 1875
> Lab <- cbind(L = 60, ab)
1876
> srgb <- convertColor(Lab, from = "Lab", to = "sRGB", clip = NA)
1877
> clipped <- attr(na.omit(srgb), "na.action")
1878
> srgb[clipped, ] <- 0
1879
> cols <- rgb(srgb[, 1], srgb[, 2], srgb[, 3])
1880
> image((-10:15)*10, (-15:10)*10, matrix(1:(26*26), ncol = 26), col = cols,
1881
+   xlab = "a", ylab = "b", main = "Lab: L=60")
56186 murdoch 1882
> 
61157 ripley 1883
> Lab <- cbind(L = 80, ab)
1884
> srgb <- convertColor(Lab, from = "Lab", to = "sRGB", clip = NA)
1885
> clipped <- attr(na.omit(srgb), "na.action")
1886
> srgb[clipped, ] <- 0
1887
> cols <- rgb(srgb[, 1], srgb[, 2], srgb[, 3])
1888
> image((-10:15)*10, (-15:10)*10, matrix(1:(26*26), ncol = 26), col = cols,
1889
+   xlab = "a", ylab = "b", main = "Lab: L=80")
56186 murdoch 1890
> 
61127 maechler 1891
> cols <- t(col2rgb(palette())); rownames(cols) <- palette(); cols
1892
        red green blue
1893
black     0     0    0
77336 murrell 1894
#DF536B 223    83  107
1895
#61D04F  97   208   79
77438 murrell 1896
#2297E6  34   151  230
1897
#28E2E5  40   226  229
77336 murrell 1898
#D03AF5 208    58  245
1899
#EEC21F 238   194   31
1900
#656565 101   101  101
61157 ripley 1901
> zapsmall(lab <- convertColor(cols, from = "sRGB", to = "Lab", scale.in = 255))
77336 murrell 1902
               L         a         b
1903
black    0.00000   0.00000   0.00000
1904
#DF536B 55.16051  56.30900  16.18063
1905
#61D04F 74.89688 -55.97739  53.00681
77438 murrell 1906
#2297E6 59.98342  -3.54255 -48.62932
1907
#28E2E5 82.01645 -41.73498 -14.10432
77336 murrell 1908
#D03AF5 55.21747  80.08516 -63.84886
1909
#EEC21F 80.15007   2.12223  77.35114
1910
#656565 42.78380   0.00000   0.00000
61127 maechler 1911
> stopifnot(all.equal(cols, # converting back.. getting the original:
61157 ripley 1912
+    round(convertColor(lab, from = "Lab", to = "sRGB", scale.out = 255)),
1913
+                     check.attributes = FALSE))
56186 murdoch 1914
> 
1915
> 
1916
> 
1917
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
1918
> cleanEx()
1919
> nameEx("densCols")
1920
> ### * densCols
1921
> 
1922
> flush(stderr()); flush(stdout())
1923
> 
1924
> ### Name: densCols
1925
> ### Title: Colors for Smooth Density Plots
1926
> ### Aliases: densCols blues9
1927
> ### Keywords: dplot
1928
> 
1929
> ### ** Examples
1930
> 
1931
> 
1932
> cleanEx()
1933
> nameEx("dev")
1934
> ### * dev
1935
> 
1936
> flush(stderr()); flush(stdout())
1937
> 
1938
> ### Name: dev
1939
> ### Title: Control Multiple Devices
1940
> ### Aliases: dev.cur dev.list dev.next dev.prev dev.off dev.set dev.new
1941
> ###   graphics.off
1942
> ### Keywords: device iplot
1943
> 
1944
> ### ** Examples
1945
> 
1946
> ## Not run: 
1947
> ##D ## Unix-specific example
1948
> ##D x11()
1949
> ##D plot(1:10)
1950
> ##D x11()
1951
> ##D plot(rnorm(10))
1952
> ##D dev.set(dev.prev())
61169 ripley 1953
> ##D abline(0, 1) # through the 1:10 points
56186 murdoch 1954
> ##D dev.set(dev.next())
61169 ripley 1955
> ##D abline(h = 0, col = "gray") # for the residual plot
56186 murdoch 1956
> ##D dev.set(dev.prev())
61169 ripley 1957
> ##D dev.off(); dev.off() #- close the two X devices
56186 murdoch 1958
> ## End(Not run)
1959
> 
1960
> 
1961
> 
1962
> cleanEx()
56868 ripley 1963
> nameEx("dev.capabilities")
1964
> ### * dev.capabilities
1965
> 
1966
> flush(stderr()); flush(stdout())
1967
> 
1968
> ### Name: dev.capabilities
1969
> ### Title: Query Capabilities of the Current Graphics Device
1970
> ### Aliases: dev.capabilities
1971
> ### Keywords: dplot
1972
> 
1973
> ### ** Examples
1974
> 
1975
> dev.capabilities()
1976
$semiTransparency
56942 ripley 1977
[1] TRUE
56868 ripley 1978
 
1979
$transparentBackground
56942 ripley 1980
[1] "semi"
56868 ripley 1981
 
1982
$rasterImage
56942 ripley 1983
[1] "yes"
56868 ripley 1984
 
1985
$capture
1986
[1] FALSE
1987
 
1988
$locator
1989
[1] FALSE
1990
 
56904 murdoch 1991
$events
1992
character(0)
1993
 
56868 ripley 1994
> 
1995
> 
1996
> 
1997
> cleanEx()
56186 murdoch 1998
> nameEx("dev.interactive")
1999
> ### * dev.interactive
2000
> 
2001
> flush(stderr()); flush(stdout())
2002
> 
2003
> ### Name: dev.interactive
2004
> ### Title: Is the Current Graphics Device Interactive?
2005
> ### Aliases: dev.interactive deviceIsInteractive
2006
> ### Keywords: device
2007
> 
2008
> ### ** Examples
2009
> 
2010
> dev.interactive()
2011
[1] FALSE
2012
> print(deviceIsInteractive(NULL))
2013
[1] "X11"      "X11cairo" "quartz"   "windows"  "JavaGD"   "CairoWin" "CairoX11"
2014
> 
2015
> 
2016
> 
2017
> cleanEx()
2018
> nameEx("dev.size")
2019
> ### * dev.size
2020
> 
2021
> flush(stderr()); flush(stdout())
2022
> 
2023
> ### Name: dev.size
2024
> ### Title: Find Size of Device Surface
2025
> ### Aliases: dev.size
2026
> ### Keywords: dplot
2027
> 
2028
> ### ** Examples
2029
> 
2030
> dev.size("cm")
2031
[1] 17.78 17.78
2032
> 
2033
> 
2034
> 
2035
> cleanEx()
2036
> nameEx("dev2")
2037
> ### * dev2
2038
> 
2039
> flush(stderr()); flush(stdout())
2040
> 
2041
> ### Name: dev2
2042
> ### Title: Copy Graphics Between Multiple Devices
2043
> ### Aliases: dev.copy dev.print dev.copy2eps dev.copy2pdf dev.control
2044
> ### Keywords: device
2045
> 
2046
> ### ** Examples
2047
> 
2048
> ## Not run: 
58212 ripley 2049
> ##D x11() # on a Unix-alike
61157 ripley 2050
> ##D plot(rnorm(10), main = "Plot 1")
2051
> ##D dev.copy(device = x11)
56186 murdoch 2052
> ##D mtext("Copy 1", 3)
61157 ripley 2053
> ##D dev.print(width = 6, height = 6, horizontal = FALSE) # prints it
56186 murdoch 2054
> ##D dev.off(dev.prev())
2055
> ##D dev.off()
2056
> ## End(Not run)
2057
> 
2058
> 
2059
> 
2060
> cleanEx()
2061
> nameEx("extendrange")
2062
> ### * extendrange
2063
> 
2064
> flush(stderr()); flush(stdout())
2065
> 
2066
> ### Name: extendrange
2067
> ### Title: Extend a Numerical Range by a Small Percentage
2068
> ### Aliases: extendrange
2069
> ### Keywords: dplot
2070
> 
2071
> ### ** Examples
2072
> 
2073
> x <- 1:5
2074
> (r <- range(x))         # 1    5
2075
[1] 1 5
2076
> extendrange(x)          # 0.8  5.2
2077
[1] 0.8 5.2
2078
> extendrange(x, f= 0.01) # 0.96 5.04
2079
[1] 0.96 5.04
74653 maechler 2080
> 
2081
> ## extend more to the right:
2082
> extendrange(x, f=c(.01,.03)) # 0.96 5.12
2083
[1] 0.96 5.12
2084
> 
56186 murdoch 2085
> ## Use 'r' if you have it already:
61157 ripley 2086
> stopifnot(identical(extendrange(r = r),
56186 murdoch 2087
+                     extendrange(x)))
2088
> 
2089
> 
2090
> 
2091
> cleanEx()
2092
> nameEx("getGraphicsEvent")
2093
> ### * getGraphicsEvent
2094
> 
2095
> flush(stderr()); flush(stdout())
2096
> 
2097
> ### Name: getGraphicsEvent
2098
> ### Title: Wait for a mouse or keyboard event from a graphics window
2099
> ### Aliases: getGraphicsEvent setGraphicsEventHandlers getGraphicsEventEnv
2100
> ###   setGraphicsEventEnv
2101
> ### Keywords: iplot
2102
> 
2103
> ### ** Examples
2104
> 
72261 murrell 2105
> # This currently only works on the Windows, X11(type = "Xlib"), and
2106
> # X11(type = "cairo") screen devices...
65700 ripley 2107
> ## Not run: 
2108
> ##D savepar <- par(ask = FALSE)
2109
> ##D dragplot <- function(..., xlim = NULL, ylim = NULL, xaxs = "r", yaxs = "r") {
2110
> ##D     plot(..., xlim = xlim, ylim = ylim, xaxs = xaxs, yaxs = yaxs)
2111
> ##D     startx <- NULL
2112
> ##D     starty <- NULL
2113
> ##D     prevx <- NULL
2114
> ##D     prevy <- NULL
2115
> ##D     usr <- NULL
2116
> ##D 
2117
> ##D     devset <- function()
2118
> ##D         if (dev.cur() != eventEnv$which) dev.set(eventEnv$which)
2119
> ##D 
2120
> ##D     dragmousedown <- function(buttons, x, y) {
2121
> ##D         startx <<- x
2122
> ##D         starty <<- y
2123
> ##D         prevx <<- 0
2124
> ##D         prevy <<- 0
2125
> ##D         devset()
2126
> ##D         usr <<- par("usr")
2127
> ##D         eventEnv$onMouseMove <- dragmousemove
2128
> ##D         NULL
2129
> ##D     }
2130
> ##D 
2131
> ##D     dragmousemove <- function(buttons, x, y) {
2132
> ##D         devset()
2133
> ##D         deltax <- diff(grconvertX(c(startx, x), "ndc", "user"))
2134
> ##D         deltay <- diff(grconvertY(c(starty, y), "ndc", "user"))
2135
> ##D 	if (abs(deltax-prevx) + abs(deltay-prevy) > 0) {
2136
> ##D 	    plot(..., xlim = usr[1:2]-deltax, xaxs = "i",
2137
> ##D 		      ylim = usr[3:4]-deltay, yaxs = "i")
2138
> ##D 	    prevx <<- deltax
2139
> ##D 	    prevy <<- deltay
2140
> ##D 	}
2141
> ##D         NULL
2142
> ##D     }
2143
> ##D 
2144
> ##D     mouseup <- function(buttons, x, y) {
2145
> ##D     	eventEnv$onMouseMove <- NULL
2146
> ##D     }	
2147
> ##D 
2148
> ##D     keydown <- function(key) {
2149
> ##D         if (key == "q") return(invisible(1))
2150
> ##D         eventEnv$onMouseMove <- NULL
2151
> ##D         NULL
2152
> ##D     }
2153
> ##D 
2154
> ##D     setGraphicsEventHandlers(prompt = "Click and drag, hit q to quit",
2155
> ##D                      onMouseDown = dragmousedown,
2156
> ##D                      onMouseUp = mouseup,
2157
> ##D                      onKeybd = keydown)
2158
> ##D     eventEnv <- getGraphicsEventEnv()
2159
> ##D }
2160
> ##D 
2161
> ##D dragplot(rnorm(1000), rnorm(1000))
2162
> ##D getGraphicsEvent()
2163
> ##D par(savepar)
2164
> ## End(Not run)
56186 murdoch 2165
> 
2166
> 
2167
> 
2168
> cleanEx()
67048 ripley 2169
> nameEx("grSoftVersion")
2170
> ### * grSoftVersion
2171
> 
2172
> flush(stderr()); flush(stdout())
2173
> 
2174
> ### Name: grSoftVersion
2175
> ### Title: Report Versions of Graphics Software
2176
> ### Aliases: grSoftVersion
2177
> 
2178
> ### ** Examples
2179
> 
2180
> 
2181
> 
2182
> 
2183
> cleanEx()
56186 murdoch 2184
> nameEx("gray")
2185
> ### * gray
2186
> 
2187
> flush(stderr()); flush(stdout())
2188
> 
2189
> ### Name: gray
2190
> ### Title: Gray Level Specification
2191
> ### Aliases: gray grey
2192
> ### Keywords: color
2193
> 
2194
> ### ** Examples
2195
> 
2196
> gray(0:8 / 8)
2197
[1] "#000000" "#202020" "#404040" "#606060" "#808080" "#9F9F9F" "#BFBFBF"
2198
[8] "#DFDFDF" "#FFFFFF"
2199
> 
2200
> 
2201
> 
2202
> cleanEx()
2203
> nameEx("gray.colors")
2204
> ### * gray.colors
2205
> 
2206
> flush(stderr()); flush(stdout())
2207
> 
2208
> ### Name: gray.colors
2209
> ### Title: Gray Color Palette
2210
> ### Aliases: gray.colors grey.colors
2211
> ### Keywords: color
2212
> 
2213
> ### ** Examples
2214
> 
2215
> require(graphics)
2216
> 
61169 ripley 2217
> pie(rep(1, 12), col = gray.colors(12))
56186 murdoch 2218
> barplot(1:12, col = gray.colors(12))
2219
> 
2220
> 
2221
> 
2222
> cleanEx()
2223
> nameEx("hcl")
2224
> ### * hcl
2225
> 
2226
> flush(stderr()); flush(stdout())
2227
> 
2228
> ### Name: hcl
2229
> ### Title: HCL Color Specification
2230
> ### Aliases: hcl
2231
> ### Keywords: color dplot
2232
> 
2233
> ### ** Examples
2234
> 
2235
> require(graphics)
2236
> 
2237
> # The Foley and Van Dam PhD Data.
2238
> csd <- matrix(c( 4,2,4,6, 4,3,1,4, 4,7,7,1,
2239
+                  0,7,3,2, 4,5,3,2, 5,4,2,2,
2240
+                  3,1,3,0, 4,4,6,7, 1,10,8,7,
2241
+                  1,5,3,2, 1,5,2,1, 4,1,4,3,
61157 ripley 2242
+                  0,3,0,6, 2,1,5,5), nrow = 4)
56186 murdoch 2243
> 
2244
> csphd <- function(colors)
2245
+   barplot(csd, col = colors, ylim = c(0,30),
2246
+           names = 72:85, xlab = "Year", ylab = "Students",
2247
+           legend = c("Winter", "Spring", "Summer", "Fall"),
2248
+           main = "Computer Science PhD Graduates", las = 1)
2249
> 
2250
> # The Original (Metaphorical) Colors (Ouch!)
2251
> csphd(c("blue", "green", "yellow", "orange"))
2252
> 
2253
> # A Color Tetrad (Maximal Color Differences)
2254
> csphd(hcl(h = c(30, 120, 210, 300)))
2255
> 
2256
> # Same, but lighter and less colorful
57440 murdoch 2257
> # Turn off automatic correction to make sure
56186 murdoch 2258
> # that we have defined real colors.
2259
> csphd(hcl(h = c(30, 120, 210, 300),
2260
+           c = 20, l = 90, fixup = FALSE))
2261
> 
2262
> # Analogous Colors
2263
> # Good for those with red/green color confusion
2264
> csphd(hcl(h = seq(60, 240, by = 60)))
2265
> 
2266
> # Metaphorical Colors
2267
> csphd(hcl(h = seq(210, 60, length = 4)))
2268
> 
2269
> # Cool Colors
2270
> csphd(hcl(h = seq(120, 0, length = 4) + 150))
2271
> 
2272
> # Warm Colors
2273
> csphd(hcl(h = seq(120, 0, length = 4) - 30))
2274
> 
2275
> # Single Color
2276
> hist(stats::rnorm(1000), col = hcl(240))
2277
> 
61127 maechler 2278
> ## Exploring the hcl() color space {in its mapping to R's sRGB colors}:
2279
> demo(hclColors)
2280
 
2281
 
2282
	demo(hclColors)
2283
	---- ~~~~~~~~~
2284
 
2285
> ### ------ hcl() explorations
56186 murdoch 2286
> 
61127 maechler 2287
> hcl.wheel <-
2288
+     function(chroma = 35, lums = 0:100, hues = 1:360, asp = 1,
2289
+              p.cex = 0.6, do.label = FALSE, rev.lum = FALSE,
2290
+              fixup = TRUE)
2291
+ {
2292
+     ## Purpose: show chroma "sections" of hcl() color space; see  ?hcl
2293
+     ## ----------------------------------------------------------------------
2294
+     ## Arguments: chroma: can be vector -> multiple plots are done,
2295
+     ##            lums, hues, fixup : all corresponding to hcl()'s args
2296
+     ##            rev.lum: logical indicating if luminance
2297
+     ## 			should go from outer to inner
2298
+     ## ----------------------------------------------------------------------
2299
+     ## Author: Martin Maechler, Date: 24 Jun 2005
2300
+ 
2301
+     require("graphics")
2302
+     stopifnot(is.numeric(lums), lums >= 0, lums <= 100,
2303
+               is.numeric(hues), hues >= 0, hues <= 360,
2304
+               is.numeric(chroma), chroma >= 0, (nch <- length(chroma)) >= 1)
2305
+     if(is.unsorted(hues)) hues <- sort(hues)
2306
+     if(nch > 1) {
64277 ripley 2307
+         op <- par(mfrow= n2mfrow(nch), mar = c(0,0,0,0), xpd = TRUE)
61127 maechler 2308
+         on.exit(par(op))
2309
+     }
2310
+     for(i.c in 1:nch) {
2311
+         plot(-1:1,-1:1, type="n", axes = FALSE, xlab="",ylab="", asp = asp)
2312
+         ## main = sprintf("hcl(h = <angle>, c = %g)", chroma[i.c]),
2313
+         text(0.4, 0.99, paste("chroma =", format(chroma[i.c])),
2314
+              adj = 0, font = 4)
2315
+         l.s <- (if(rev.lum) rev(lums) else lums) / max(lums) # <= 1
2316
+         for(ang in hues) { # could do all this using outer() instead of for()...
2317
+             a. <- ang * pi/180
2318
+             z.a <- exp(1i * a.)
2319
+             cols <- hcl(ang, c = chroma[i.c], l = lums, fixup = fixup)
2320
+             points(l.s * z.a, pch = 16, col = cols, cex = p.cex)
2321
+             ##if(do."text") : draw the 0,45,90,... angle "lines"
2322
+             if(do.label)
2323
+                 text(z.a*1.05, labels = ang, col = cols[length(cols)/2],
2324
+                      srt = ang)
2325
+         }
2326
+         if(!fixup) ## show the outline
2327
+             lines(exp(1i * hues * pi/180))
2328
+    }
2329
+    invisible()
2330
+ }
2331
 
2332
> ## and now a few interesting calls :
56186 murdoch 2333
> 
61127 maechler 2334
> hcl.wheel() # and watch it redraw when you fiddle with the graphic window
2335
 
2336
> hcl.wheel(rev.lum= TRUE) # ditto
2337
 
2338
> hcl.wheel(do.lab = TRUE) # ditto
2339
 
2340
> ## Now watch:
2341
> hcl.wheel(ch = c(25,35,45,55))
2342
 
2343
> hcl.wheel(ch = seq(10, 90, by = 10), p.cex = 0.4)
2344
 
2345
> hcl.wheel(ch = seq(10, 90, by = 10), p.cex = 0.3, fixup = FALSE)
2346
 
2347
> hcl.wheel(ch = seq(10, 90, by = 10), p.cex = 0.3, rev.lum = TRUE)
2348
 
2349
> if(dev.interactive()) # new "graphics window" -- to compare with previous :
2350
+     dev.new()
2351
 
2352
> hcl.wheel(ch = seq(10, 90, by = 10), p.cex = 0.3, rev.lum = TRUE, fixup=FALSE)
2353
> 
2354
> 
2355
> 
2356
> 
56186 murdoch 2357
> cleanEx()
2358
> nameEx("hsv")
2359
> ### * hsv
2360
> 
2361
> flush(stderr()); flush(stdout())
2362
> 
2363
> ### Name: hsv
2364
> ### Title: HSV Color Specification
2365
> ### Aliases: hsv
2366
> ### Keywords: color dplot
2367
> 
2368
> ### ** Examples
2369
> 
2370
> require(graphics)
2371
> 
2372
> hsv(.5,.5,.5)
2373
[1] "#408080"
2374
> 
2375
> ## Red tones:
2376
> n <- 20;  y <- -sin(3*pi*((1:n)-1/2)/n)
61169 ripley 2377
> op <- par(mar = rep(1.5, 4))
56186 murdoch 2378
> plot(y, axes = FALSE, frame.plot = TRUE,
2379
+      xlab = "", ylab = "", pch = 21, cex = 30,
61157 ripley 2380
+      bg = rainbow(n, start = .85, end = .1),
56186 murdoch 2381
+      main = "Red tones")
2382
> par(op)
2383
> 
2384
> 
2385
> 
2386
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
2387
> cleanEx()
2388
> nameEx("make.rgb")
2389
> ### * make.rgb
2390
> 
2391
> flush(stderr()); flush(stdout())
2392
> 
2393
> ### Name: make.rgb
2394
> ### Title: Create colour spaces
2395
> ### Aliases: make.rgb colorConverter
2396
> ### Keywords: color
2397
> 
2398
> ### ** Examples
2399
> 
61157 ripley 2400
> (pal <- make.rgb(red =   c(0.6400, 0.3300),
2401
+                  green = c(0.2900, 0.6000),
2402
+                  blue =  c(0.1500, 0.0600),
56186 murdoch 2403
+                  name = "PAL/SECAM RGB"))
2404
Color space converter: PAL/SECAM RGB
2405
Reference white: D65
2406
display gamma = 2.2
2407
> 
2408
> ## converter for sRGB in #rrggbb format
61169 ripley 2409
> hexcolor <- colorConverter(toXYZ = function(hex, ...) {
56186 murdoch 2410
+                             rgb <- t(col2rgb(hex))/255
58933 ripley 2411
+                             colorspaces$sRGB$toXYZ(rgb, ...) },
61169 ripley 2412
+                            fromXYZ = function(xyz, ...) {
75868 murrell 2413
+                               rgb <- colorspaces$sRGB$fromXYZ(xyz, ...)
61169 ripley 2414
+                               rgb <- round(rgb, 5)
56186 murdoch 2415
+                               if (min(rgb) < 0 || max(rgb) > 1)
2416
+                                    as.character(NA)
58933 ripley 2417
+                               else rgb(rgb[1], rgb[2], rgb[3])},
56186 murdoch 2418
+                            white = "D65", name = "#rrggbb")
2419
> 
2420
> (cols <- t(col2rgb(palette())))
2421
     red green blue
2422
[1,]   0     0    0
77336 murrell 2423
[2,] 223    83  107
2424
[3,]  97   208   79
77438 murrell 2425
[4,]  34   151  230
2426
[5,]  40   226  229
77336 murrell 2427
[6,] 208    58  245
2428
[7,] 238   194   31
2429
[8,] 101   101  101
61169 ripley 2430
> zapsmall(luv <- convertColor(cols, from = "sRGB", to = "Luv", scale.in = 255))
58933 ripley 2431
            L         u          v
2432
[1,]  0.00000   0.00000    0.00000
77336 murrell 2433
[2,] 55.16051  99.94871    8.95299
2434
[3,] 74.89688 -51.95694   73.49647
77438 murrell 2435
[4,] 59.98342 -36.43653  -76.74275
2436
[5,] 82.01645 -61.64283  -15.85619
77336 murrell 2437
[6,] 55.21747  51.07792 -108.40014
2438
[7,] 80.15007  38.24066   81.46952
2439
[8,] 42.78380   0.00000    0.00000
61157 ripley 2440
> (hex <- convertColor(luv, from = "Luv",  to = hexcolor, scale.out = NULL))
75868 murrell 2441
     [,1]     
2442
[1,] "#000000"
77336 murrell 2443
[2,] "#DF536B"
2444
[3,] "#61D04F"
77438 murrell 2445
[4,] "#2297E6"
2446
[5,] "#28E2E5"
77336 murrell 2447
[6,] "#D03AF5"
2448
[7,] "#EEC21F"
2449
[8,] "#656565"
56186 murdoch 2450
> 
2451
> ## must make hex a matrix before using it
61157 ripley 2452
> (cc <- round(convertColor(as.matrix(hex), from = hexcolor, to = "sRGB",
2453
+                           scale.in = NULL, scale.out = 255)))
56186 murdoch 2454
     [,1] [,2] [,3]
2455
[1,]    0    0    0
77336 murrell 2456
[2,]  223   83  107
2457
[3,]   97  208   79
77438 murrell 2458
[4,]   34  151  230
2459
[5,]   40  226  229
77336 murrell 2460
[6,]  208   58  245
2461
[7,]  238  194   31
2462
[8,]  101  101  101
56186 murdoch 2463
> stopifnot(cc == cols)
2464
> 
75868 murrell 2465
> ## Internally vectorized version of hexcolor, notice the use
2466
> ## of `vectorized = TRUE`:
56186 murdoch 2467
> 
75868 murrell 2468
> hexcolorv <- colorConverter(toXYZ = function(hex, ...) {
2469
+                             rgb <- t(col2rgb(hex))/255
2470
+                             colorspaces$sRGB$toXYZ(rgb, ...) },
2471
+                            fromXYZ = function(xyz, ...) {
2472
+                               rgb <- colorspaces$sRGB$fromXYZ(xyz, ...)
2473
+                               rgb <- round(rgb, 5)
2474
+                               oob <- pmin(rgb[,1],rgb[,2],rgb[,3]) < 0 |
2475
+                                      pmax(rgb[,1],rgb[,2],rgb[,3]) > 0
2476
+                               res <- rep(NA_character_, nrow(rgb))
2477
+                               res[!oob] <- rgb(rgb[!oob,,drop=FALSE])},
2478
+                            white = "D65", name = "#rrggbb",
2479
+                            vectorized=TRUE)
2480
> (ccv <- round(convertColor(as.matrix(hex), from = hexcolor, to = "sRGB",
2481
+                            scale.in = NULL, scale.out = 255)))
2482
     [,1] [,2] [,3]
2483
[1,]    0    0    0
77336 murrell 2484
[2,]  223   83  107
2485
[3,]   97  208   79
77438 murrell 2486
[4,]   34  151  230
2487
[5,]   40  226  229
77336 murrell 2488
[6,]  208   58  245
2489
[7,]  238  194   31
2490
[8,]  101  101  101
75868 murrell 2491
> stopifnot(ccv == cols)
56186 murdoch 2492
> 
75868 murrell 2493
> 
2494
> 
2495
> 
56186 murdoch 2496
> cleanEx()
2497
> nameEx("n2mfrow")
2498
> ### * n2mfrow
2499
> 
2500
> flush(stderr()); flush(stdout())
2501
> 
2502
> ### Name: n2mfrow
77448 maechler 2503
> ### Title: Compute Default 'mfrow' From Number of Plots
56186 murdoch 2504
> ### Aliases: n2mfrow
2505
> ### Keywords: dplot utilities
2506
> 
2507
> ### ** Examples
2508
> 
2509
> require(graphics)
2510
> 
2511
> n2mfrow(8) # 3 x 3
2512
[1] 3 3
2513
> 
61157 ripley 2514
> n <- 5 ; x <- seq(-2, 2, len = 51)
56186 murdoch 2515
> ## suppose now that 'n' is not known {inside function}
2516
> op <- par(mfrow = n2mfrow(n))
2517
> for (j in 1:n)
2518
+    plot(x, x^j, main = substitute(x^ exp, list(exp = j)), type = "l",
2519
+    col = "blue")
2520
> 
77447 maechler 2521
> sapply(1:14, n2mfrow)
2522
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
2523
[1,]    1    2    3    2    3    3    3    3    3     4     4     4     4     4
2524
[2,]    1    1    1    2    2    2    3    3    3     3     3     3     4     4
2525
> sapply(1:14, n2mfrow, asp=16/9)
2526
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
2527
[1,]    1    2    2    2    2    2    2    3    3     3     3     3     3     3
2528
[2,]    1    1    2    2    3    3    4    3    3     4     4     4     5     5
56186 murdoch 2529
> 
2530
> 
2531
> 
2532
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
2533
> cleanEx()
2534
> nameEx("nclass")
2535
> ### * nclass
2536
> 
2537
> flush(stderr()); flush(stdout())
2538
> 
2539
> ### Name: nclass
2540
> ### Title: Compute the Number of Classes for a Histogram
2541
> ### Aliases: nclass.Sturges nclass.scott nclass.FD
2542
> ### Keywords: univar
2543
> 
2544
> ### ** Examples
2545
> 
2546
> set.seed(1)
2547
> x <- stats::rnorm(1111)
2548
> nclass.Sturges(x)
2549
[1] 12
2550
> 
2551
> ## Compare them:
2552
> NC <- function(x) c(Sturges = nclass.Sturges(x),
2553
+       Scott = nclass.scott(x), FD = nclass.FD(x))
2554
> NC(x)
2555
Sturges   Scott      FD 
2556
     12      20      26 
2557
> onePt <- rep(1, 11)
2558
> NC(onePt) # no longer gives NaN
2559
Sturges   Scott      FD 
2560
      5       1       1 
2561
> 
2562
> 
2563
> 
2564
> cleanEx()
2565
> nameEx("palette")
2566
> ### * palette
2567
> 
2568
> flush(stderr()); flush(stdout())
2569
> 
2570
> ### Name: palette
2571
> ### Title: Set or View the Graphics Palette
77336 murrell 2572
> ### Aliases: palette palette.pals palette.colors
56186 murdoch 2573
> ### Keywords: color sysdata
2574
> 
2575
> ### ** Examples
2576
> 
2577
> require(graphics)
2578
> 
2579
> palette()               # obtain the current palette
77438 murrell 2580
[1] "black"   "#DF536B" "#61D04F" "#2297E6" "#28E2E5" "#D03AF5" "#EEC21F"
77336 murrell 2581
[8] "#656565"
77448 maechler 2582
> palette("R3");palette() # old default palette
2583
[1] "black"   "red"     "green3"  "blue"    "cyan"    "magenta" "yellow" 
2584
[8] "gray"   
77375 maechler 2585
> palette("ggplot2")      # ggplot2-style palette
77448 maechler 2586
> palette()
2587
[1] "black"   "#F8766D" "#00BA38" "#619CFF" "#00BFC4" "#F564E3" "#B79F00"
2588
[8] "gray62" 
56186 murdoch 2589
> 
77375 maechler 2590
> palette(hcl.colors(8, "viridis"))
2591
> 
61157 ripley 2592
> (palette(gray(seq(0,.9,len = 25)))) # gray scales; print old palette
77375 maechler 2593
[1] "#4B0055" "#3C3777" "#006290" "#008A98" "#00AC8E" "#25C771" "#A6DA42"
2594
[8] "#FDE333"
61169 ripley 2595
> matplot(outer(1:100, 1:30), type = "l", lty = 1,lwd = 2, col = 1:30,
56186 murdoch 2596
+         main = "Gray Scales Palette",
61169 ripley 2597
+         sub = "palette(gray(seq(0, .9, len=25)))")
56186 murdoch 2598
> palette("default")      # reset back to the default
2599
> 
77375 maechler 2600
> ## on a device where alpha transparency is supported,
56186 murdoch 2601
> ##  use 'alpha = 0.3' transparency with the default palette :
2602
> mycols <- adjustcolor(palette(), alpha.f = 0.3)
2603
> opal <- palette(mycols)
2604
> x <- rnorm(1000); xy <- cbind(x, 3*x + rnorm(1000))
61157 ripley 2605
> plot (xy, lwd = 2,
56186 murdoch 2606
+        main = "Alpha-Transparency Palette\n alpha = 0.3")
2607
> xy[,1] <- -xy[,1]
61157 ripley 2608
> points(xy, col = 8, pch = 16, cex = 1.5)
56186 murdoch 2609
> palette("default")
2610
> 
77336 murrell 2611
> ## List available built-in palettes
2612
> palette.pals()
2613
 [1] "R3"              "R4"              "ggplot2"         "Okabe-Ito"      
2614
 [5] "Accent"          "Dark 2"          "Paired"          "Pastel 1"       
2615
 [9] "Pastel 2"        "Set 1"           "Set 2"           "Set 3"          
2616
[13] "Tableau 10"      "Classic Tableau" "Polychrome 36"   "Alphabet"       
56186 murdoch 2617
> 
77336 murrell 2618
> ## Demonstrate the colors 1:8 in different palettes using a custom matplot()
77448 maechler 2619
> sinplot <- function(main=NULL) {
77336 murrell 2620
+     x <- outer(
2621
+ 	seq(-pi, pi, length.out = 50),
2622
+ 	seq(0, pi, length.out = 8),
2623
+ 	function(x, y) sin(x - y)
2624
+     )
77448 maechler 2625
+     matplot(x, type = "l", lwd = 4, lty = 1, col = 1:8, ylab = "", main=main)
77336 murrell 2626
+ }
77448 maechler 2627
> sinplot("default palette")
56186 murdoch 2628
> 
77448 maechler 2629
> palette("R3");        sinplot("R3")
2630
> palette("Okabe-Ito"); sinplot("Okabe-Ito")
2631
> palette("Tableau")  ; sinplot("Tableau")
2632
> palette("default") # reset
77336 murrell 2633
> 
77448 maechler 2634
> ## color swatches for palette.colors()
2635
> palette.swatch <- function(palette = palette.pals(), n = 8, nrow = 8,
2636
+                            border = "black", cex = 1, ...)
2637
+ {
2638
+      cols <- sapply(palette, palette.colors, n = n, recycle = TRUE)
2639
+      ncol <- ncol(cols)
2640
+      nswatch <- min(ncol, nrow)
2641
+      op <- par(mar = rep(0.1, 4),
2642
+                mfrow = c(1, min(5, ceiling(ncol/nrow))),
2643
+      	       cex = cex, ...)
2644
+      on.exit(par(op))
2645
+      while (length(palette)) {
2646
+  	subset <- seq_len(min(nrow, ncol(cols)))
2647
+  	plot.new()
2648
+  	plot.window(c(0, n), c(0.25, nrow + 0.25))
2649
+  	y <- rev(subset)
2650
+  	text(0, y + 0.1, palette[subset], adj = c(0, 0))
2651
+  	y <- rep(y, each = n)
2652
+  	rect(rep(0:(n-1), n), y, rep(1:n, n), y - 0.5,
2653
+  	     col = cols[, subset], border = border)
2654
+  	palette <- palette[-subset]
2655
+  	cols    <- cols [, -subset]
2656
+      }
2657
+ }
77336 murrell 2658
> 
77448 maechler 2659
> palette.swatch()
77336 murrell 2660
> 
77448 maechler 2661
> palette.swatch(n = 26) # show full "Alphabet"; recycle most others
2662
> 
2663
> 
2664
> 
56186 murdoch 2665
> cleanEx()
2666
> nameEx("palettes")
2667
> ### * palettes
2668
> 
2669
> flush(stderr()); flush(stdout())
2670
> 
2671
> ### Name: Palettes
2672
> ### Title: Color Palettes
2673
> ### Aliases: rainbow heat.colors terrain.colors topo.colors cm.colors
76276 murrell 2674
> ###   hcl.colors hcl.pals
56186 murdoch 2675
> ### Keywords: color dplot
2676
> 
2677
> ### ** Examples
2678
> 
76276 murrell 2679
> require("graphics")
56186 murdoch 2680
> 
76276 murrell 2681
> # color wheels in RGB/HSV and HCL space
2682
> par(mfrow = c(2, 2))
2683
> pie(rep(1, 12), col = rainbow(12), main = "RGB/HSV")
2684
> pie(rep(1, 12), col = hcl.colors(12, "Set 2"), main = "HCL")
2685
> par(mfrow = c(1, 1))
2686
> 
2687
> ## color swatches for RGB/HSV palettes
56186 murdoch 2688
> demo.pal <-
61157 ripley 2689
+   function(n, border = if (n < 32) "light gray" else NA,
61169 ripley 2690
+            main = paste("color palettes;  n=", n),
56186 murdoch 2691
+            ch.col = c("rainbow(n, start=.7, end=.1)", "heat.colors(n)",
2692
+                       "terrain.colors(n)", "topo.colors(n)",
2693
+                       "cm.colors(n)"))
2694
+ {
2695
+     nt <- length(ch.col)
2696
+     i <- 1:n; j <- n / nt; d <- j/6; dy <- 2*d
61157 ripley 2697
+     plot(i, i+d, type = "n", yaxt = "n", ylab = "", main = main)
56186 murdoch 2698
+     for (k in 1:nt) {
2699
+         rect(i-.5, (k-1)*j+ dy, i+.4, k*j,
76385 maechler 2700
+              col = eval(str2lang(ch.col[k])), border = border)
61157 ripley 2701
+         text(2*j,  k * j + dy/4, ch.col[k])
56186 murdoch 2702
+     }
2703
+ }
76276 murrell 2704
> demo.pal(16)
56186 murdoch 2705
> 
76276 murrell 2706
> ## color swatches for HCL palettes
2707
> hcl.swatch <- function(type = NULL, n = 5, nrow = 11,
2708
+   border = if (n < 15) "black" else NA) {
2709
+     palette <- hcl.pals(type)
2710
+     cols <- sapply(palette, hcl.colors, n = n)
2711
+     ncol <- ncol(cols)
2712
+     nswatch <- min(ncol, nrow)
2713
+ 
2714
+     par(mar = rep(0.1, 4),
77427 ripley 2715
+         mfrow = c(1, min(5, ceiling(ncol/nrow))),
76276 murrell 2716
+         pin = c(1, 0.5 * nswatch),
2717
+         cex = 0.7)
2718
+ 
2719
+     while (length(palette)) {
2720
+         subset <- 1:min(nrow, ncol(cols))
2721
+         plot.new()
2722
+         plot.window(c(0, n), c(0, nrow + 1))
2723
+         text(0, rev(subset) + 0.1, palette[subset], adj = c(0, 0))
2724
+         y <- rep(subset, each = n)
2725
+         rect(rep(0:(n-1), n), rev(y), rep(1:n, n), rev(y) - 0.5,
2726
+              col = cols[, subset], border = border)
2727
+         palette <- palette[-subset]
2728
+         cols <- cols[, -subset]
2729
+     }
2730
+ 
2731
+     par(mfrow = c(1, 1), mar = c(5.1, 4.1, 4.1, 2.1), cex = 1)
2732
+ }
2733
> hcl.swatch()
2734
> hcl.swatch("qualitative")
2735
> hcl.swatch("sequential")
2736
> hcl.swatch("diverging")
2737
> hcl.swatch("divergingx")
56186 murdoch 2738
> 
76276 murrell 2739
> ## heat maps with sequential HCL palette (purple)
2740
> image(volcano, col = hcl.colors(11, "purples", rev = TRUE))
2741
> filled.contour(volcano, nlevels = 10,
2742
+                color.palette = function(n, ...)
2743
+                    hcl.colors(n, "purples", rev = TRUE, ...))
56186 murdoch 2744
> 
76276 murrell 2745
> ## list available HCL color palettes
2746
> hcl.pals("qualitative")
2747
[1] "Pastel 1" "Dark 2"   "Dark 3"   "Set 2"    "Set 3"    "Warm"     "Cold"    
2748
[8] "Harmonic" "Dynamic" 
2749
> hcl.pals("sequential")
2750
 [1] "Grays"         "Light Grays"   "Blues 2"       "Blues 3"      
2751
 [5] "Purples 2"     "Purples 3"     "Reds 2"        "Reds 3"       
2752
 [9] "Greens 2"      "Greens 3"      "Oslo"          "Purple-Blue"  
2753
[13] "Red-Purple"    "Red-Blue"      "Purple-Orange" "Purple-Yellow"
2754
[17] "Blue-Yellow"   "Green-Yellow"  "Red-Yellow"    "Heat"         
2755
[21] "Heat 2"        "Terrain"       "Terrain 2"     "Viridis"      
2756
[25] "Plasma"        "Inferno"       "Dark Mint"     "Mint"         
2757
[29] "BluGrn"        "Teal"          "TealGrn"       "Emrld"        
2758
[33] "BluYl"         "ag_GrnYl"      "Peach"         "PinkYl"       
2759
[37] "Burg"          "BurgYl"        "RedOr"         "OrYel"        
2760
[41] "Purp"          "PurpOr"        "Sunset"        "Magenta"      
2761
[45] "SunsetDark"    "ag_Sunset"     "BrwnYl"        "YlOrRd"       
2762
[49] "YlOrBr"        "OrRd"          "Oranges"       "YlGn"         
2763
[53] "YlGnBu"        "Reds"          "RdPu"          "PuRd"         
2764
[57] "Purples"       "PuBuGn"        "PuBu"          "Greens"       
2765
[61] "BuGn"          "GnBu"          "BuPu"          "Blues"        
2766
[65] "Lajolla"       "Turku"        
2767
> hcl.pals("diverging")
2768
 [1] "Blue-Red"      "Blue-Red 2"    "Blue-Red 3"    "Red-Green"    
2769
 [5] "Purple-Green"  "Purple-Brown"  "Green-Brown"   "Blue-Yellow 2"
2770
 [9] "Blue-Yellow 3" "Green-Orange"  "Cyan-Magenta"  "Tropic"       
2771
[13] "Broc"          "Cork"          "Vik"           "Berlin"       
2772
[17] "Lisbon"        "Tofino"       
2773
> hcl.pals("divergingx")
2774
 [1] "ArmyRose" "Earth"    "Fall"     "Geyser"   "TealRose" "Temps"   
2775
 [7] "PuOr"     "RdBu"     "RdGy"     "PiYG"     "PRGn"     "BrBG"    
2776
[13] "RdYlBu"   "RdYlGn"   "Spectral" "Zissou 1" "Cividis" 
2777
> 
2778
> 
2779
> 
2780
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
56186 murdoch 2781
> cleanEx()
2782
> nameEx("pdf")
2783
> ### * pdf
2784
> 
2785
> flush(stderr()); flush(stdout())
2786
> 
2787
> ### Name: pdf
2788
> ### Title: PDF Graphics Device
2789
> ### Aliases: pdf
2790
> ### Keywords: device
2791
> 
2792
> ### ** Examples
2793
> 
2794
> 
2795
> 
2796
> cleanEx()
2797
> nameEx("pdf.options")
2798
> ### * pdf.options
2799
> 
2800
> flush(stderr()); flush(stdout())
2801
> 
2802
> ### Name: pdf.options
2803
> ### Title: Auxiliary Function to Set/View Defaults for Arguments of pdf
2804
> ### Aliases: pdf.options
2805
> ### Keywords: device
2806
> 
2807
> ### ** Examples
2808
> 
2809
> pdf.options(bg = "pink")
2810
> utils::str(pdf.options())
56925 ripley 2811
List of 18
56186 murdoch 2812
 $ width      : num 7
2813
 $ height     : num 7
2814
 $ onefile    : logi TRUE
2815
 $ family     : chr "Helvetica"
2816
 $ title      : chr "R Graphics Output"
2817
 $ fonts      : NULL
2818
 $ version    : chr "1.4"
2819
 $ paper      : chr "special"
2820
 $ encoding   : chr "default"
2821
 $ bg         : chr "pink"
2822
 $ fg         : chr "black"
2823
 $ pointsize  : num 12
2824
 $ pagecentre : logi TRUE
56808 ripley 2825
 $ colormodel : chr "srgb"
56186 murdoch 2826
 $ useDingbats: logi TRUE
2827
 $ useKerning : logi TRUE
2828
 $ fillOddEven: logi FALSE
2829
 $ compress   : logi TRUE
2830
> pdf.options(reset = TRUE) # back to factory-fresh
2831
> 
2832
> 
2833
> 
2834
> cleanEx()
2835
> nameEx("pictex")
2836
> ### * pictex
2837
> 
2838
> flush(stderr()); flush(stdout())
2839
> 
2840
> ### Name: pictex
2841
> ### Title: A PicTeX Graphics Driver
2842
> ### Aliases: pictex
2843
> ### Keywords: device
2844
> 
2845
> ### ** Examples
2846
> 
2847
> require(graphics)
74547 maechler 2848
> ## Don't show: 
2849
> oldwd <- setwd(tempdir())
2850
> ## End(Don't show)
56186 murdoch 2851
> 
2852
> pictex()
61169 ripley 2853
> plot(1:11, (-5:5)^2, type = "b", main = "Simple Example Plot")
56186 murdoch 2854
> dev.off()
56942 ripley 2855
pdf 
2856
  2 
56186 murdoch 2857
> ##--------------------
2858
> ## Not run: 
2859
> ##D %% LaTeX Example
2860
> ##D \documentclass{article}
2861
> ##D \usepackage{pictex}
2862
> ##D \usepackage{graphics} % for \rotatebox
2863
> ##D \begin{document}
2864
> ##D %...
2865
> ##D \begin{figure}[h]
2866
> ##D   \centerline{\input{Rplots.tex}}
2867
> ##D   \caption{}
2868
> ##D \end{figure}
2869
> ##D %...
2870
> ##D \end{document}
2871
> ## End(Not run)
2872
> ##--------------------
2873
> unlink("Rplots.tex")
74547 maechler 2874
> ## Don't show: 
2875
> setwd(oldwd)
2876
> ## End(Don't show)
56186 murdoch 2877
> 
2878
> 
2879
> 
2880
> cleanEx()
2881
> nameEx("plotmath")
2882
> ### * plotmath
2883
> 
2884
> flush(stderr()); flush(stdout())
2885
> 
2886
> ### Name: plotmath
2887
> ### Title: Mathematical Annotation in R
2888
> ### Aliases: plotmath symbol plain bold italic bolditalic hat bar dot ring
2889
> ###   widehat widetilde displaystyle textstyle scriptstyle
2890
> ###   scriptscriptstyle underline phantom over frac atop integral inf sup
2891
> ###   group bgroup
2892
> ### Keywords: aplot
2893
> 
2894
> ### ** Examples
2895
> 
2896
> require(graphics)
2897
> 
2898
> x <- seq(-4, 4, len = 101)
2899
> y <- cbind(sin(x), cos(x))
2900
> matplot(x, y, type = "l", xaxt = "n",
2901
+         main = expression(paste(plain(sin) * phi, "  and  ",
2902
+                                 plain(cos) * phi)),
2903
+         ylab = expression("sin" * phi, "cos" * phi), # only 1st is taken
2904
+         xlab = expression(paste("Phase Angle ", phi)),
2905
+         col.main = "blue")
2906
> axis(1, at = c(-pi, -pi/2, 0, pi/2, pi),
2907
+      labels = expression(-pi, -pi/2, 0, pi/2, pi))
2908
> 
2909
> 
2910
> ## How to combine "math" and numeric variables :
2911
> plot(1:10, type="n", xlab="", ylab="", main = "plot math & numbers")
2912
> theta <- 1.23 ; mtext(bquote(hat(theta) == .(theta)), line= .25)
2913
> for(i in 2:9)
61169 ripley 2914
+     text(i, i+1, substitute(list(xi, eta) == group("(",list(x,y),")"),
2915
+                             list(x = i, y = i+1)))
56186 murdoch 2916
> ## note that both of these use calls rather than expressions.
2917
> ##
61169 ripley 2918
> text(1, 10,  "Derivatives:", adj = 0)
2919
> text(1, 9.6, expression(
2920
+  "             first: {f * minute}(x) " == {f * minute}(x)), adj = 0)
2921
> text(1, 9.0, expression(
2922
+  "     second: {f * second}(x) "        == {f * second}(x)), adj = 0)
56186 murdoch 2923
> 
2924
> 
2925
> plot(1:10, 1:10)
2926
> text(4, 9, expression(hat(beta) == (X^t * X)^{-1} * X^t * y))
2927
> text(4, 8.4, "expression(hat(beta) == (X^t * X)^{-1} * X^t * y)",
2928
+      cex = .8)
2929
> text(4, 7, expression(bar(x) == sum(frac(x[i], n), i==1, n)))
2930
> text(4, 6.4, "expression(bar(x) == sum(frac(x[i], n), i==1, n))",
2931
+      cex = .8)
2932
> text(8, 5, expression(paste(frac(1, sigma*sqrt(2*pi)), " ",
2933
+                             plain(e)^{frac(-(x-mu)^2, 2*sigma^2)})),
2934
+      cex = 1.2)
2935
> 
2936
> ## some other useful symbols
2937
> plot.new(); plot.window(c(0,4), c(15,1))
61169 ripley 2938
> text(1, 1, "universal", adj = 0); text(2.5, 1,  "\\042")
56186 murdoch 2939
> text(3, 1, expression(symbol("\042")))
61169 ripley 2940
> text(1, 2, "existential", adj = 0); text(2.5, 2,  "\\044")
56186 murdoch 2941
> text(3, 2, expression(symbol("\044")))
61169 ripley 2942
> text(1, 3, "suchthat", adj = 0); text(2.5, 3,  "\\047")
56186 murdoch 2943
> text(3, 3, expression(symbol("\047")))
61169 ripley 2944
> text(1, 4, "therefore", adj = 0); text(2.5, 4,  "\\134")
56186 murdoch 2945
> text(3, 4, expression(symbol("\134")))
61169 ripley 2946
> text(1, 5, "perpendicular", adj = 0); text(2.5, 5,  "\\136")
56186 murdoch 2947
> text(3, 5, expression(symbol("\136")))
61169 ripley 2948
> text(1, 6, "circlemultiply", adj = 0); text(2.5, 6,  "\\304")
56186 murdoch 2949
> text(3, 6, expression(symbol("\304")))
61169 ripley 2950
> text(1, 7, "circleplus", adj = 0); text(2.5, 7,  "\\305")
56186 murdoch 2951
> text(3, 7, expression(symbol("\305")))
61169 ripley 2952
> text(1, 8, "emptyset", adj = 0); text(2.5, 8,  "\\306")
56186 murdoch 2953
> text(3, 8, expression(symbol("\306")))
61169 ripley 2954
> text(1, 9, "angle", adj = 0); text(2.5, 9,  "\\320")
56186 murdoch 2955
> text(3, 9, expression(symbol("\320")))
61169 ripley 2956
> text(1, 10, "leftangle", adj = 0); text(2.5, 10,  "\\341")
56186 murdoch 2957
> text(3, 10, expression(symbol("\341")))
61169 ripley 2958
> text(1, 11, "rightangle", adj = 0); text(2.5, 11,  "\\361")
56186 murdoch 2959
> text(3, 11, expression(symbol("\361")))
2960
> 
2961
> 
2962
> 
2963
> cleanEx()
2964
> nameEx("postscriptFonts")
2965
> ### * postscriptFonts
2966
> 
2967
> flush(stderr()); flush(stdout())
2968
> 
2969
> ### Name: postscriptFonts
2970
> ### Title: PostScript and PDF Font Families
2971
> ### Aliases: postscriptFonts pdfFonts
2972
> ### Keywords: device
2973
> 
2974
> ### ** Examples
2975
> 
2976
> postscriptFonts()
2977
$serif
2978
$family
2979
[1] "Times"
2980
 
2981
$metrics
2982
[1] "Times-Roman.afm"      "Times-Bold.afm"       "Times-Italic.afm"    
2983
[4] "Times-BoldItalic.afm" "Symbol.afm"          
2984
 
2985
$encoding
2986
[1] "default"
2987
 
2988
attr(,"class")
2989
[1] "Type1Font"
2990
 
2991
$sans
2992
$family
2993
[1] "Helvetica"
2994
 
2995
$metrics
2996
[1] "Helvetica.afm"             "Helvetica-Bold.afm"       
2997
[3] "Helvetica-Oblique.afm"     "Helvetica-BoldOblique.afm"
2998
[5] "Symbol.afm"               
2999
 
3000
$encoding
3001
[1] "default"
3002
 
3003
attr(,"class")
3004
[1] "Type1Font"
3005
 
3006
$mono
3007
$family
3008
[1] "Courier"
3009
 
3010
$metrics
3011
[1] "Courier.afm"             "Courier-Bold.afm"       
3012
[3] "Courier-Oblique.afm"     "Courier-BoldOblique.afm"
3013
[5] "Symbol.afm"             
3014
 
3015
$encoding
3016
[1] "default"
3017
 
3018
attr(,"class")
3019
[1] "Type1Font"
3020
 
3021
$AvantGarde
3022
$family
3023
[1] "AvantGarde"
3024
 
3025
$metrics
3026
[1] "agw_____.afm" "agd_____.afm" "agwo____.afm" "agdo____.afm" "Symbol.afm"  
3027
 
3028
$encoding
3029
[1] "default"
3030
 
3031
attr(,"class")
3032
[1] "Type1Font"
3033
 
3034
$Bookman
3035
$family
3036
[1] "Bookman"
3037
 
3038
$metrics
3039
[1] "bkl_____.afm" "bkd_____.afm" "bkli____.afm" "bkdi____.afm" "Symbol.afm"  
3040
 
3041
$encoding
3042
[1] "default"
3043
 
3044
attr(,"class")
3045
[1] "Type1Font"
3046
 
3047
$Courier
3048
$family
3049
[1] "Courier"
3050
 
3051
$metrics
3052
[1] "Courier.afm"             "Courier-Bold.afm"       
3053
[3] "Courier-Oblique.afm"     "Courier-BoldOblique.afm"
3054
[5] "Symbol.afm"             
3055
 
3056
$encoding
3057
[1] "default"
3058
 
3059
attr(,"class")
3060
[1] "Type1Font"
3061
 
3062
$Helvetica
3063
$family
3064
[1] "Helvetica"
3065
 
3066
$metrics
3067
[1] "Helvetica.afm"             "Helvetica-Bold.afm"       
3068
[3] "Helvetica-Oblique.afm"     "Helvetica-BoldOblique.afm"
3069
[5] "Symbol.afm"               
3070
 
3071
$encoding
3072
[1] "default"
3073
 
3074
attr(,"class")
3075
[1] "Type1Font"
3076
 
3077
$`Helvetica-Narrow`
3078
$family
3079
[1] "Helvetica-Narrow"
3080
 
3081
$metrics
3082
[1] "hvn_____.afm" "hvnb____.afm" "hvno____.afm" "hvnbo___.afm" "Symbol.afm"  
3083
 
3084
$encoding
3085
[1] "default"
3086
 
3087
attr(,"class")
3088
[1] "Type1Font"
3089
 
3090
$NewCenturySchoolbook
3091
$family
3092
[1] "NewCenturySchoolbook"
3093
 
3094
$metrics
3095
[1] "ncr_____.afm" "ncb_____.afm" "nci_____.afm" "ncbi____.afm" "Symbol.afm"  
3096
 
3097
$encoding
3098
[1] "default"
3099
 
3100
attr(,"class")
3101
[1] "Type1Font"
3102
 
3103
$Palatino
3104
$family
3105
[1] "Palatino"
3106
 
3107
$metrics
3108
[1] "por_____.afm" "pob_____.afm" "poi_____.afm" "pobi____.afm" "Symbol.afm"  
3109
 
3110
$encoding
3111
[1] "default"
3112
 
3113
attr(,"class")
3114
[1] "Type1Font"
3115
 
3116
$Times
3117
$family
3118
[1] "Times"
3119
 
3120
$metrics
3121
[1] "Times-Roman.afm"      "Times-Bold.afm"       "Times-Italic.afm"    
3122
[4] "Times-BoldItalic.afm" "Symbol.afm"          
3123
 
3124
$encoding
3125
[1] "default"
3126
 
3127
attr(,"class")
3128
[1] "Type1Font"
3129
 
3130
$URWGothic
3131
$family
3132
[1] "URWGothic"
3133
 
3134
$metrics
3135
[1] "a010013l.afm" "a010015l.afm" "a010033l.afm" "a010035l.afm" "s050000l.afm"
3136
 
3137
$encoding
3138
[1] "default"
3139
 
3140
attr(,"class")
3141
[1] "Type1Font"
3142
 
3143
$URWBookman
3144
$family
3145
[1] "URWBookman"
3146
 
3147
$metrics
3148
[1] "b018012l.afm" "b018015l.afm" "b018032l.afm" "b018035l.afm" "s050000l.afm"
3149
 
3150
$encoding
3151
[1] "default"
3152
 
3153
attr(,"class")
3154
[1] "Type1Font"
3155
 
3156
$NimbusMon
3157
$family
3158
[1] "NimbusMon"
3159
 
3160
$metrics
3161
[1] "n022003l.afm" "n022004l.afm" "n022023l.afm" "n022024l.afm" "s050000l.afm"
3162
 
3163
$encoding
3164
[1] "default"
3165
 
3166
attr(,"class")
3167
[1] "Type1Font"
3168
 
3169
$NimbusSan
3170
$family
3171
[1] "NimbusSan"
3172
 
3173
$metrics
3174
[1] "n019003l.afm" "n019004l.afm" "n019023l.afm" "n019024l.afm" "s050000l.afm"
3175
 
3176
$encoding
3177
[1] "default"
3178
 
3179
attr(,"class")
3180
[1] "Type1Font"
3181
 
3182
$URWHelvetica
3183
$family
3184
[1] "URWHelvetica"
3185
 
3186
$metrics
3187
[1] "n019003l.afm" "n019004l.afm" "n019023l.afm" "n019024l.afm" "s050000l.afm"
3188
 
3189
$encoding
3190
[1] "default"
3191
 
3192
attr(,"class")
3193
[1] "Type1Font"
3194
 
3195
$NimbusSanCond
3196
$family
3197
[1] "NimbusSanCond"
3198
 
3199
$metrics
3200
[1] "n019043l.afm" "n019044l.afm" "n019063l.afm" "n019064l.afm" "s050000l.afm"
3201
 
3202
$encoding
3203
[1] "default"
3204
 
3205
attr(,"class")
3206
[1] "Type1Font"
3207
 
3208
$CenturySch
3209
$family
3210
[1] "CenturySch"
3211
 
3212
$metrics
3213
[1] "c059013l.afm" "c059016l.afm" "c059033l.afm" "c059036l.afm" "s050000l.afm"
3214
 
3215
$encoding
3216
[1] "default"
3217
 
3218
attr(,"class")
3219
[1] "Type1Font"
3220
 
3221
$URWPalladio
3222
$family
3223
[1] "URWPalladio"
3224
 
3225
$metrics
3226
[1] "p052003l.afm" "p052004l.afm" "p052023l.afm" "p052024l.afm" "s050000l.afm"
3227
 
3228
$encoding
3229
[1] "default"
3230
 
3231
attr(,"class")
3232
[1] "Type1Font"
3233
 
3234
$NimbusRom
3235
$family
3236
[1] "NimbusRom"
3237
 
3238
$metrics
3239
[1] "n021003l.afm" "n021004l.afm" "n021023l.afm" "n021024l.afm" "s050000l.afm"
3240
 
3241
$encoding
3242
[1] "default"
3243
 
3244
attr(,"class")
3245
[1] "Type1Font"
3246
 
3247
$URWTimes
3248
$family
3249
[1] "URWTimes"
3250
 
3251
$metrics
3252
[1] "n021003l.afm" "n021004l.afm" "n021023l.afm" "n021024l.afm" "s050000l.afm"
3253
 
3254
$encoding
3255
[1] "default"
3256
 
3257
attr(,"class")
3258
[1] "Type1Font"
3259
 
63675 ripley 3260
$ArialMT
3261
$family
3262
[1] "ArialMT"
3263
 
3264
$metrics
3265
[1] "ArialMT.afm"            "ArialMT-Bold.afm"       "ArialMT-Italic.afm"    
3266
[4] "ArialMT-BoldItalic.afm" "Symbol.afm"            
3267
 
3268
$encoding
3269
[1] "default"
3270
 
3271
attr(,"class")
3272
[1] "Type1Font"
3273
 
56186 murdoch 3274
$ComputerModern
3275
$family
3276
[1] "ComputerModern"
3277
 
3278
$metrics
3279
[1] "CM_regular_10.afm"      "CM_boldx_10.afm"        "CM_italic_10.afm"      
3280
[4] "CM_boldx_italic_10.afm" "CM_symbol_10.afm"      
3281
 
3282
$encoding
3283
[1] "TeXtext.enc"
3284
 
3285
attr(,"class")
3286
[1] "Type1Font"
3287
 
3288
$ComputerModernItalic
3289
$family
3290
[1] "ComputerModernItalic"
3291
 
3292
$metrics
3293
[1] "CM_regular_10.afm" "CM_boldx_10.afm"   "cmti10.afm"       
3294
[4] "cmbxti10.afm"      "CM_symbol_10.afm" 
3295
 
3296
$encoding
3297
[1] "TeXtext.enc"
3298
 
3299
attr(,"class")
3300
[1] "Type1Font"
3301
 
3302
$Japan1
3303
$family
3304
[1] "HeiseiKakuGo-W5"
3305
 
3306
$metrics
3307
[1] ""           ""           ""           ""           "Symbol.afm"
3308
 
3309
$cmap
3310
[1] "EUC-H"
3311
 
3312
$cmapEncoding
3313
[1] "EUC-JP"
3314
 
3315
$pdfresource
3316
[1] ""
3317
 
3318
attr(,"class")
3319
[1] "CIDFont"
3320
 
3321
$Japan1HeiMin
3322
$family
3323
[1] "HeiseiMin-W3"
3324
 
3325
$metrics
3326
[1] ""           ""           ""           ""           "Symbol.afm"
3327
 
3328
$cmap
3329
[1] "EUC-H"
3330
 
3331
$cmapEncoding
3332
[1] "EUC-JP"
3333
 
3334
$pdfresource
3335
[1] ""
3336
 
3337
attr(,"class")
3338
[1] "CIDFont"
3339
 
3340
$Japan1GothicBBB
3341
$family
3342
[1] "GothicBBB-Medium"
3343
 
3344
$metrics
3345
[1] ""           ""           ""           ""           "Symbol.afm"
3346
 
3347
$cmap
3348
[1] "EUC-H"
3349
 
3350
$cmapEncoding
3351
[1] "EUC-JP"
3352
 
3353
$pdfresource
3354
[1] ""
3355
 
3356
attr(,"class")
3357
[1] "CIDFont"
3358
 
3359
$Japan1Ryumin
3360
$family
3361
[1] "Ryumin-Light"
3362
 
3363
$metrics
3364
[1] ""           ""           ""           ""           "Symbol.afm"
3365
 
3366
$cmap
3367
[1] "EUC-H"
3368
 
3369
$cmapEncoding
3370
[1] "EUC-JP"
3371
 
3372
$pdfresource
3373
[1] ""
3374
 
3375
attr(,"class")
3376
[1] "CIDFont"
3377
 
3378
$Korea1
3379
$family
3380
[1] "Baekmuk-Batang"
3381
 
3382
$metrics
3383
[1] ""           ""           ""           ""           "Symbol.afm"
3384
 
3385
$cmap
3386
[1] "KSCms-UHC-H"
3387
 
3388
$cmapEncoding
3389
[1] "CP949"
3390
 
3391
$pdfresource
3392
[1] ""
3393
 
3394
attr(,"class")
3395
[1] "CIDFont"
3396
 
3397
$Korea1deb
3398
$family
3399
[1] "Batang-Regular"
3400
 
3401
$metrics
3402
[1] ""           ""           ""           ""           "Symbol.afm"
3403
 
3404
$cmap
3405
[1] "KSCms-UHC-H"
3406
 
3407
$cmapEncoding
3408
[1] "CP949"
3409
 
3410
$pdfresource
3411
[1] ""
3412
 
3413
attr(,"class")
3414
[1] "CIDFont"
3415
 
3416
$CNS1
3417
$family
3418
[1] "MOESung-Regular"
3419
 
3420
$metrics
3421
[1] ""           ""           ""           ""           "Symbol.afm"
3422
 
3423
$cmap
3424
[1] "B5pc-H"
3425
 
3426
$cmapEncoding
3427
[1] "CP950"
3428
 
3429
$pdfresource
3430
[1] ""
3431
 
3432
attr(,"class")
3433
[1] "CIDFont"
3434
 
3435
$GB1
3436
$family
3437
[1] "BousungEG-Light-GB"
3438
 
3439
$metrics
3440
[1] ""           ""           ""           ""           "Symbol.afm"
3441
 
3442
$cmap
3443
[1] "GBK-EUC-H"
3444
 
3445
$cmapEncoding
3446
[1] "GBK"
3447
 
3448
$pdfresource
3449
[1] ""
3450
 
3451
attr(,"class")
3452
[1] "CIDFont"
3453
 
3454
> ## This duplicates "ComputerModernItalic".
3455
> CMitalic <- Type1Font("ComputerModern2",
3456
+                       c("CM_regular_10.afm", "CM_boldx_10.afm",
3457
+                         "cmti10.afm", "cmbxti10.afm",
3458
+                          "CM_symbol_10.afm"),
3459
+                       encoding = "TeXtext.enc")
3460
> postscriptFonts(CMitalic = CMitalic)
3461
> 
3462
> ## A CID font for Japanese using a different CMap and
3463
> ## corresponding cmapEncoding.
3464
> `Jp_UCS-2` <- CIDFont("TestUCS2",
3465
+                   c("Adobe-Japan1-UniJIS-UCS2-H.afm",
3466
+                     "Adobe-Japan1-UniJIS-UCS2-H.afm",
3467
+                     "Adobe-Japan1-UniJIS-UCS2-H.afm",
3468
+                     "Adobe-Japan1-UniJIS-UCS2-H.afm"),
3469
+                   "UniJIS-UCS2-H", "UCS-2")
3470
> pdfFonts(`Jp_UCS-2` = `Jp_UCS-2`)
3471
> names(pdfFonts())
3472
 [1] "serif"                "sans"                 "mono"                
3473
 [4] "AvantGarde"           "Bookman"              "Courier"             
3474
 [7] "Helvetica"            "Helvetica-Narrow"     "NewCenturySchoolbook"
3475
[10] "Palatino"             "Times"                "URWGothic"           
3476
[13] "URWBookman"           "NimbusMon"            "NimbusSan"           
3477
[16] "URWHelvetica"         "NimbusSanCond"        "CenturySch"          
3478
[19] "URWPalladio"          "NimbusRom"            "URWTimes"            
63675 ripley 3479
[22] "ArialMT"              "Japan1"               "Japan1HeiMin"        
3480
[25] "Japan1GothicBBB"      "Japan1Ryumin"         "Korea1"              
3481
[28] "Korea1deb"            "CNS1"                 "GB1"                 
3482
[31] "Jp_UCS-2"            
56186 murdoch 3483
> 
3484
> 
3485
> 
3486
> cleanEx()
3487
> nameEx("pretty.Date")
3488
> ### * pretty.Date
3489
> 
3490
> flush(stderr()); flush(stdout())
3491
> 
3492
> ### Name: pretty.Date
3493
> ### Title: Pretty Breakpoints for Date-Time Classes
70448 maechler 3494
> ### Aliases: pretty.Date pretty.POSIXt
56186 murdoch 3495
> ### Keywords: dplot
3496
> 
3497
> ### ** Examples
3498
> 
70467 maechler 3499
> pretty(as.Date("2000-03-01")) # R 1.0.0 came in a leap year
3500
[1] "2000-02-28" "2000-02-29" "2000-03-01" "2000-03-02" "2000-03-03"
3501
[6] "2000-03-04"
56186 murdoch 3502
> 
70467 maechler 3503
> ## time ranges in diverse scales:% also in ../../../../tests/reg-tests-1c.R
3504
> require(stats)
3505
> steps <- setNames(,
3506
+     c("10 secs", "1 min", "5 mins", "30 mins", "6 hours", "12 hours",
3507
+       "1 DSTday", "2 weeks", "1 month", "6 months", "1 year",
3508
+       "10 years", "50 years", "1000 years"))
56186 murdoch 3509
> x <- as.POSIXct("2002-02-02 02:02")
3510
> lapply(steps,
3511
+        function(s) {
3512
+            at <- pretty(seq(x, by = s, length = 2), n = 5)
3513
+            attr(at, "labels")
3514
+        })
70467 maechler 3515
$`10 secs`
56186 murdoch 3516
[1] "00" "02" "04" "06" "08" "10"
3517
 
70467 maechler 3518
$`1 min`
56186 murdoch 3519
[1] "00" "10" "20" "30" "40" "50" "00"
3520
 
70467 maechler 3521
$`5 mins`
56186 murdoch 3522
[1] "02:02" "02:03" "02:04" "02:05" "02:06" "02:07"
3523
 
70467 maechler 3524
$`30 mins`
3525
[1] "02:00" "02:10" "02:20" "02:30" "02:40"
56186 murdoch 3526
 
70467 maechler 3527
$`6 hours`
3528
[1] "02:00" "03:00" "04:00" "05:00" "06:00" "07:00" "08:00" "09:00"
56186 murdoch 3529
 
70467 maechler 3530
$`12 hours`
3531
[1] "00:00" "03:00" "06:00" "09:00" "12:00" "15:00"
56186 murdoch 3532
 
70467 maechler 3533
$`1 DSTday`
3534
[1] "Feb 02 00:00" "Feb 02 06:00" "Feb 02 12:00" "Feb 02 18:00" "Feb 03 00:00"
3535
[6] "Feb 03 06:00"
56186 murdoch 3536
 
70467 maechler 3537
$`2 weeks`
3538
[1] "Jan 28" "Feb 04" "Feb 11" "Feb 18"
56186 murdoch 3539
 
70467 maechler 3540
$`1 month`
3541
[1] "Jan 28" "Feb 04" "Feb 11" "Feb 18" "Feb 25" "Mar 04"
56186 murdoch 3542
 
70467 maechler 3543
$`6 months`
3544
[1] "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep"
56186 murdoch 3545
 
70467 maechler 3546
$`1 year`
3547
[1] "Jan" "Apr" "Jul" "Oct" "Jan" "Apr"
56186 murdoch 3548
 
70467 maechler 3549
$`10 years`
3550
[1] "2002" "2004" "2006" "2008" "2010" "2012" "2014"
56186 murdoch 3551
 
70467 maechler 3552
$`50 years`
3553
[1] "2000" "2010" "2020" "2030" "2040" "2050" "2060"
56186 murdoch 3554
 
70467 maechler 3555
$`1000 years`
3556
[1] "2000" "2200" "2400" "2600" "2800" "3000" "3200"
56186 murdoch 3557
 
3558
> 
3559
> 
3560
> 
3561
> cleanEx()
3562
> nameEx("ps.options")
3563
> ### * ps.options
3564
> 
3565
> flush(stderr()); flush(stdout())
3566
> 
3567
> ### Name: ps.options
3568
> ### Title: Auxiliary Function to Set/View Defaults for Arguments of
3569
> ###   postscript
3570
> ### Aliases: ps.options setEPS setPS
3571
> ### Keywords: device
3572
> 
3573
> ### ** Examples
3574
> 
3575
> ps.options(bg = "pink")
3576
> utils::str(ps.options())
3577
List of 18
3578
 $ onefile    : logi TRUE
3579
 $ family     : chr "Helvetica"
3580
 $ title      : chr "R Graphics Output"
3581
 $ fonts      : NULL
3582
 $ encoding   : chr "default"
3583
 $ bg         : chr "pink"
3584
 $ fg         : chr "black"
56942 ripley 3585
 $ width      : num 0
3586
 $ height     : num 0
56186 murdoch 3587
 $ horizontal : logi TRUE
3588
 $ pointsize  : num 12
56942 ripley 3589
 $ paper      : chr "default"
56186 murdoch 3590
 $ pagecentre : logi TRUE
3591
 $ print.it   : logi FALSE
3592
 $ command    : chr "default"
56943 ripley 3593
 $ colormodel : chr "srgb"
56186 murdoch 3594
 $ useKerning : logi TRUE
3595
 $ fillOddEven: logi FALSE
3596
> 
3597
> ### ---- error checking of arguments: ----
61157 ripley 3598
> ps.options(width = 0:12, onefile = 0, bg = pi)
56186 murdoch 3599
Warning: ‘mode(onefile)’ and ‘mode(bg)’ differ between new and previous
3600
	 ==> NOT changing ‘onefile’ & ‘bg’
3601
Warning: ‘length(width)’ differs between new and previous
3602
	 ==> NOT changing ‘width’
3603
> # override the check for 'width', but not 'bg':
61157 ripley 3604
> ps.options(width = 0:12, bg = pi, override.check = c(TRUE,FALSE))
56186 murdoch 3605
Warning: ‘mode(bg)’ differs between new and previous
3606
	 ==> NOT changing ‘bg’
3607
Warning: ‘length(width)’ differs between new and previous
3608
> utils::str(ps.options())
3609
List of 18
3610
 $ onefile    : logi TRUE
3611
 $ family     : chr "Helvetica"
3612
 $ title      : chr "R Graphics Output"
3613
 $ fonts      : NULL
3614
 $ encoding   : chr "default"
3615
 $ bg         : chr "pink"
3616
 $ fg         : chr "black"
3617
 $ width      : int [1:13] 0 1 2 3 4 5 6 7 8 9 ...
56942 ripley 3618
 $ height     : num 0
56186 murdoch 3619
 $ horizontal : logi TRUE
3620
 $ pointsize  : num 12
56942 ripley 3621
 $ paper      : chr "default"
56186 murdoch 3622
 $ pagecentre : logi TRUE
3623
 $ print.it   : logi FALSE
3624
 $ command    : chr "default"
56943 ripley 3625
 $ colormodel : chr "srgb"
56186 murdoch 3626
 $ useKerning : logi TRUE
3627
 $ fillOddEven: logi FALSE
3628
> ps.options(reset = TRUE) # back to factory-fresh
3629
> 
3630
> 
3631
> 
3632
> cleanEx()
75104 maechler 3633
> nameEx("quartz")
3634
> ### * quartz
3635
> 
3636
> flush(stderr()); flush(stdout())
3637
> 
3638
> ### Name: quartz
3639
> ### Title: macOS Quartz Device
3640
> ### Aliases: quartz quartz.options quartz.save
3641
> ### Keywords: device
3642
> 
3643
> ### ** Examples
3644
> ## Not run: 
3645
> ##D ## Only on a Mac,
3646
> ##D ## put something like this is your .Rprofile to customize the defaults
3647
> ##D setHook(packageEvent("grDevices", "onLoad"),
3648
> ##D         function(...) grDevices::quartz.options(width = 8, height = 6,
3649
> ##D                                                 pointsize = 10))
3650
> ## End(Not run)
3651
> 
3652
> 
3653
> cleanEx()
3654
> nameEx("quartzFonts")
3655
> ### * quartzFonts
3656
> 
3657
> flush(stderr()); flush(stdout())
3658
> 
3659
> ### Name: quartzFonts
3660
> ### Title: Quartz Fonts Setup
3661
> ### Aliases: quartzFont quartzFonts
3662
> ### Keywords: device
3663
> 
3664
> ### ** Examples
3665
> 
3666
> if(.Platform$OS.type == "unix") { # includes Mac
3667
+ 
3668
+  utils::str( quartzFonts() ) # a list(serif = .., sans = .., mono = ..)
3669
+  quartzFonts("mono") # the list(mono = ..) sublist of quartzFonts()
3670
+ ## Not run: 
3671
+ ##D   ## for East Asian locales you can use something like
3672
+ ##D   quartzFonts(sans = quartzFont(rep("AppleGothic", 4)),
3673
+ ##D 	      serif = quartzFont(rep("AppleMyungjp", 4)))
3674
+ ##D   ## since the default fonts may well not have the glyphs needed
3675
+ ## End(Not run)
3676
+ }
3677
List of 3
3678
 $ serif: chr [1:4] "Times-Roman" "Times-Bold" "Times-Italic" "Times-BoldItalic"
3679
 $ sans : chr [1:4] "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
3680
 $ mono : chr [1:4] "Courier" "Courier-Bold" "Courier-Oblique" "Courier-BoldOblique"
3681
$mono
3682
[1] "Courier"             "Courier-Bold"        "Courier-Oblique"    
3683
[4] "Courier-BoldOblique"
3684
 
3685
> 
3686
> 
3687
> 
3688
> cleanEx()
56186 murdoch 3689
> nameEx("recordGraphics")
3690
> ### * recordGraphics
3691
> 
3692
> flush(stderr()); flush(stdout())
3693
> 
3694
> ### Name: recordGraphics
3695
> ### Title: Record Graphics Operations
3696
> ### Aliases: recordGraphics
3697
> ### Keywords: device
3698
> 
3699
> ### ** Examples
3700
> 
3701
> require(graphics)
3702
> 
3703
> plot(1:10)
3704
> # This rectangle remains 1inch wide when the device is resized
3705
> recordGraphics(
3706
+   {
3707
+     rect(4, 2,
3708
+          4 + diff(par("usr")[1:2])/par("pin")[1], 3)
3709
+   },
3710
+   list(),
3711
+   getNamespace("graphics"))
3712
> 
3713
> 
3714
> 
3715
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
3716
> cleanEx()
3717
> nameEx("rgb")
3718
> ### * rgb
3719
> 
3720
> flush(stderr()); flush(stdout())
3721
> 
3722
> ### Name: rgb
3723
> ### Title: RGB Color Specification
3724
> ### Aliases: rgb
3725
> ### Keywords: color
3726
> 
3727
> ### ** Examples
3728
> 
61169 ripley 3729
> rgb(0, 1, 0)
56186 murdoch 3730
[1] "#00FF00"
3731
> 
61157 ripley 3732
> rgb((0:15)/15, green = 0, blue = 0, names = paste("red", 0:15, sep = "."))
56186 murdoch 3733
    red.0     red.1     red.2     red.3     red.4     red.5     red.6     red.7 
3734
"#000000" "#110000" "#220000" "#330000" "#440000" "#550000" "#660000" "#770000" 
3735
    red.8     red.9    red.10    red.11    red.12    red.13    red.14    red.15 
3736
"#880000" "#990000" "#AA0000" "#BB0000" "#CC0000" "#DD0000" "#EE0000" "#FF0000" 
3737
> 
61169 ripley 3738
> rgb(0, 0:12, 0, max = 255) # integer input
56186 murdoch 3739
 [1] "#000000" "#000100" "#000200" "#000300" "#000400" "#000500" "#000600"
3740
 [8] "#000700" "#000800" "#000900" "#000A00" "#000B00" "#000C00"
3741
> 
3742
> ramp <- colorRamp(c("red", "white"))
3743
> rgb( ramp(seq(0, 1, length = 5)), max = 255)
3744
[1] "#FF0000" "#FF3F3F" "#FF7F7F" "#FFBFBF" "#FFFFFF"
3745
> 
3746
> 
3747
> 
3748
> cleanEx()
3749
> nameEx("rgb2hsv")
3750
> ### * rgb2hsv
3751
> 
3752
> flush(stderr()); flush(stdout())
3753
> 
3754
> ### Name: rgb2hsv
3755
> ### Title: RGB to HSV Conversion
3756
> ### Aliases: rgb2hsv
3757
> ### Keywords: color dplot
3758
> 
3759
> ### ** Examples
3760
> 
3761
> ## These (saturated, bright ones) only differ by hue
3762
> (rc <- col2rgb(c("red", "yellow","green","cyan", "blue", "magenta")))
3763
      [,1] [,2] [,3] [,4] [,5] [,6]
3764
red    255  255    0    0    0  255
3765
green    0  255  255  255    0    0
3766
blue     0    0    0  255  255  255
3767
> (hc <- rgb2hsv(rc))
3768
  [,1]      [,2]      [,3] [,4]      [,5]      [,6]
3769
h    0 0.1666667 0.3333333  0.5 0.6666667 0.8333333
3770
s    1 1.0000000 1.0000000  1.0 1.0000000 1.0000000
3771
v    1 1.0000000 1.0000000  1.0 1.0000000 1.0000000
3772
> 6 * hc["h",] # the hues are equispaced
3773
[1] 0 1 2 3 4 5
3774
> 
3775
> ## Don't show: 
3776
> set.seed(151)
66943 maechler 3777
> ## End(Don't show)
61169 ripley 3778
> (rgb3 <- floor(256 * matrix(stats::runif(3*12), 3, 12)))
56186 murdoch 3779
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
3780
[1,]  122  137  116  244   20  153  191  250  134   117    27   202
3781
[2,]  221  113  210  200  218  151   64  182  195   103   218   254
3782
[3,]  199  157   88   76   39   91   80  146   22   105    17   239
3783
> (hsv3 <- rgb2hsv(rgb3))
3784
       [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
3785
h 0.4629630 0.7575758 0.2950820 0.1230159 0.3493266 0.1612903 0.9790026
3786
s 0.4479638 0.2802548 0.5809524 0.6885246 0.9082569 0.4052288 0.6649215
3787
v 0.8666667 0.6156863 0.8235294 0.9568627 0.8549020 0.6000000 0.7490196
3788
        [,8]      [,9]     [,10]     [,11]     [,12]
3789
h 0.05769231 0.2254335 0.9761905 0.3250415 0.4519231
3790
s 0.41600000 0.8871795 0.1196581 0.9220183 0.2047244
3791
v 0.98039216 0.7647059 0.4588235 0.8549020 0.9960784
3792
> ## Consistency :
61157 ripley 3793
> stopifnot(rgb3 == col2rgb(hsv(h = hsv3[1,], s = hsv3[2,], v = hsv3[3,])),
56186 murdoch 3794
+           all.equal(hsv3, rgb2hsv(rgb3/255, maxColorValue = 1)))
3795
> 
3796
> ## A (simplified) pure R version -- originally by Wolfram Fischer --
3797
> ## showing the exact algorithm:
3798
> rgb2hsvR <- function(rgb, gamma = 1, maxColorValue = 255)
3799
+ {
3800
+     if(!is.numeric(rgb)) stop("rgb matrix must be numeric")
3801
+     d <- dim(rgb)
3802
+     if(d[1] != 3) stop("rgb matrix must have 3 rows")
3803
+     n <- d[2]
61169 ripley 3804
+     if(n == 0) return(cbind(c(h = 1, s = 1, v = 1))[,0])
56186 murdoch 3805
+     rgb <- rgb/maxColorValue
3806
+     if(gamma != 1) rgb <- rgb ^ (1/gamma)
3807
+ 
3808
+     ## get the max and min
3809
+     v <- apply( rgb, 2, max)
3810
+     s <- apply( rgb, 2, min)
3811
+     D <- v - s # range
3812
+ 
3813
+     ## set hue to zero for undefined values (gray has no hue)
3814
+     h <- numeric(n)
3815
+     notgray <- ( s != v )
3816
+ 
3817
+     ## blue hue
3818
+     idx <- (v == rgb[3,] & notgray )
3819
+     if (any (idx))
3820
+         h[idx] <- 2/3 + 1/6 * (rgb[1,idx] - rgb[2,idx]) / D[idx]
3821
+     ## green hue
3822
+     idx <- (v == rgb[2,] & notgray )
3823
+     if (any (idx))
3824
+         h[idx] <- 1/3 + 1/6 * (rgb[3,idx] - rgb[1,idx]) / D[idx]
3825
+     ## red hue
3826
+     idx <- (v == rgb[1,] & notgray )
3827
+     if (any (idx))
3828
+         h[idx] <-       1/6 * (rgb[2,idx] - rgb[3,idx]) / D[idx]
3829
+ 
3830
+     ## correct for negative red
3831
+     idx <- (h < 0)
3832
+     h[idx] <- 1+h[idx]
3833
+ 
3834
+     ## set the saturation
3835
+     s[! notgray] <- 0;
3836
+     s[notgray] <- 1 - s[notgray] / v[notgray]
3837
+ 
61157 ripley 3838
+     rbind( h = h, s = s, v = v )
56186 murdoch 3839
+ }
3840
> 
3841
> ## confirm the equivalence:
3842
> all.equal(rgb2hsv (rgb3),
64891 ripley 3843
+           rgb2hsvR(rgb3), tolerance = 1e-14) # TRUE
56186 murdoch 3844
[1] TRUE
3845
> 
3846
> 
3847
> 
3848
> cleanEx()
3849
> nameEx("trans3d")
3850
> ### * trans3d
3851
> 
3852
> flush(stderr()); flush(stdout())
3853
> 
3854
> ### Name: trans3d
3855
> ### Title: 3D to 2D Transformation for Perspective Plots
3856
> ### Aliases: trans3d
3857
> ### Keywords: dplot
3858
> 
3859
> ### ** Examples
3860
> 
3861
> ## See  help(persp) {after attaching the 'graphics' package}
3862
> ##      -----------
3863
> 
3864
> 
3865
> 
3866
> cleanEx()
75104 maechler 3867
> nameEx("windows")
3868
> ### * windows
3869
> 
3870
> flush(stderr()); flush(stdout())
3871
> 
3872
> ### Name: windows
3873
> ### Title: Windows Graphics Devices
3874
> ### Aliases: windows win.graph win.metafile win.print print.SavedPlots
3875
> ###   [.SavedPlots
3876
> ### Keywords: device
3877
> 
3878
> ### ** Examples
3879
> ## Not run: 
3880
> ##D ## A series of plots written to a sequence of metafiles
3881
> ##D if(.Platform$OS.type == "windows")
3882
> ##D    win.metafile("Rplot%02d.wmf", pointsize = 10)
3883
> ## End(Not run)
3884
> 
3885
> 
3886
> cleanEx()
3887
> nameEx("windows.options")
3888
> ### * windows.options
3889
> 
3890
> flush(stderr()); flush(stdout())
3891
> 
3892
> ### Name: windows.options
3893
> ### Title: Auxiliary Function to Set/View Defaults for Arguments of
3894
> ###   windows()
3895
> ### Aliases: windows.options
3896
> ### Keywords: device
3897
> 
3898
> ### ** Examples
3899
> ## Not run: 
3900
> ##D ## put something like this is your .Rprofile to customize the defaults
3901
> ##D setHook(packageEvent("grDevices", "onLoad"),
3902
> ##D         function(...)
3903
> ##D             grDevices::windows.options(width = 8, height = 6,
3904
> ##D                                        xpos = 0, pointsize = 10,
3905
> ##D                                        bitmap.aa.win = "cleartype"))
3906
> ## End(Not run)
3907
> 
3908
> 
3909
> cleanEx()
3910
> nameEx("windowsFonts")
3911
> ### * windowsFonts
3912
> 
3913
> flush(stderr()); flush(stdout())
3914
> 
3915
> ### Name: windowsFonts
3916
> ### Title: Windows Fonts
3917
> ### Aliases: windowsFont windowsFonts
3918
> ### Keywords: device
3919
> 
3920
> ### ** Examples
3921
> 
3922
> if(.Platform$OS.type == "windows") withAutoprint({
3923
+   windowsFonts()
3924
+   windowsFonts("mono")
3925
+ })
3926
> ## Not run: 
3927
> ##D ## set up for Japanese: needs the fonts installed
3928
> ##D windows()  # make sure we have the right device type (available on Windows only)
3929
> ##D Sys.setlocale("LC_ALL", "ja")
3930
> ##D windowsFonts(JP1 = windowsFont("MS Mincho"),
3931
> ##D              JP2 = windowsFont("MS Gothic"),
3932
> ##D              JP3 = windowsFont("Arial Unicode MS"))
3933
> ##D plot(1:10)
3934
> ##D text(5, 2, "\u{4E10}\u{4E00}\u{4E01}", family = "JP1")
3935
> ##D text(7, 2, "\u{4E10}\u{4E00}\u{4E01}", family = "JP1", font = 2)
3936
> ##D text(5, 1.5, "\u{4E10}\u{4E00}\u{4E01}", family = "JP2")
3937
> ##D text(9, 2, "\u{5100}", family = "JP3")
3938
> ## End(Not run)
3939
> 
3940
> 
3941
> cleanEx()
3942
> nameEx("x11")
3943
> ### * x11
3944
> 
3945
> flush(stderr()); flush(stdout())
3946
> 
3947
> ### Name: x11
3948
> ### Title: X Window System Graphics (X11)
3949
> ### Aliases: x11 X11 X11.options
3950
> ### Keywords: device
3951
> 
3952
> ### ** Examples
3953
> ## Not run: 
3954
> ##D if(.Platform$OS.type == "unix") { # Only on unix-alikes, possibly Mac,
3955
> ##D ## put something like this is your .Rprofile to customize the defaults
3956
> ##D setHook(packageEvent("grDevices", "onLoad"),
3957
> ##D         function(...) grDevices::X11.options(width = 8, height = 6, xpos = 0,
3958
> ##D                                              pointsize = 10))
3959
> ##D }
3960
> ## End(Not run)
3961
> 
3962
> 
3963
> cleanEx()
3964
> nameEx("x11Fonts")
3965
> ### * x11Fonts
3966
> 
3967
> flush(stderr()); flush(stdout())
3968
> 
3969
> ### Name: X11Fonts
3970
> ### Title: X11 Fonts
3971
> ### Aliases: X11Font X11Fonts
3972
> ### Keywords: device
3973
> 
3974
> ### ** Examples
3975
> 
75266 ripley 3976
> ## IGNORE_RDIFF_BEGIN
75124 ripley 3977
> if(capabilities()[["X11"]]) withAutoprint({
3978
+ X11Fonts()
3979
+ X11Fonts("mono")
3980
+ utopia <- X11Font("-*-utopia-*-*-*-*-*-*-*-*-*-*-*-*")
3981
+ X11Fonts(utopia = utopia)
3982
+ })
77438 murrell 3983
> X11Fonts()
3984
$serif
3985
[1] "-*-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"
3986
 
3987
$sans
3988
[1] "-*-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
3989
 
3990
$mono
3991
[1] "-*-courier-%s-%s-*-*-%d-*-*-*-*-*-*-*"
3992
 
3993
$Times
3994
[1] "-adobe-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"
3995
 
3996
$Helvetica
3997
[1] "-adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
3998
 
3999
$CyrTimes
4000
[1] "-cronyx-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"
4001
 
4002
$CyrHelvetica
4003
[1] "-cronyx-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
4004
 
4005
$Arial
4006
[1] "-monotype-arial-%s-%s-*-*-%d-*-*-*-*-*-*-*"
4007
 
4008
$Mincho
4009
[1] "-*-mincho-%s-%s-*-*-%d-*-*-*-*-*-*-*"
4010
 
4011
> X11Fonts("mono")
4012
$mono
4013
[1] "-*-courier-%s-%s-*-*-%d-*-*-*-*-*-*-*"
4014
 
4015
> utopia <- X11Font("-*-utopia-*-*-*-*-*-*-*-*-*-*-*-*")
4016
> X11Fonts(utopia = utopia)
75266 ripley 4017
> ## IGNORE_RDIFF_END
75104 maechler 4018
> 
4019
> 
4020
> 
4021
> cleanEx()
56186 murdoch 4022
> nameEx("xy.coords")
4023
> ### * xy.coords
4024
> 
4025
> flush(stderr()); flush(stdout())
4026
> 
4027
> ### Name: xy.coords
4028
> ### Title: Extracting Plotting Structures
4029
> ### Aliases: xy.coords
4030
> ### Keywords: dplot
4031
> 
4032
> ### ** Examples
4033
> 
70533 maechler 4034
> ff <- stats::fft(1:9)
4035
> xy.coords(ff)
56186 murdoch 4036
$x
4037
[1] 45.0 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5
4038
 
4039
$y
4040
[1]   0.0000000  12.3636484   5.3628912   2.5980762   0.7934714  -0.7934714
4041
[7]  -2.5980762  -5.3628912 -12.3636484
4042
 
4043
$xlab
4044
[1] "Re()"
4045
 
4046
$ylab
4047
[1] "Im()"
4048
 
70533 maechler 4049
> xy.coords(ff, xlab = "fft") # labels "Re(fft)",  "Im(fft)"
4050
$x
4051
[1] 45.0 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5
4052
 
4053
$y
4054
[1]   0.0000000  12.3636484   5.3628912   2.5980762   0.7934714  -0.7934714
4055
[7]  -2.5980762  -5.3628912 -12.3636484
4056
 
4057
$xlab
4058
[1] "Re(fft)"
4059
 
4060
$ylab
4061
[1] "Im(fft)"
4062
 
4063
> ## Don't show: 
4064
> stopifnot(identical(xy.coords(ff, xlab = "fft"),
4065
+                     xy.coords(ff, ylab = "fft")))
4066
> xy.labs <- function(...) xy.coords(...)[c("xlab","ylab")]
4067
> stopifnot(identical(xy.labs(ff, xlab = "fft", setLab = FALSE),
4068
+                     list(xlab = "fft", ylab = "fft")),
4069
+           identical(xy.labs(ff, ylab = "fft", setLab = FALSE),
4070
+                     list(xlab = NULL, ylab = "fft")),
4071
+           identical(xy.labs(ff, xlab = "Re(fft)", ylab = "Im(fft)", setLab = FALSE),
4072
+                     list(xlab = "Re(fft)", ylab = "Im(fft)")))
4073
> ## End(Don't show)
56186 murdoch 4074
> with(cars, xy.coords(dist ~ speed, NULL)$xlab ) # = "speed"
4075
[1] "speed"
4076
> 
70533 maechler 4077
> xy.coords(1:3, 1:2, recycle = TRUE) # otherwise error "lengths differ"
56186 murdoch 4078
$x
4079
[1] 1 2 3
4080
 
4081
$y
4082
[1] 1 2 1
4083
 
4084
$xlab
4085
NULL
4086
 
4087
$ylab
4088
NULL
4089
 
70533 maechler 4090
> xy.coords(-2:10, log = "y")
4091
Warning in xy.coords(-2:10, log = "y") :
56186 murdoch 4092
  3 y values <= 0 omitted from logarithmic plot
4093
$x
4094
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13
4095
 
4096
$y
4097
 [1] NA NA NA  1  2  3  4  5  6  7  8  9 10
4098
 
4099
$xlab
4100
[1] "Index"
4101
 
4102
$ylab
4103
NULL
4104
 
70533 maechler 4105
> ##> xlab: "Index"  \\  warning: 3 y values <= 0 omitted ..
56186 murdoch 4106
> 
4107
> 
4108
> 
4109
> cleanEx()
4110
> nameEx("xyTable")
4111
> ### * xyTable
4112
> 
4113
> flush(stderr()); flush(stdout())
4114
> 
4115
> ### Name: xyTable
4116
> ### Title: Multiplicities of (x,y) Points, e.g., for a Sunflower Plot
4117
> ### Aliases: xyTable
4118
> ### Keywords: dplot
4119
> 
4120
> ### ** Examples
4121
> 
61169 ripley 4122
> xyTable(iris[, 3:4], digits = 6)
56186 murdoch 4123
$x
4124
  [1] 1.0 1.1 1.2 1.3 1.3 1.3 1.4 1.4 1.4 1.5 1.5 1.5 1.5 1.6 1.6 1.6 1.7 1.7
4125
 [19] 1.7 1.7 1.9 1.9 3.0 3.3 3.5 3.6 3.7 3.8 3.9 3.9 3.9 4.0 4.0 4.0 4.1 4.1
4126
 [37] 4.2 4.2 4.2 4.3 4.4 4.4 4.4 4.5 4.5 4.5 4.5 4.6 4.6 4.6 4.7 4.7 4.7 4.7
4127
 [55] 4.8 4.8 4.9 4.9 4.9 5.0 5.0 5.0 5.0 5.1 5.1 5.1 5.1 5.1 5.1 5.1 5.2 5.2
4128
 [73] 5.3 5.3 5.4 5.4 5.5 5.5 5.6 5.6 5.6 5.6 5.6 5.7 5.7 5.7 5.8 5.8 5.8 5.9
4129
 [91] 5.9 6.0 6.0 6.1 6.1 6.1 6.3 6.4 6.6 6.7 6.7 6.9
4130
 
4131
$y
4132
  [1] 0.2 0.1 0.2 0.2 0.3 0.4 0.1 0.2 0.3 0.1 0.2 0.3 0.4 0.2 0.4 0.6 0.2 0.3
4133
 [19] 0.4 0.5 0.2 0.4 1.1 1.0 1.0 1.3 1.0 1.1 1.1 1.2 1.4 1.0 1.2 1.3 1.0 1.3
4134
 [37] 1.2 1.3 1.5 1.3 1.2 1.3 1.4 1.3 1.5 1.6 1.7 1.3 1.4 1.5 1.2 1.4 1.5 1.6
4135
 [55] 1.4 1.8 1.5 1.8 2.0 1.5 1.7 1.9 2.0 1.5 1.6 1.8 1.9 2.0 2.3 2.4 2.0 2.3
4136
 [73] 1.9 2.3 2.1 2.3 1.8 2.1 1.4 1.8 2.1 2.2 2.4 2.1 2.3 2.5 1.6 1.8 2.2 2.1
4137
 [91] 2.3 1.8 2.5 1.9 2.3 2.5 1.8 2.0 2.1 2.0 2.2 2.3
4138
 
4139
$number
4140
  [1] 1 1 2 4 2 1 2 8 3 2 7 1 3 5 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 3 1 2 1
4141
 [38] 2 1 2 1 1 2 1 5 1 1 1 1 1 1 2 1 1 1 3 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1
4142
 [75] 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
4143
 
4144
> 
4145
> ## Discretized uncorrelated Gaussian:
4146
> ## Don't show: 
4147
> set.seed(1)
66943 maechler 4148
> ## End(Don't show)
56186 murdoch 4149
> require(stats)
4150
> xy <- data.frame(x = round(sort(rnorm(100))), y = rnorm(100))
4151
> xyTable(xy, digits = 1)
4152
$x
4153
 [1] -2 -2 -2 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1  0  0  0  0  0  0  0  0
4154
[26]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  1  1  1  1  1  1  1  1  1  1  1
4155
[51]  1  1  1  1  1  1  2  2  2  2
4156
 
4157
$y
4158
 [1] -0.90 -0.60  0.04  0.20 -0.70 -0.60 -0.50 -0.40 -0.30 -0.20 -0.10  0.40
4159
[13]  0.50  0.70  0.90  1.00  2.00 -2.00 -1.00 -0.90 -0.80 -0.70 -0.60 -0.50
4160
[25] -0.30 -0.20 -0.07 -0.06 -0.04 -0.02  0.02  0.06  0.30  0.40  0.50  0.70
4161
[37]  0.90  1.00  2.00 -1.00 -0.90 -0.80 -0.70 -0.40 -0.30 -0.20 -0.10 -0.08
4162
[49] -0.03  0.10  0.20  0.40  0.50  0.80  1.00  2.00 -1.00 -0.40  0.40  1.00
4163
 
4164
$number
4165
 [1] 1 1 1 1 2 1 2 1 2 4 1 1 1 1 1 2 2 5 5 1 1 2 3 2 3 1 1 1 1 1 1 1 1 1 2 1 1 3
4166
[39] 3 3 1 1 1 1 2 2 1 1 1 1 2 1 2 2 4 2 3 1 1 1
4167
 
4168
> 
4169
> 
4170
> 
4171
> cleanEx()
4172
> nameEx("xyz.coords")
4173
> ### * xyz.coords
4174
> 
4175
> flush(stderr()); flush(stdout())
4176
> 
4177
> ### Name: xyz.coords
4178
> ### Title: Extracting Plotting Structures
4179
> ### Aliases: xyz.coords
4180
> ### Keywords: dplot
4181
> 
4182
> ### ** Examples
4183
> 
4184
> xyz.coords(data.frame(10*1:9, -4), y = NULL, z = NULL)
4185
$x
4186
[1] 1 2 3 4 5 6 7 8 9
4187
 
4188
$y
4189
[1] 10 20 30 40 50 60 70 80 90
4190
 
4191
$z
4192
[1] -4 -4 -4 -4 -4 -4 -4 -4 -4
4193
 
4194
$xlab
4195
[1] "Index"
4196
 
4197
$ylab
4198
NULL
4199
 
4200
$zlab
4201
NULL
4202
 
4203
> 
4204
> xyz.coords(1:5, stats::fft(1:5), z = NULL, xlab = "X", ylab = "Y")
4205
$x
4206
[1] 15.0 -2.5 -2.5 -2.5 -2.5
4207
 
4208
$y
4209
[1]  0.0000000  3.4409548  0.8122992 -0.8122992 -3.4409548
4210
 
4211
$z
4212
[1] 1 2 3 4 5
4213
 
4214
$xlab
4215
[1] "Re(Y)"
4216
 
4217
$ylab
4218
[1] "Im(Y)"
4219
 
4220
$zlab
4221
[1] "X"
4222
 
4223
> 
4224
> y <- 2 * (x2 <- 10 + (x1 <- 1:10))
4225
> xyz.coords(y ~ x1 + x2, y = NULL, z = NULL)
4226
$x
4227
 [1]  1  2  3  4  5  6  7  8  9 10
4228
 
4229
$y
4230
 [1] 11 12 13 14 15 16 17 18 19 20
4231
 
4232
$z
4233
 [1] 22 24 26 28 30 32 34 36 38 40
4234
 
4235
$xlab
4236
[1] "x1"
4237
 
4238
$ylab
4239
[1] "x2"
4240
 
4241
$zlab
4242
[1] "y"
4243
 
4244
> 
4245
> xyz.coords(data.frame(x = -1:9, y = 2:12, z = 3:13), y = NULL, z = NULL,
4246
+            log = "xy")
4247
Warning in xyz.coords(data.frame(x = -1:9, y = 2:12, z = 3:13), y = NULL,  :
4248
  2 x values <= 0 omitted from logarithmic plot
4249
$x
4250
 [1] NA NA  1  2  3  4  5  6  7  8  9
4251
 
4252
$y
4253
 [1]  2  3  4  5  6  7  8  9 10 11 12
4254
 
4255
$z
4256
 [1]  3  4  5  6  7  8  9 10 11 12 13
4257
 
4258
$xlab
4259
[1] "x"
4260
 
4261
$ylab
4262
[1] "y"
4263
 
4264
$zlab
4265
[1] "z"
4266
 
4267
> ##> Warning message: 2 x values <= 0 omitted ...
4268
> 
4269
> 
4270
> 
4271
> ### * <FOOTER>
4272
> ###
73819 hornik 4273
> cleanEx()
62439 ripley 4274
> options(digits = 7L)
61787 ripley 4275
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
77448 maechler 4276
Time elapsed:  6.49 0.237 6.812 0 0 
56186 murdoch 4277
> grDevices::dev.off()
4278
null device 
4279
          1 
4280
> ###
4281
> ### Local variables: ***
4282
> ### mode: outline-minor ***
4283
> ### outline-regexp: "\\(> \\)?### [*]+" ***
4284
> ### End: ***
4285
> quit('no')