The R Project SVN R

Rev

Rev 77447 | Rev 77499 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 77447 Rev 77448
Line 1... Line 1...
1
 
1
 
2
R Under development (unstable) (2019-11-21 r77446) -- "Unsuffered Consequences"
2
R Under development (unstable) (2019-11-22 r77447) -- "Unsuffered Consequences"
3
Copyright (C) 2019 The R Foundation for Statistical Computing
3
Copyright (C) 2019 The R Foundation for Statistical Computing
4
Platform: x86_64-pc-linux-gnu (64-bit)
4
Platform: x86_64-pc-linux-gnu (64-bit)
5
 
5
 
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
7
You are welcome to redistribute it under certain conditions.
7
You are welcome to redistribute it under certain conditions.
Line 2498... Line 2498...
2498
> ### * n2mfrow
2498
> ### * n2mfrow
2499
> 
2499
> 
2500
> flush(stderr()); flush(stdout())
2500
> flush(stderr()); flush(stdout())
2501
> 
2501
> 
2502
> ### Name: n2mfrow
2502
> ### Name: n2mfrow
2503
> ### Title: Compute Default mfrow From Number of Plots
2503
> ### Title: Compute Default 'mfrow' From Number of Plots
2504
> ### Aliases: n2mfrow
2504
> ### Aliases: n2mfrow
2505
> ### Keywords: dplot utilities
2505
> ### Keywords: dplot utilities
2506
> 
2506
> 
2507
> ### ** Examples
2507
> ### ** Examples
2508
> 
2508
> 
Line 2577... Line 2577...
2577
> require(graphics)
2577
> require(graphics)
2578
> 
2578
> 
2579
> palette()               # obtain the current palette
2579
> palette()               # obtain the current palette
2580
[1] "black"   "#DF536B" "#61D04F" "#2297E6" "#28E2E5" "#D03AF5" "#EEC21F"
2580
[1] "black"   "#DF536B" "#61D04F" "#2297E6" "#28E2E5" "#D03AF5" "#EEC21F"
2581
[8] "#656565"
2581
[8] "#656565"
2582
> palette("R3")           # old default palette
2582
> palette("R3");palette() # old default palette
-
 
2583
[1] "black"   "red"     "green3"  "blue"    "cyan"    "magenta" "yellow" 
-
 
2584
[8] "gray"   
2583
> palette("ggplot2")      # ggplot2-style palette
2585
> palette("ggplot2")      # ggplot2-style palette
-
 
2586
> palette()
-
 
2587
[1] "black"   "#F8766D" "#00BA38" "#619CFF" "#00BFC4" "#F564E3" "#B79F00"
-
 
2588
[8] "gray62" 
2584
> 
2589
> 
2585
> palette(hcl.colors(8, "viridis"))
2590
> palette(hcl.colors(8, "viridis"))
2586
> 
2591
> 
2587
> (palette(gray(seq(0,.9,len = 25)))) # gray scales; print old palette
2592
> (palette(gray(seq(0,.9,len = 25)))) # gray scales; print old palette
2588
[1] "#4B0055" "#3C3777" "#006290" "#008A98" "#00AC8E" "#25C771" "#A6DA42"
2593
[1] "#4B0055" "#3C3777" "#006290" "#008A98" "#00AC8E" "#25C771" "#A6DA42"
Line 2609... Line 2614...
2609
 [5] "Accent"          "Dark 2"          "Paired"          "Pastel 1"       
2614
 [5] "Accent"          "Dark 2"          "Paired"          "Pastel 1"       
2610
 [9] "Pastel 2"        "Set 1"           "Set 2"           "Set 3"          
2615
 [9] "Pastel 2"        "Set 1"           "Set 2"           "Set 3"          
2611
[13] "Tableau 10"      "Classic Tableau" "Polychrome 36"   "Alphabet"       
2616
[13] "Tableau 10"      "Classic Tableau" "Polychrome 36"   "Alphabet"       
2612
> 
2617
> 
2613
> ## Demonstrate the colors 1:8 in different palettes using a custom matplot()
2618
> ## Demonstrate the colors 1:8 in different palettes using a custom matplot()
2614
> sinplot <- function() {
2619
> sinplot <- function(main=NULL) {
2615
+     x <- outer(
2620
+     x <- outer(
2616
+ 	seq(-pi, pi, length.out = 50),
2621
+ 	seq(-pi, pi, length.out = 50),
2617
+ 	seq(0, pi, length.out = 8),
2622
+ 	seq(0, pi, length.out = 8),
2618
+ 	function(x, y) sin(x - y)
2623
+ 	function(x, y) sin(x - y)
2619
+     )
2624
+     )
2620
+     matplot(x, type = "l", lwd = 4, lty = 1, col = 1:8, ylab = "")
2625
+     matplot(x, type = "l", lwd = 4, lty = 1, col = 1:8, ylab = "", main=main)
2621
+ }
2626
+ }
2622
> sinplot()
-
 
2623
> palette("R3")
-
 
2624
> sinplot()
-
 
2625
> palette("Okabe-Ito")
2627
> sinplot("default palette")
2626
> sinplot()
-
 
2627
> palette("Tableau")
-
 
2628
> sinplot()
-
 
2629
> 
2628
> 
-
 
2629
> palette("R3");        sinplot("R3")
-
 
2630
> palette("Okabe-Ito"); sinplot("Okabe-Ito")
-
 
2631
> palette("Tableau")  ; sinplot("Tableau")
2630
> palette("default")
2632
> palette("default") # reset
-
 
2633
> 
-
 
2634
> ## color swatches for palette.colors()
-
 
2635
> palette.swatch <- function(palette = palette.pals(), n = 8, nrow = 8,
-
 
2636
+                            border = "black", cex = 1, ...)
-
 
2637
+ {
-
 
2638
+      cols <- sapply(palette, palette.colors, n = n, recycle = TRUE)
-
 
2639
+      ncol <- ncol(cols)
-
 
2640
+      nswatch <- min(ncol, nrow)
-
 
2641
+      op <- par(mar = rep(0.1, 4),
-
 
2642
+                mfrow = c(1, min(5, ceiling(ncol/nrow))),
-
 
2643
+      	       cex = cex, ...)
-
 
2644
+      on.exit(par(op))
-
 
2645
+      while (length(palette)) {
-
 
2646
+  	subset <- seq_len(min(nrow, ncol(cols)))
-
 
2647
+  	plot.new()
-
 
2648
+  	plot.window(c(0, n), c(0.25, nrow + 0.25))
-
 
2649
+  	y <- rev(subset)
-
 
2650
+  	text(0, y + 0.1, palette[subset], adj = c(0, 0))
-
 
2651
+  	y <- rep(y, each = n)
-
 
2652
+  	rect(rep(0:(n-1), n), y, rep(1:n, n), y - 0.5,
-
 
2653
+  	     col = cols[, subset], border = border)
-
 
2654
+  	palette <- palette[-subset]
-
 
2655
+  	cols    <- cols [, -subset]
-
 
2656
+      }
-
 
2657
+ }
-
 
2658
> 
-
 
2659
> palette.swatch()
-
 
2660
> 
-
 
2661
> palette.swatch(n = 26) # show full "Alphabet"; recycle most others
2631
> 
2662
> 
2632
> 
2663
> 
2633
> 
2664
> 
2634
> cleanEx()
2665
> cleanEx()
2635
> nameEx("palettes")
2666
> nameEx("palettes")
Line 4240... Line 4271...
4240
> ### * <FOOTER>
4271
> ### * <FOOTER>
4241
> ###
4272
> ###
4242
> cleanEx()
4273
> cleanEx()
4243
> options(digits = 7L)
4274
> options(digits = 7L)
4244
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
4275
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
4245
Time elapsed:  10.88 0.276 11.176 0 0 
4276
Time elapsed:  6.49 0.237 6.812 0 0 
4246
> grDevices::dev.off()
4277
> grDevices::dev.off()
4247
null device 
4278
null device 
4248
          1 
4279
          1 
4249
> ###
4280
> ###
4250
> ### Local variables: ***
4281
> ### Local variables: ***