The R Project SVN R

Rev

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

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