The R Project SVN R

Rev

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

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