| 1 |
|
| 2 |
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" |
| 3 |
Copyright (C) 2022 The R Foundation for Statistical Computing |
| 4 |
Platform: x86_64-pc-linux-gnu (64-bit) |
| 5 |
|
| 6 |
R is free software and comes with ABSOLUTELY NO WARRANTY. |
| 7 |
You are welcome to redistribute it under certain conditions. |
| 8 |
Type 'license()' or 'licence()' for distribution details. |
| 9 |
|
| 10 |
Natural language support but running in an English locale |
| 11 |
|
| 12 |
R is a collaborative project with many contributors. |
| 13 |
Type 'contributors()' for more information and |
| 14 |
'citation()' on how to cite R or R packages in publications. |
| 15 |
|
| 16 |
Type 'demo()' for some demos, 'help()' for on-line help, or |
| 17 |
'help.start()' for an HTML browser interface to help. |
| 18 |
Type 'q()' to quit R. |
| 19 |
|
| 20 |
> pkgname <- "colorspace" |
| 21 |
> source(file.path(R.home("share"), "R", "examples-header.R")) |
| 22 |
> options(warn = 1) |
| 23 |
> library('colorspace') |
| 24 |
> |
| 25 |
> base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') |
| 26 |
> base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') |
| 27 |
> cleanEx() |
| 28 |
> nameEx("HLS") |
| 29 |
> ### * HLS |
| 30 |
> |
| 31 |
> flush(stderr()); flush(stdout()) |
| 32 |
> |
| 33 |
> ### Name: HLS |
| 34 |
> ### Title: Create HLS Colors |
| 35 |
> ### Aliases: HLS |
| 36 |
> ### Keywords: color |
| 37 |
> |
| 38 |
> ### ** Examples |
| 39 |
> |
| 40 |
> # A rainbow of full-intensity hues |
| 41 |
> HLS(seq(0, 360, length.out = 13)[-13], 0.5, 1) |
| 42 |
H L S |
| 43 |
[1,] 0 0.5 1 |
| 44 |
[2,] 30 0.5 1 |
| 45 |
[3,] 60 0.5 1 |
| 46 |
[4,] 90 0.5 1 |
| 47 |
[5,] 120 0.5 1 |
| 48 |
[6,] 150 0.5 1 |
| 49 |
[7,] 180 0.5 1 |
| 50 |
[8,] 210 0.5 1 |
| 51 |
[9,] 240 0.5 1 |
| 52 |
[10,] 270 0.5 1 |
| 53 |
[11,] 300 0.5 1 |
| 54 |
[12,] 330 0.5 1 |
| 55 |
> |
| 56 |
> |
| 57 |
> |
| 58 |
> cleanEx() |
| 59 |
> nameEx("HSV") |
| 60 |
> ### * HSV |
| 61 |
> |
| 62 |
> flush(stderr()); flush(stdout()) |
| 63 |
> |
| 64 |
> ### Name: HSV |
| 65 |
> ### Title: Create HSV Colors |
| 66 |
> ### Aliases: HSV |
| 67 |
> ### Keywords: color |
| 68 |
> |
| 69 |
> ### ** Examples |
| 70 |
> |
| 71 |
> # A rainbow of full-intensity hues |
| 72 |
> HSV(seq(0, 360, length.out = 13)[-13], 1, 1) |
| 73 |
H S V |
| 74 |
[1,] 0 1 1 |
| 75 |
[2,] 30 1 1 |
| 76 |
[3,] 60 1 1 |
| 77 |
[4,] 90 1 1 |
| 78 |
[5,] 120 1 1 |
| 79 |
[6,] 150 1 1 |
| 80 |
[7,] 180 1 1 |
| 81 |
[8,] 210 1 1 |
| 82 |
[9,] 240 1 1 |
| 83 |
[10,] 270 1 1 |
| 84 |
[11,] 300 1 1 |
| 85 |
[12,] 330 1 1 |
| 86 |
> |
| 87 |
> |
| 88 |
> |
| 89 |
> cleanEx() |
| 90 |
> nameEx("LAB") |
| 91 |
> ### * LAB |
| 92 |
> |
| 93 |
> flush(stderr()); flush(stdout()) |
| 94 |
> |
| 95 |
> ### Name: LAB |
| 96 |
> ### Title: Create LAB Colors |
| 97 |
> ### Aliases: LAB |
| 98 |
> ### Keywords: color |
| 99 |
> |
| 100 |
> ### ** Examples |
| 101 |
> |
| 102 |
> ## Show the LAB space |
| 103 |
> set.seed(1) |
| 104 |
> x <- sRGB(runif(1000), runif(1000), runif(1000)) |
| 105 |
> y <- as(x, "LAB") |
| 106 |
> head(x) |
| 107 |
R G B |
| 108 |
[1,] 0.2655087 0.5308088 0.871805 |
| 109 |
> head(y) |
| 110 |
L A B |
| 111 |
[1,] 56.02127 6.894485 -50.58648 |
| 112 |
> plot(y) |
| 113 |
> |
| 114 |
> |
| 115 |
> |
| 116 |
> cleanEx() |
| 117 |
> nameEx("LUV") |
| 118 |
> ### * LUV |
| 119 |
> |
| 120 |
> flush(stderr()); flush(stdout()) |
| 121 |
> |
| 122 |
> ### Name: LUV |
| 123 |
> ### Title: Create LUV Colors |
| 124 |
> ### Aliases: LUV |
| 125 |
> ### Keywords: color |
| 126 |
> |
| 127 |
> ### ** Examples |
| 128 |
> |
| 129 |
> ## Show the LUV space |
| 130 |
> set.seed(1) |
| 131 |
> x <- sRGB(runif(1000), runif(1000), runif(1000)) |
| 132 |
> y <- as(x, "LUV") |
| 133 |
> head(x) |
| 134 |
R G B |
| 135 |
[1,] 0.2655087 0.5308088 0.871805 |
| 136 |
> head(y) |
| 137 |
L U V |
| 138 |
[1,] 56.02127 -26.35485 -80.16156 |
| 139 |
> plot(y) |
| 140 |
> |
| 141 |
> |
| 142 |
> |
| 143 |
> cleanEx() |
| 144 |
> nameEx("RGB") |
| 145 |
> ### * RGB |
| 146 |
> |
| 147 |
> flush(stderr()); flush(stdout()) |
| 148 |
> |
| 149 |
> ### Name: RGB |
| 150 |
> ### Title: Create RGB Colors |
| 151 |
> ### Aliases: RGB |
| 152 |
> ### Keywords: color |
| 153 |
> |
| 154 |
> ### ** Examples |
| 155 |
> |
| 156 |
> # Create a random set of colors |
| 157 |
> set.seed(1) |
| 158 |
> RGB(R = runif(20), G = runif(20), B = runif(20)) |
| 159 |
R G B |
| 160 |
[1,] 0.26550866 0.93470523 0.82094629 |
| 161 |
[2,] 0.37212390 0.21214252 0.64706019 |
| 162 |
[3,] 0.57285336 0.65167377 0.78293276 |
| 163 |
[4,] 0.90820779 0.12555510 0.55303631 |
| 164 |
[5,] 0.20168193 0.26722067 0.52971958 |
| 165 |
[6,] 0.89838968 0.38611409 0.78935623 |
| 166 |
[7,] 0.94467527 0.01339033 0.02333120 |
| 167 |
[8,] 0.66079779 0.38238796 0.47723007 |
| 168 |
[9,] 0.62911404 0.86969085 0.73231374 |
| 169 |
[10,] 0.06178627 0.34034900 0.69273156 |
| 170 |
[11,] 0.20597457 0.48208012 0.47761962 |
| 171 |
[12,] 0.17655675 0.59956583 0.86120948 |
| 172 |
[13,] 0.68702285 0.49354131 0.43809711 |
| 173 |
[14,] 0.38410372 0.18621760 0.24479728 |
| 174 |
[15,] 0.76984142 0.82737332 0.07067905 |
| 175 |
[16,] 0.49769924 0.66846674 0.09946616 |
| 176 |
[17,] 0.71761851 0.79423986 0.31627171 |
| 177 |
[18,] 0.99190609 0.10794363 0.51863426 |
| 178 |
[19,] 0.38003518 0.72371095 0.66200508 |
| 179 |
[20,] 0.77744522 0.41127443 0.40683019 |
| 180 |
> |
| 181 |
> |
| 182 |
> |
| 183 |
> cleanEx() |
| 184 |
> nameEx("USSouthPolygon") |
| 185 |
> ### * USSouthPolygon |
| 186 |
> |
| 187 |
> flush(stderr()); flush(stdout()) |
| 188 |
> |
| 189 |
> ### Name: USSouthPolygon |
| 190 |
> ### Title: Polygon for County Map of US South States: Alabama, Georgia, and |
| 191 |
> ### South Carolina |
| 192 |
> ### Aliases: USSouthPolygon |
| 193 |
> ### Keywords: datasets |
| 194 |
> |
| 195 |
> ### ** Examples |
| 196 |
> |
| 197 |
> ## generate color palette |
| 198 |
> pal <- diverging_hcl(9) |
| 199 |
> n <- length(pal) |
| 200 |
> |
| 201 |
> ## draw shaded polygons |
| 202 |
> plot(0, 0, type = "n", xlab = "", ylab = "", xaxt = "n", yaxt = "n", bty = "n", |
| 203 |
+ xlim = c(-88.5, -78.6), ylim = c(30.2, 35.2), asp = 1) |
| 204 |
> polygon(USSouthPolygon, col = pal[cut(na.omit(USSouthPolygon$z), breaks = 0:n/n)]) |
| 205 |
> |
| 206 |
> |
| 207 |
> |
| 208 |
> cleanEx() |
| 209 |
> nameEx("XYZ") |
| 210 |
> ### * XYZ |
| 211 |
> |
| 212 |
> flush(stderr()); flush(stdout()) |
| 213 |
> |
| 214 |
> ### Name: XYZ |
| 215 |
> ### Title: Create XYZ Colors |
| 216 |
> ### Aliases: XYZ |
| 217 |
> ### Keywords: color |
| 218 |
> |
| 219 |
> ### ** Examples |
| 220 |
> |
| 221 |
> ## Generate white in XYZ space |
| 222 |
> XYZ(95.047, 100.000, 108.883) |
| 223 |
X Y Z |
| 224 |
[1,] 95.047 100 108.883 |
| 225 |
> |
| 226 |
> |
| 227 |
> |
| 228 |
> cleanEx() |
| 229 |
> nameEx("adjust_transparency") |
| 230 |
> ### * adjust_transparency |
| 231 |
> |
| 232 |
> flush(stderr()); flush(stdout()) |
| 233 |
> |
| 234 |
> ### Name: adjust_transparency |
| 235 |
> ### Title: Adjust or Extract Transparency of Colors |
| 236 |
> ### Aliases: adjust_transparency extract_transparency |
| 237 |
> ### Keywords: color |
| 238 |
> |
| 239 |
> ### ** Examples |
| 240 |
> |
| 241 |
> ## modify transparency of a color (in different formats) |
| 242 |
> adjust_transparency("black", alpha = c(0, 0.5, 1)) ## name |
| 243 |
[1] "#00000000" "#00000080" "#000000FF" |
| 244 |
> adjust_transparency("#000000", alpha = c(0, 0.5, 1)) ## hex string |
| 245 |
[1] "#00000000" "#00000080" "#000000FF" |
| 246 |
> adjust_transparency(1, alpha = c(0, 0.5, 1)) ## palette() integer |
| 247 |
[1] "#00000000" "#00000080" "#000000FF" |
| 248 |
> |
| 249 |
> ## three shades of gray (in different formats: |
| 250 |
> ## name/opaque, hex/opaque, hex/semi-transparent) |
| 251 |
> x <- c("gray", "#BEBEBE", "#BEBEBE80") |
| 252 |
> |
| 253 |
> ## adjust transparency |
| 254 |
> adjust_transparency(x, alpha = NULL) ## only if necessary |
| 255 |
[1] "#BEBEBE" "#BEBEBE" "#BEBEBE80" |
| 256 |
> adjust_transparency(x, alpha = TRUE) ## add |
| 257 |
[1] "#BEBEBEFF" "#BEBEBEFF" "#BEBEBE80" |
| 258 |
> adjust_transparency(x, alpha = FALSE) ## remove |
| 259 |
[1] "#BEBEBE" "#BEBEBE" "#BEBEBE" |
| 260 |
> adjust_transparency(x, alpha = 0.8) ## modify |
| 261 |
[1] "#BEBEBECC" "#BEBEBECC" "#BEBEBECC" |
| 262 |
> |
| 263 |
> ## extract transparency in different formats |
| 264 |
> extract_transparency(x, mode = "numeric") ## default |
| 265 |
[1] 1.0000000 1.0000000 0.5019608 |
| 266 |
> extract_transparency(x, mode = "integer") |
| 267 |
[1] 255 255 128 |
| 268 |
> extract_transparency(x, mode = "character") |
| 269 |
[1] "FF" "FF" "80" |
| 270 |
> extract_transparency(x, mode = "hexmode") |
| 271 |
[1] "ff" "ff" "80" |
| 272 |
> |
| 273 |
> ## extract transparency with different default values |
| 274 |
> extract_transparency(x, default = NA) |
| 275 |
[1] NA NA 0.5019608 |
| 276 |
> extract_transparency(x, default = 0.5) |
| 277 |
[1] 0.5000000 0.5000000 0.5019608 |
| 278 |
> extract_transparency(x, default = 128L) |
| 279 |
[1] 0.5019608 0.5019608 0.5019608 |
| 280 |
> extract_transparency(x, default = "80", mode = "integer") |
| 281 |
[1] 128 128 128 |
| 282 |
> |
| 283 |
> |
| 284 |
> |
| 285 |
> cleanEx() |
| 286 |
> nameEx("choose_palette") |
| 287 |
> ### * choose_palette |
| 288 |
> |
| 289 |
> flush(stderr()); flush(stdout()) |
| 290 |
> |
| 291 |
> ### Name: choose_palette |
| 292 |
> ### Title: Graphical User Interface for Choosing HCL Color Palettes |
| 293 |
> ### Aliases: choose_palette hclwizard hcl_wizard |
| 294 |
> ### Keywords: misc |
| 295 |
> |
| 296 |
> ### ** Examples |
| 297 |
> |
| 298 |
> if(interactive()) { |
| 299 |
+ ## Using tcltk GUI |
| 300 |
+ pal <- choose_palette() |
| 301 |
+ ## or equivalently: hclwizard(gui = "tcltk") |
| 302 |
+ |
| 303 |
+ ## Using shiny GUI |
| 304 |
+ pal <- hclwizard() |
| 305 |
+ ## or equivalently: choose_palette(gui = "shiny") |
| 306 |
+ |
| 307 |
+ ## use resulting palette function |
| 308 |
+ filled.contour(volcano, color.palette = pal, asp = 1) |
| 309 |
+ } |
| 310 |
> |
| 311 |
> |
| 312 |
> |
| 313 |
> cleanEx() |
| 314 |
> nameEx("color-class") |
| 315 |
> ### * color-class |
| 316 |
> |
| 317 |
> flush(stderr()); flush(stdout()) |
| 318 |
> |
| 319 |
> ### Name: color-class |
| 320 |
> ### Title: Class "color" |
| 321 |
> ### Aliases: color-class RGB-class sRGB-class XYZ-class HSV-class HLS-class |
| 322 |
> ### LAB-class LUV-class polarLAB-class polarLUV-class [,color-method |
| 323 |
> ### coerce,color,RGB-method coerce,color,sRGB-method |
| 324 |
> ### coerce,color,XYZ-method coerce,color,LAB-method |
| 325 |
> ### coerce,color,polarLAB-method coerce,color,HSV-method |
| 326 |
> ### coerce,color,HLS-method coerce,color,LUV-method |
| 327 |
> ### coerce,color,polarLUV-method coords,color-method plot,color-method |
| 328 |
> ### show,color-method |
| 329 |
> ### Keywords: classes |
| 330 |
> |
| 331 |
> ### ** Examples |
| 332 |
> |
| 333 |
> x <- sRGB(runif(1000), runif(1000), runif(1000)) |
| 334 |
> plot(as(x, "LUV")) |
| 335 |
> |
| 336 |
> |
| 337 |
> |
| 338 |
> cleanEx() |
| 339 |
> nameEx("contrast_ratio") |
| 340 |
> ### * contrast_ratio |
| 341 |
> |
| 342 |
> flush(stderr()); flush(stdout()) |
| 343 |
> |
| 344 |
> ### Name: contrast_ratio |
| 345 |
> ### Title: W3C Contrast Ratio |
| 346 |
> ### Aliases: contrast_ratio |
| 347 |
> ### Keywords: color |
| 348 |
> |
| 349 |
> ### ** Examples |
| 350 |
> |
| 351 |
> # check contrast ratio of default palette on white background |
| 352 |
> contrast_ratio(palette(), "white") |
| 353 |
[1] 21.000000 3.758588 1.973030 3.163940 1.603030 4.805641 1.608044 |
| 354 |
[8] 2.679156 |
| 355 |
> |
| 356 |
> # visualize contrast ratio of default palette on white and black background |
| 357 |
> contrast_ratio(palette(), "white", plot = TRUE) |
| 358 |
> contrast_ratio(palette()[-1], "black", plot = TRUE) |
| 359 |
> |
| 360 |
> # APCA algorithm |
| 361 |
> contrast_ratio(palette(), "white", algorithm = "APCA") |
| 362 |
normal reverse |
| 363 |
[1,] 106.04067 -107.88473 |
| 364 |
[2,] 64.27800 -69.77386 |
| 365 |
[3,] 37.72423 -42.10985 |
| 366 |
[4,] 58.24111 -63.64142 |
| 367 |
[5,] 26.62298 -30.08416 |
| 368 |
[6,] 71.04046 -76.51234 |
| 369 |
[7,] 27.09773 -30.60320 |
| 370 |
[8,] 52.07286 -57.27345 |
| 371 |
> contrast_ratio(palette(), "white", algorithm = "APCA", plot = TRUE, digits = 0) |
| 372 |
> |
| 373 |
> |
| 374 |
> |
| 375 |
> cleanEx() |
| 376 |
> nameEx("coords") |
| 377 |
> ### * coords |
| 378 |
> |
| 379 |
> flush(stderr()); flush(stdout()) |
| 380 |
> |
| 381 |
> ### Name: coords |
| 382 |
> ### Title: Extract the Numerical Coordinates of a Color |
| 383 |
> ### Aliases: coords |
| 384 |
> ### Keywords: color |
| 385 |
> |
| 386 |
> ### ** Examples |
| 387 |
> |
| 388 |
> x <- sRGB(1, 0, 0) |
| 389 |
> coords(as(x, "HSV")) |
| 390 |
H S V |
| 391 |
[1,] 360 1 1 |
| 392 |
> |
| 393 |
> |
| 394 |
> |
| 395 |
> cleanEx() |
| 396 |
> nameEx("demoplot") |
| 397 |
> ### * demoplot |
| 398 |
> |
| 399 |
> flush(stderr()); flush(stdout()) |
| 400 |
> |
| 401 |
> ### Name: demoplot |
| 402 |
> ### Title: Color Palette Demonstration Plot |
| 403 |
> ### Aliases: demoplot |
| 404 |
> ### Keywords: hplot |
| 405 |
> |
| 406 |
> ### ** Examples |
| 407 |
> |
| 408 |
> ## all built-in demos with the same sequential heat color palette |
| 409 |
> par(mfrow = c(3, 3)) |
| 410 |
> cl <- sequential_hcl(5, "Heat") |
| 411 |
> for (i in c("map", "heatmap", "scatter", "spine", "bar", "pie", "perspective", "mosaic", "lines")) { |
| 412 |
+ demoplot(cl, type = i) |
| 413 |
+ } |
| 414 |
> |
| 415 |
> ## qualitative palettes: light pastel colors for shading areas (pie) |
| 416 |
> ## and darker colorful palettes for points or lines |
| 417 |
> demoplot(qualitative_hcl(4, "Pastel 1"), type = "pie") |
| 418 |
> demoplot(qualitative_hcl(4, "Set 2"), type = "scatter") |
| 419 |
> demoplot(qualitative_hcl(4, "Dark 3"), type = "lines") |
| 420 |
> |
| 421 |
> ## sequential palettes: display almost continuous gradients with |
| 422 |
> ## strong luminance contrasts (heatmap, perspective) and colorful |
| 423 |
> ## sequential palette for spine plot with only a few ordered categories |
| 424 |
> demoplot(sequential_hcl(99, "Purple-Blue"), type = "heatmap") |
| 425 |
> demoplot(sequential_hcl(99, "Reds"), type = "perspective") |
| 426 |
> demoplot(sequential_hcl(4, "Viridis"), type = "spine") |
| 427 |
> |
| 428 |
> ## diverging palettes: display almost continuous gradient with |
| 429 |
> ## strong luminance contrast bringing out the extremes (map), |
| 430 |
> ## more colorful palette with lower luminance contrasts for displays |
| 431 |
> ## with fewer colors (mosaic, bar) |
| 432 |
> demoplot(diverging_hcl(99, "Tropic", power = 2.5), type = "map") |
| 433 |
> demoplot(diverging_hcl(5, "Green-Orange"), type = "mosaic") |
| 434 |
> demoplot(diverging_hcl(5, "Blue-Red 2"), type = "bar") |
| 435 |
> |
| 436 |
> ## some palettes that work well on black backgrounds |
| 437 |
> par(mfrow = c(2, 3), bg = "black") |
| 438 |
> demoplot(sequential_hcl(9, "Oslo"), "heatmap") |
| 439 |
> demoplot(sequential_hcl(9, "Turku"), "heatmap") |
| 440 |
> demoplot(sequential_hcl(9, "Inferno", rev = TRUE), "heatmap") |
| 441 |
> demoplot(qualitative_hcl(9, "Set 2"), "lines") |
| 442 |
> demoplot(diverging_hcl(9, "Berlin"), "scatter") |
| 443 |
> demoplot(diverging_hcl(9, "Cyan-Magenta", l2 = 20), "lines") |
| 444 |
> |
| 445 |
> |
| 446 |
> |
| 447 |
> |
| 448 |
> graphics::par(get("par.postscript", pos = 'CheckExEnv')) |
| 449 |
> cleanEx() |
| 450 |
> nameEx("desaturate") |
| 451 |
> ### * desaturate |
| 452 |
> |
| 453 |
> flush(stderr()); flush(stdout()) |
| 454 |
> |
| 455 |
> ### Name: desaturate |
| 456 |
> ### Title: Desaturate Colors by Chroma Removal in HCL Space |
| 457 |
> ### Aliases: desaturate |
| 458 |
> ### Keywords: color |
| 459 |
> |
| 460 |
> ### ** Examples |
| 461 |
> |
| 462 |
> ## rainbow of colors and their desaturated counterparts |
| 463 |
> rainbow_hcl(12) |
| 464 |
[1] "#E495A5" "#DB9D85" "#C7A76C" "#ABB065" "#86B875" "#5CBD92" "#39BEB1" |
| 465 |
[8] "#4CB9CC" "#7DB0DD" "#ACA4E2" "#CD99D8" "#E093C3" |
| 466 |
> desaturate(rainbow_hcl(12)) |
| 467 |
[1] "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" |
| 468 |
[8] "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" |
| 469 |
> |
| 470 |
> ## convenience demo function |
| 471 |
> wheel <- function(col, radius = 1, ...) |
| 472 |
+ pie(rep(1, length(col)), col = col, radius = radius, ...) |
| 473 |
> |
| 474 |
> ## compare base and colorspace palettes |
| 475 |
> ## (in color and desaturated) |
| 476 |
> par(mar = rep(0, 4), mfrow = c(2, 2)) |
| 477 |
> ## rainbow color wheel |
| 478 |
> wheel(rainbow_hcl(12)) |
| 479 |
> wheel(rainbow(12)) |
| 480 |
> wheel(desaturate(rainbow_hcl(12))) |
| 481 |
> wheel(desaturate(rainbow(12))) |
| 482 |
> |
| 483 |
> ## apply desaturation directly on wide RGB matrix (with R/G/B channels in rows) |
| 484 |
> RGB <- diag(3) * 255 |
| 485 |
> rownames(RGB) <- c("R", "G", "B") |
| 486 |
> desaturate(RGB) |
| 487 |
[,1] [,2] [,3] |
| 488 |
R 127.1223 219.9281 75.94690 |
| 489 |
G 127.1213 219.9264 75.94625 |
| 490 |
B 127.1266 219.9352 75.94962 |
| 491 |
> |
| 492 |
> |
| 493 |
> |
| 494 |
> graphics::par(get("par.postscript", pos = 'CheckExEnv')) |
| 495 |
> cleanEx() |
| 496 |
> nameEx("divergingx_hcl") |
| 497 |
> ### * divergingx_hcl |
| 498 |
> |
| 499 |
> flush(stderr()); flush(stdout()) |
| 500 |
> |
| 501 |
> ### Name: divergingx_hcl |
| 502 |
> ### Title: (More) Flexible Diverging HCL Palettes |
| 503 |
> ### Aliases: divergingx_hcl divergex_hcl divergingx_palettes |
| 504 |
> ### Keywords: color |
| 505 |
> |
| 506 |
> ### ** Examples |
| 507 |
> |
| 508 |
> ## show emulated CARTO/ColorBrewer.org palettes |
| 509 |
> divergingx_palettes(plot = TRUE) |
| 510 |
> |
| 511 |
> ## compared to diverging_hcl() the diverging CARTO palettes are typically warmer |
| 512 |
> ## but also less balanced with respect to chroma/luminance, see e.g., |
| 513 |
> specplot(divergingx_hcl(7, "ArmyRose")) |
| 514 |
> |
| 515 |
> |
| 516 |
> |
| 517 |
> cleanEx() |
| 518 |
> nameEx("hcl_color_picker") |
| 519 |
> ### * hcl_color_picker |
| 520 |
> |
| 521 |
> flush(stderr()); flush(stdout()) |
| 522 |
> |
| 523 |
> ### Name: hcl_color_picker |
| 524 |
> ### Title: Graphical User Interface to Pick Colors in HCL Space |
| 525 |
> ### Aliases: hcl_color_picker choose_color hclcolorpicker |
| 526 |
> ### Keywords: misc |
| 527 |
> |
| 528 |
> ### ** Examples |
| 529 |
> |
| 530 |
> ## Not run: |
| 531 |
> ##D hcl_color_picker() |
| 532 |
> ## End(Not run) |
| 533 |
> |
| 534 |
> |
| 535 |
> |
| 536 |
> cleanEx() |
| 537 |
> nameEx("hcl_palettes") |
| 538 |
> ### * hcl_palettes |
| 539 |
> |
| 540 |
> flush(stderr()); flush(stdout()) |
| 541 |
> |
| 542 |
> ### Name: hcl_palettes |
| 543 |
> ### Title: HCL Color Palettes |
| 544 |
> ### Aliases: hcl_palettes print.hcl_palettes summary.hcl_palettes |
| 545 |
> ### plot.hcl_palettes qualitative_hcl sequential_hcl diverging_hcl |
| 546 |
> ### diverge_hcl |
| 547 |
> ### Keywords: color |
| 548 |
> |
| 549 |
> ### ** Examples |
| 550 |
> |
| 551 |
> ## overview of all _named_ HCL palettes |
| 552 |
> hcl_palettes() |
| 553 |
HCL palettes |
| 554 |
|
| 555 |
Type: Qualitative |
| 556 |
Names: Pastel 1, Dark 2, Dark 3, Set 2, Set 3, Warm, Cold, Harmonic, Dynamic |
| 557 |
|
| 558 |
Type: Sequential (single-hue) |
| 559 |
Names: Grays, Light Grays, Blues 2, Blues 3, Purples 2, Purples 3, Reds 2, |
| 560 |
Reds 3, Greens 2, Greens 3, Oslo |
| 561 |
|
| 562 |
Type: Sequential (multi-hue) |
| 563 |
Names: Purple-Blue, Red-Purple, Red-Blue, Purple-Orange, Purple-Yellow, |
| 564 |
Blue-Yellow, Green-Yellow, Red-Yellow, Heat, Heat 2, Terrain, |
| 565 |
Terrain 2, Viridis, Plasma, Inferno, Rocket, Mako, Dark Mint, |
| 566 |
Mint, BluGrn, Teal, TealGrn, Emrld, BluYl, ag_GrnYl, Peach, |
| 567 |
PinkYl, Burg, BurgYl, RedOr, OrYel, Purp, PurpOr, Sunset, |
| 568 |
Magenta, SunsetDark, ag_Sunset, BrwnYl, YlOrRd, YlOrBr, OrRd, |
| 569 |
Oranges, YlGn, YlGnBu, Reds, RdPu, PuRd, Purples, PuBuGn, PuBu, |
| 570 |
Greens, BuGn, GnBu, BuPu, Blues, Lajolla, Turku, Hawaii, Batlow |
| 571 |
|
| 572 |
Type: Diverging |
| 573 |
Names: Blue-Red, Blue-Red 2, Blue-Red 3, Red-Green, Purple-Green, |
| 574 |
Purple-Brown, Green-Brown, Blue-Yellow 2, Blue-Yellow 3, |
| 575 |
Green-Orange, Cyan-Magenta, Tropic, Broc, Cork, Vik, Berlin, |
| 576 |
Lisbon, Tofino |
| 577 |
> |
| 578 |
> ## visualize |
| 579 |
> hcl_palettes("qualitative", plot = TRUE) |
| 580 |
> hcl_palettes("sequential (single-hue)", n = 7, plot = TRUE) |
| 581 |
> hcl_palettes("sequential (multi-hue)", n = 7, plot = TRUE) |
| 582 |
> hcl_palettes("diverging", n = 7, plot = TRUE) |
| 583 |
> |
| 584 |
> ## inspect a specific palette |
| 585 |
> ## (upper-case, spaces, etc. are ignored for matching) |
| 586 |
> hcl_palettes(palette = "Dark 2") |
| 587 |
HCL palette |
| 588 |
Name: Dark 2 |
| 589 |
Type: Qualitative |
| 590 |
Parameter ranges: |
| 591 |
h1 h2 c1 c2 l1 l2 p1 p2 cmax fixup |
| 592 |
0 NA 50 NA 60 NA NA NA NA TRUE |
| 593 |
> hcl_palettes(palette = "dark2") |
| 594 |
HCL palette |
| 595 |
Name: Dark 2 |
| 596 |
Type: Qualitative |
| 597 |
Parameter ranges: |
| 598 |
h1 h2 c1 c2 l1 l2 p1 p2 cmax fixup |
| 599 |
0 NA 50 NA 60 NA NA NA NA TRUE |
| 600 |
> |
| 601 |
> ## set up actual colors |
| 602 |
> qualitative_hcl(4, h = c(0, 288), c = 50, l = 60) ## by hand |
| 603 |
[1] "#C87A8A" "#8A9748" "#00A2A2" "#A782C3" |
| 604 |
> qualitative_hcl(4, palette = "dark2") ## by name |
| 605 |
[1] "#C87A8A" "#909646" "#00A396" "#9189C7" |
| 606 |
> qualitative_hcl(4, palette = "dark2", c = 80) ## by name plus modification |
| 607 |
[1] "#E16A86" "#909800" "#00AD9A" "#9183E6" |
| 608 |
> |
| 609 |
> ## how HCL palettes are constructed: |
| 610 |
> ## by varying the perceptual properties via hue/chroma/luminance |
| 611 |
> swatchplot( |
| 612 |
+ "Hue" = sequential_hcl(5, h = c(0, 300), c = c(60, 60), l = 65), |
| 613 |
+ "Chroma" = sequential_hcl(5, h = 0, c = c(100, 0), l = 65, rev = TRUE, power = 1), |
| 614 |
+ "Luminance" = sequential_hcl(5, h = 260, c = c(25, 25), l = c(25, 90), rev = TRUE, power = 1), |
| 615 |
+ off = 0 |
| 616 |
+ ) |
| 617 |
> |
| 618 |
> ## for qualitative palettes luminance and chroma are fixed, varying only hue |
| 619 |
> hclplot(qualitative_hcl(9, c = 50, l = 70)) |
| 620 |
> |
| 621 |
> ## single-hue sequential palette (h = 260) with linear vs. power-transformed trajectory |
| 622 |
> hclplot(sequential_hcl(7, h = 260, c = 80, l = c(35, 95), power = 1)) |
| 623 |
> hclplot(sequential_hcl(7, h = 260, c = 80, l = c(35, 95), power = 1.5)) |
| 624 |
> |
| 625 |
> ## advanced single-hue sequential palette with triangular chroma trajectory |
| 626 |
> ## (piecewise linear vs. power-transformed) |
| 627 |
> hclplot(sequential_hcl(7, h = 245, c = c(40, 75, 0), l = c(30, 95), power = 1)) |
| 628 |
> hclplot(sequential_hcl(7, h = 245, c = c(40, 75, 0), l = c(30, 95), power = c(0.8, 1.4))) |
| 629 |
> |
| 630 |
> ## multi-hue sequential palette with small hue range and triangular chroma vs. |
| 631 |
> ## large hue range and linear chroma trajectory |
| 632 |
> hclplot(sequential_hcl(7, h = c(260, 220), c = c(50, 75, 0), l = c(30, 95), power = 1)) |
| 633 |
> hclplot(sequential_hcl(7, h = c(260, 60), c = 60, l = c(40, 95), power = 1)) |
| 634 |
> |
| 635 |
> ## balanced diverging palette constructed from two simple single-hue sequential |
| 636 |
> ## palettes (for hues 260/blue and 0/red) |
| 637 |
> hclplot(diverging_hcl(7, h = c(260, 0), c = 80, l = c(35, 95), power = 1)) |
| 638 |
> |
| 639 |
> ## to register a particular adapted palette for re-use in the same session |
| 640 |
> ## with a new name the register=... argument can be used once, e.g., |
| 641 |
> diverging_hcl(7, palette = "Tropic", h2 = 0, register = "mytropic") |
| 642 |
> |
| 643 |
> ## subsequently palete="mytropic" is available in diverging_hcl() and the diverging |
| 644 |
> ## ggplot2 scales such as scale_color_continuous_diverging() etc. |
| 645 |
> demoplot(diverging_hcl(11, "mytropic"), type = "map") |
| 646 |
> |
| 647 |
> ## to register this palette in all R sessions you could place the following |
| 648 |
> ## code in a startup script (e.g., .Rprofile): |
| 649 |
> ## colorspace::diverging_hcl(7, palette = "Tropic", h2 = 0, register = "mytropic") |
| 650 |
> |
| 651 |
> |
| 652 |
> |
| 653 |
> |
| 654 |
> cleanEx() |
| 655 |
> nameEx("hclplot") |
| 656 |
> ### * hclplot |
| 657 |
> |
| 658 |
> flush(stderr()); flush(stdout()) |
| 659 |
> |
| 660 |
> ### Name: hclplot |
| 661 |
> ### Title: Palette Plot in HCL Space |
| 662 |
> ### Aliases: hclplot |
| 663 |
> ### Keywords: hplot |
| 664 |
> |
| 665 |
> ### ** Examples |
| 666 |
> |
| 667 |
> ## for qualitative palettes luminance and chroma are fixed, varying only hue |
| 668 |
> hclplot(qualitative_hcl(9, c = 50, l = 70)) |
| 669 |
> |
| 670 |
> ## single-hue sequential palette (h = 260) with linear vs. power-transformed trajectory |
| 671 |
> hclplot(sequential_hcl(7, h = 260, c = 80, l = c(35, 95), power = 1)) |
| 672 |
> hclplot(sequential_hcl(7, h = 260, c = 80, l = c(35, 95), power = 1.5)) |
| 673 |
> |
| 674 |
> ## advanced single-hue sequential palette with triangular chroma trajectory |
| 675 |
> ## (piecewise linear vs. power-transformed) |
| 676 |
> hclplot(sequential_hcl(7, h = 245, c = c(40, 75, 0), l = c(30, 95), power = 1)) |
| 677 |
> hclplot(sequential_hcl(7, h = 245, c = c(40, 75, 0), l = c(30, 95), power = c(0.8, 1.4))) |
| 678 |
> |
| 679 |
> ## multi-hue sequential palette with small hue range and triangular chroma vs. |
| 680 |
> ## large hue range and linear chroma trajectory |
| 681 |
> hclplot(sequential_hcl(7, h = c(260, 220), c = c(50, 75, 0), l = c(30, 95), power = 1)) |
| 682 |
> hclplot(sequential_hcl(7, h = c(260, 60), c = 60, l = c(40, 95), power = 1)) |
| 683 |
> |
| 684 |
> ## balanced diverging palette constructed from two simple single-hue sequential |
| 685 |
> ## palettes (for hues 260/blue and 0/red) |
| 686 |
> hclplot(diverging_hcl(7, h = c(260, 0), c = 80, l = c(35, 95), power = 1)) |
| 687 |
> |
| 688 |
> |
| 689 |
> |
| 690 |
> |
| 691 |
> cleanEx() |
| 692 |
> nameEx("hex") |
| 693 |
> ### * hex |
| 694 |
> |
| 695 |
> flush(stderr()); flush(stdout()) |
| 696 |
> |
| 697 |
> ### Name: hex |
| 698 |
> ### Title: Convert Colors to Hexadecimal Strings |
| 699 |
> ### Aliases: hex |
| 700 |
> ### Keywords: color |
| 701 |
> |
| 702 |
> ### ** Examples |
| 703 |
> |
| 704 |
> hsv <- HSV(seq(0, 360, length.out = 7)[-7], 1, 1) |
| 705 |
> hsv |
| 706 |
H S V |
| 707 |
[1,] 0 1 1 |
| 708 |
[2,] 60 1 1 |
| 709 |
[3,] 120 1 1 |
| 710 |
[4,] 180 1 1 |
| 711 |
[5,] 240 1 1 |
| 712 |
[6,] 300 1 1 |
| 713 |
> hex(hsv) |
| 714 |
[1] "#FF0000" "#FFFF00" "#00FF00" "#00FFFF" "#0000FF" "#FF00FF" |
| 715 |
> barplot(rep(1,6), col = hex(hsv)) |
| 716 |
> |
| 717 |
> |
| 718 |
> |
| 719 |
> cleanEx() |
| 720 |
> nameEx("hex2RGB") |
| 721 |
> ### * hex2RGB |
| 722 |
> |
| 723 |
> flush(stderr()); flush(stdout()) |
| 724 |
> |
| 725 |
> ### Name: hex2RGB |
| 726 |
> ### Title: Convert Hexadecimal Color Specifications to sRGB Objects |
| 727 |
> ### Aliases: hex2RGB |
| 728 |
> ### Keywords: color |
| 729 |
> |
| 730 |
> ### ** Examples |
| 731 |
> |
| 732 |
> hex2RGB(c("#FF0000","#00FF00", "#0000FF50")) |
| 733 |
R G B |
| 734 |
[1,] 1 0 0 |
| 735 |
[2,] 0 1 0 |
| 736 |
[3,] 0 0 1 |
| 737 |
> |
| 738 |
> |
| 739 |
> |
| 740 |
> cleanEx() |
| 741 |
> nameEx("lighten") |
| 742 |
> ### * lighten |
| 743 |
> |
| 744 |
> flush(stderr()); flush(stdout()) |
| 745 |
> |
| 746 |
> ### Name: lighten |
| 747 |
> ### Title: Algorithmically Lighten or Darken Colors |
| 748 |
> ### Aliases: lighten darken |
| 749 |
> ### Keywords: color |
| 750 |
> |
| 751 |
> ### ** Examples |
| 752 |
> |
| 753 |
> # lighten dark colors, example 1 |
| 754 |
> cl <- qualitative_hcl(5) |
| 755 |
> swatchplot(list( |
| 756 |
+ HCL = rbind("0%" = cl, |
| 757 |
+ "15%" = lighten(cl, 0.15), |
| 758 |
+ "30%" = lighten(cl, 0.3)), |
| 759 |
+ HLS = rbind("0%" = cl, |
| 760 |
+ "15%" = lighten(cl, 0.15, space = "HLS"), |
| 761 |
+ "30%" = lighten(cl, 0.3, space = "HLS")), |
| 762 |
+ combined = rbind("0%" = cl, |
| 763 |
+ "15%" = lighten(cl, 0.15, space = "combined"), |
| 764 |
+ "30%" = lighten(cl, 0.3, space = "combined"))), |
| 765 |
+ nrow = 4, line = 2.5 |
| 766 |
+ ) |
| 767 |
> |
| 768 |
> # lighten dark colors, example 2 |
| 769 |
> cl <- c("#61A9D9", "#ADD668", "#E6D152", "#CE6BAF", "#797CBA") |
| 770 |
> swatchplot(list( |
| 771 |
+ HCL = rbind("0%" = cl, |
| 772 |
+ "15%" = lighten(cl, 0.15), |
| 773 |
+ "30%" = lighten(cl, 0.3)), |
| 774 |
+ HLS = rbind("0%" = cl, |
| 775 |
+ "15%" = lighten(cl, 0.15, space = "HLS"), |
| 776 |
+ "30%" = lighten(cl, 0.3, space = "HLS")), |
| 777 |
+ combined = rbind("0%" = cl, |
| 778 |
+ "15%" = lighten(cl, 0.15, space = "combined"), |
| 779 |
+ "30%" = lighten(cl, 0.3, space = "combined"))), |
| 780 |
+ nrow = 4, line = 2.5 |
| 781 |
+ ) |
| 782 |
> |
| 783 |
> # darken light colors, example 1 |
| 784 |
> cl <- qualitative_hcl(5, "Pastel 1") |
| 785 |
> swatchplot(list( |
| 786 |
+ combined = rbind("0%" = cl, |
| 787 |
+ "15%" = darken(cl, 0.15), |
| 788 |
+ "30%" = darken(cl, 0.3)), |
| 789 |
+ HCL = rbind("0%" = cl, |
| 790 |
+ "15%" = darken(cl, 0.15, space = "HCL"), |
| 791 |
+ "30%" = darken(cl, 0.3, space = "HCL")), |
| 792 |
+ HLS = rbind("0%" = cl, |
| 793 |
+ "15%" = darken(cl, 0.15, space = "HLS"), |
| 794 |
+ "30%" = darken(cl, 0.3, space = "HLS"))), |
| 795 |
+ nrow = 4, line = 2.5 |
| 796 |
+ ) |
| 797 |
> |
| 798 |
> # darken light colors, example 2 |
| 799 |
> cl <- c("#CDE4F3","#E7F3D3","#F7F0C7","#EFCFE5","#D0D1E7") |
| 800 |
> swatchplot(list( |
| 801 |
+ combined = rbind("0%" = cl, |
| 802 |
+ "15%" = darken(cl, 0.15), |
| 803 |
+ "30%" = darken(cl, 0.3)), |
| 804 |
+ HCL = rbind("0%" = cl, |
| 805 |
+ "15%" = darken(cl, 0.15, space = "HCL"), |
| 806 |
+ "30%" = darken(cl, 0.3, space = "HCL")), |
| 807 |
+ HLS = rbind("0%" = cl, |
| 808 |
+ "15%" = darken(cl, 0.15, space = "HLS"), |
| 809 |
+ "30%" = darken(cl, 0.3, space = "HLS"))), |
| 810 |
+ nrow = 4, line = 2.5 |
| 811 |
+ ) |
| 812 |
> |
| 813 |
> |
| 814 |
> |
| 815 |
> cleanEx() |
| 816 |
> nameEx("max_chroma") |
| 817 |
> ### * max_chroma |
| 818 |
> |
| 819 |
> flush(stderr()); flush(stdout()) |
| 820 |
> |
| 821 |
> ### Name: max_chroma |
| 822 |
> ### Title: Compute Maximum Chroma for Given Hue and Luminance in HCL |
| 823 |
> ### Aliases: max_chroma max_chroma_table |
| 824 |
> ### Keywords: color datasets |
| 825 |
> |
| 826 |
> ### ** Examples |
| 827 |
> |
| 828 |
> max_chroma(h = 0:36 * 10, l = 50) |
| 829 |
[1] 137.96 161.61 121.85 91.86 75.55 65.86 59.99 56.66 55.28 55.61 |
| 830 |
[11] 57.70 61.92 69.06 72.78 58.06 49.54 44.38 41.33 39.81 39.55 |
| 831 |
[21] 40.52 42.87 47.04 53.90 65.45 86.65 124.44 123.87 127.15 131.17 |
| 832 |
[31] 119.54 112.95 110.23 110.93 115.15 123.62 137.96 |
| 833 |
> max_chroma(h = 120, l = 0:10 * 10) |
| 834 |
[1] 0.00 14.44 28.04 41.67 55.35 69.06 82.79 96.53 110.28 122.90 |
| 835 |
[11] 0.00 |
| 836 |
> |
| 837 |
> |
| 838 |
> |
| 839 |
> cleanEx() |
| 840 |
> nameEx("mixcolor") |
| 841 |
> ### * mixcolor |
| 842 |
> |
| 843 |
> flush(stderr()); flush(stdout()) |
| 844 |
> |
| 845 |
> ### Name: mixcolor |
| 846 |
> ### Title: Compute the Convex Combination of Two Colors |
| 847 |
> ### Aliases: mixcolor |
| 848 |
> ### Keywords: color |
| 849 |
> |
| 850 |
> ### ** Examples |
| 851 |
> |
| 852 |
> mixcolor(0.5, sRGB(1, 0, 0), sRGB(0, 1, 0)) |
| 853 |
R G B |
| 854 |
[1,] 0.5 0.5 0 |
| 855 |
> |
| 856 |
> |
| 857 |
> |
| 858 |
> cleanEx() |
| 859 |
> nameEx("polarLAB") |
| 860 |
> ### * polarLAB |
| 861 |
> |
| 862 |
> flush(stderr()); flush(stdout()) |
| 863 |
> |
| 864 |
> ### Name: polarLAB |
| 865 |
> ### Title: Create polarLAB Colors |
| 866 |
> ### Aliases: polarLAB |
| 867 |
> ### Keywords: color |
| 868 |
> |
| 869 |
> ### ** Examples |
| 870 |
> |
| 871 |
> ## Show the polarLAB space |
| 872 |
> set.seed(1) |
| 873 |
> x <- sRGB(runif(1000), runif(1000), runif(1000)) |
| 874 |
> y <- as(x, "polarLAB") |
| 875 |
> head(x) |
| 876 |
R G B |
| 877 |
[1,] 0.2655087 0.5308088 0.871805 |
| 878 |
> head(y) |
| 879 |
L C H |
| 880 |
[1,] 56.02127 51.05415 277.7611 |
| 881 |
> plot(y) |
| 882 |
> |
| 883 |
> |
| 884 |
> |
| 885 |
> cleanEx() |
| 886 |
> nameEx("polarLUV") |
| 887 |
> ### * polarLUV |
| 888 |
> |
| 889 |
> flush(stderr()); flush(stdout()) |
| 890 |
> |
| 891 |
> ### Name: polarLUV |
| 892 |
> ### Title: Create polarLUV (HCL) Colors |
| 893 |
> ### Aliases: polarLUV HCL |
| 894 |
> ### Keywords: color |
| 895 |
> |
| 896 |
> ### ** Examples |
| 897 |
> |
| 898 |
> ## Show the polarLUV space |
| 899 |
> set.seed(1) |
| 900 |
> x <- sRGB(runif(1000), runif(1000), runif(1000)) |
| 901 |
> y <- as(x, "polarLUV") |
| 902 |
> head(x) |
| 903 |
R G B |
| 904 |
[1,] 0.2655087 0.5308088 0.871805 |
| 905 |
> head(y) |
| 906 |
L C H |
| 907 |
[1,] 56.02127 84.38279 251.8006 |
| 908 |
> plot(y) |
| 909 |
> |
| 910 |
> |
| 911 |
> |
| 912 |
> cleanEx() |
| 913 |
> nameEx("rainbow_hcl") |
| 914 |
> ### * rainbow_hcl |
| 915 |
> |
| 916 |
> flush(stderr()); flush(stdout()) |
| 917 |
> |
| 918 |
> ### Name: rainbow_hcl |
| 919 |
> ### Title: HCL (and HSV) Color Palettes Corresponding to Base R Palettes |
| 920 |
> ### Aliases: rainbow_hcl heat_hcl terrain_hcl diverging_hsv diverge_hsv |
| 921 |
> ### Keywords: color |
| 922 |
> |
| 923 |
> ### ** Examples |
| 924 |
> |
| 925 |
> ## convenience demo function |
| 926 |
> wheel <- function(col, radius = 1, ...) |
| 927 |
+ pie(rep(1, length(col)), col = col, radius = radius, ...) |
| 928 |
> |
| 929 |
> ## compare base and colorspace palettes |
| 930 |
> ## (in color and desaturated) |
| 931 |
> par(mar = rep(0, 4), mfrow = c(2, 2)) |
| 932 |
> ## rainbow color wheel |
| 933 |
> wheel(rainbow_hcl(12)) |
| 934 |
> wheel(rainbow(12)) |
| 935 |
> wheel(desaturate(rainbow_hcl(12))) |
| 936 |
> wheel(desaturate(rainbow(12))) |
| 937 |
> |
| 938 |
> ## diverging red-blue colors |
| 939 |
> swatchplot( |
| 940 |
+ diverging_hsv(7), |
| 941 |
+ desaturate(diverging_hsv(7)), |
| 942 |
+ diverging_hcl(7, c = 100, l = c(50, 90)), |
| 943 |
+ desaturate(diverging_hcl(7, c = 100, l = c(50, 90))), |
| 944 |
+ nrow = 2 |
| 945 |
+ ) |
| 946 |
> |
| 947 |
> ## diverging cyan-magenta colors |
| 948 |
> swatchplot( |
| 949 |
+ cm.colors(7), |
| 950 |
+ desaturate(cm.colors(7)), |
| 951 |
+ diverging_hcl(7, "Cyan-Magenta"), ## or, similarly: Tropic |
| 952 |
+ desaturate(diverging_hcl(7, "Cyan-Magenta")), |
| 953 |
+ nrow = 2 |
| 954 |
+ ) |
| 955 |
> |
| 956 |
> ## heat colors |
| 957 |
> swatchplot( |
| 958 |
+ heat.colors(12), |
| 959 |
+ desaturate(heat.colors(12)), |
| 960 |
+ heat_hcl(12), |
| 961 |
+ desaturate(heat_hcl(12)), |
| 962 |
+ nrow = 2 |
| 963 |
+ ) |
| 964 |
> |
| 965 |
> ## terrain colors |
| 966 |
> swatchplot( |
| 967 |
+ terrain.colors(12), |
| 968 |
+ desaturate(terrain.colors(12)), |
| 969 |
+ terrain_hcl(12), |
| 970 |
+ desaturate(terrain_hcl(12)), |
| 971 |
+ nrow = 2 |
| 972 |
+ ) |
| 973 |
> |
| 974 |
> |
| 975 |
> |
| 976 |
> graphics::par(get("par.postscript", pos = 'CheckExEnv')) |
| 977 |
> cleanEx() |
| 978 |
> nameEx("readRGB") |
| 979 |
> ### * readRGB |
| 980 |
> |
| 981 |
> flush(stderr()); flush(stdout()) |
| 982 |
> |
| 983 |
> ### Name: readRGB |
| 984 |
> ### Title: Read RGB Color Descriptions |
| 985 |
> ### Aliases: readRGB |
| 986 |
> ### Keywords: color |
| 987 |
> |
| 988 |
> ### ** Examples |
| 989 |
> |
| 990 |
> ## Not run: |
| 991 |
> ##D rgb <- readRGB("pastel.rgb") |
| 992 |
> ##D hsv <- readRGB("pastel.rgb", "HSV") |
| 993 |
> ## End(Not run) |
| 994 |
> |
| 995 |
> |
| 996 |
> |
| 997 |
> cleanEx() |
| 998 |
> nameEx("readhex") |
| 999 |
> ### * readhex |
| 1000 |
> |
| 1001 |
> flush(stderr()); flush(stdout()) |
| 1002 |
> |
| 1003 |
> ### Name: readhex |
| 1004 |
> ### Title: Read Hexadecimal Color Descriptions |
| 1005 |
> ### Aliases: readhex |
| 1006 |
> ### Keywords: color |
| 1007 |
> |
| 1008 |
> ### ** Examples |
| 1009 |
> |
| 1010 |
> ## Not run: |
| 1011 |
> ##D rgb <- readhex("pastel.txt") |
| 1012 |
> ##D hsv <- readhex("pastel.txt", "HSV") |
| 1013 |
> ## End(Not run) |
| 1014 |
> |
| 1015 |
> |
| 1016 |
> |
| 1017 |
> cleanEx() |
| 1018 |
> nameEx("sRGB") |
| 1019 |
> ### * sRGB |
| 1020 |
> |
| 1021 |
> flush(stderr()); flush(stdout()) |
| 1022 |
> |
| 1023 |
> ### Name: sRGB |
| 1024 |
> ### Title: Create sRGB Colors |
| 1025 |
> ### Aliases: sRGB |
| 1026 |
> ### Keywords: color |
| 1027 |
> |
| 1028 |
> ### ** Examples |
| 1029 |
> |
| 1030 |
> # Create a random set of colors |
| 1031 |
> set.seed(1) |
| 1032 |
> sRGB(R = runif(20), G = runif(20), B = runif(20)) |
| 1033 |
R G B |
| 1034 |
[1,] 0.26550866 0.93470523 0.82094629 |
| 1035 |
[2,] 0.37212390 0.21214252 0.64706019 |
| 1036 |
[3,] 0.57285336 0.65167377 0.78293276 |
| 1037 |
[4,] 0.90820779 0.12555510 0.55303631 |
| 1038 |
[5,] 0.20168193 0.26722067 0.52971958 |
| 1039 |
[6,] 0.89838968 0.38611409 0.78935623 |
| 1040 |
[7,] 0.94467527 0.01339033 0.02333120 |
| 1041 |
[8,] 0.66079779 0.38238796 0.47723007 |
| 1042 |
[9,] 0.62911404 0.86969085 0.73231374 |
| 1043 |
[10,] 0.06178627 0.34034900 0.69273156 |
| 1044 |
[11,] 0.20597457 0.48208012 0.47761962 |
| 1045 |
[12,] 0.17655675 0.59956583 0.86120948 |
| 1046 |
[13,] 0.68702285 0.49354131 0.43809711 |
| 1047 |
[14,] 0.38410372 0.18621760 0.24479728 |
| 1048 |
[15,] 0.76984142 0.82737332 0.07067905 |
| 1049 |
[16,] 0.49769924 0.66846674 0.09946616 |
| 1050 |
[17,] 0.71761851 0.79423986 0.31627171 |
| 1051 |
[18,] 0.99190609 0.10794363 0.51863426 |
| 1052 |
[19,] 0.38003518 0.72371095 0.66200508 |
| 1053 |
[20,] 0.77744522 0.41127443 0.40683019 |
| 1054 |
> |
| 1055 |
> |
| 1056 |
> |
| 1057 |
> cleanEx() |
| 1058 |
> nameEx("scale_colour_binned_diverging") |
| 1059 |
> ### * scale_colour_binned_diverging |
| 1060 |
> |
| 1061 |
> flush(stderr()); flush(stdout()) |
| 1062 |
> |
| 1063 |
> ### Name: scale_colour_binned_diverging |
| 1064 |
> ### Title: HCL-Based Binned Diverging Color Scales for ggplot2 |
| 1065 |
> ### Aliases: scale_colour_binned_diverging scale_color_binned_diverging |
| 1066 |
> ### scale_fill_binned_diverging |
| 1067 |
> |
| 1068 |
> ### ** Examples |
| 1069 |
> |
| 1070 |
> # adapted from stackoverflow: https://stackoverflow.com/a/20127706/4975218 |
| 1071 |
> |
| 1072 |
> library("ggplot2") |
| 1073 |
> |
| 1074 |
> # generate dataset and base plot |
| 1075 |
> set.seed(100) |
| 1076 |
> df <- data.frame(country = LETTERS, V = runif(26, -40, 40)) |
| 1077 |
> df$country = factor(LETTERS, LETTERS[order(df$V)]) # reorder factors |
| 1078 |
> gg <- ggplot(df, aes(x = country, y = V, fill = V)) + |
| 1079 |
+ geom_bar(stat = "identity") + |
| 1080 |
+ labs(y = "Under/over valuation in %", x = "Country") + |
| 1081 |
+ coord_flip() + theme_minimal() |
| 1082 |
> |
| 1083 |
> # plot with default diverging scale |
| 1084 |
> gg + scale_fill_binned_diverging(n.breaks = 6) |
| 1085 |
> |
| 1086 |
> # plot with alternative scale |
| 1087 |
> gg + scale_fill_binned_diverging(palette = "Purple-Green", n.breaks = 6) |
| 1088 |
> |
| 1089 |
> |
| 1090 |
> |
| 1091 |
> cleanEx() |
| 1092 |
|
| 1093 |
detaching ‘package:ggplot2’ |
| 1094 |
|
| 1095 |
> nameEx("scale_colour_binned_divergingx") |
| 1096 |
> ### * scale_colour_binned_divergingx |
| 1097 |
> |
| 1098 |
> flush(stderr()); flush(stdout()) |
| 1099 |
> |
| 1100 |
> ### Name: scale_colour_binned_divergingx |
| 1101 |
> ### Title: HCL-Based Binned Flexible Diverging Scales for ggplot2 |
| 1102 |
> ### Aliases: scale_colour_binned_divergingx scale_color_binned_divergingx |
| 1103 |
> ### scale_fill_binned_divergingx |
| 1104 |
> |
| 1105 |
> ### ** Examples |
| 1106 |
> |
| 1107 |
> library("ggplot2") |
| 1108 |
> |
| 1109 |
> # volcano plot (difference from mean height) |
| 1110 |
> nx = 87 |
| 1111 |
> ny = 61 |
| 1112 |
> df <- data.frame(diff = c(volcano) - mean(volcano), x = rep(1:nx, ny), y = rep(1:ny, each = nx)) |
| 1113 |
> ggplot(df, aes(x, y, fill=diff)) + |
| 1114 |
+ geom_raster() + scale_fill_binned_divergingx(palette = "Fall", rev = TRUE) + |
| 1115 |
+ coord_fixed(expand = FALSE) |
| 1116 |
> |
| 1117 |
> |
| 1118 |
> # adapted from stackoverflow: https://stackoverflow.com/a/20127706/4975218 |
| 1119 |
> |
| 1120 |
> # generate dataset and base plot |
| 1121 |
> set.seed(100) |
| 1122 |
> df <- data.frame(country = LETTERS, V = runif(26, -40, 40)) |
| 1123 |
> df$country = factor(LETTERS, LETTERS[order(df$V)]) # reorder factors |
| 1124 |
> gg <- ggplot(df, aes(x = country, y = V, fill = V)) + |
| 1125 |
+ geom_bar(stat = "identity") + |
| 1126 |
+ labs(y = "Under/over valuation in %", x = "Country") + |
| 1127 |
+ coord_flip() + theme_minimal() |
| 1128 |
> |
| 1129 |
> # plot with diverging scale "Geyser" |
| 1130 |
> gg + scale_fill_binned_divergingx(palette = "Geyser", n.breaks = 6) |
| 1131 |
> |
| 1132 |
> |
| 1133 |
> |
| 1134 |
> cleanEx() |
| 1135 |
|
| 1136 |
detaching ‘package:ggplot2’ |
| 1137 |
|
| 1138 |
> nameEx("scale_colour_binned_qualitative") |
| 1139 |
> ### * scale_colour_binned_qualitative |
| 1140 |
> |
| 1141 |
> flush(stderr()); flush(stdout()) |
| 1142 |
> |
| 1143 |
> ### Name: scale_colour_binned_qualitative |
| 1144 |
> ### Title: HCL-Based Binned Qualitative Color Scales for ggplot2 |
| 1145 |
> ### Aliases: scale_colour_binned_qualitative scale_color_binned_qualitative |
| 1146 |
> ### scale_fill_binned_qualitative |
| 1147 |
> |
| 1148 |
> ### ** Examples |
| 1149 |
> |
| 1150 |
> library("ggplot2") |
| 1151 |
> |
| 1152 |
> # none of these examples are necessarily good ideas |
| 1153 |
> gg <- ggplot(iris, aes(x = Species, y = Sepal.Width, color = Sepal.Length)) + |
| 1154 |
+ geom_jitter(width = 0.3) + theme_minimal() |
| 1155 |
> |
| 1156 |
> gg + scale_color_binned_qualitative(palette = "Dynamic") |
| 1157 |
> gg + scale_color_binned_qualitative(palette = "Dark3", l1 = 70) |
| 1158 |
> |
| 1159 |
> nx = 87 |
| 1160 |
> ny = 61 |
| 1161 |
> df <- data.frame(height = c(volcano), x = rep(1:nx, ny), y = rep(1:ny, each = nx)) |
| 1162 |
> ggplot(df, aes(x, y, fill=height)) + |
| 1163 |
+ geom_raster() + scale_fill_binned_qualitative(palette = "Dark 3") + |
| 1164 |
+ coord_fixed(expand = FALSE) |
| 1165 |
> |
| 1166 |
> |
| 1167 |
> |
| 1168 |
> cleanEx() |
| 1169 |
|
| 1170 |
detaching ‘package:ggplot2’ |
| 1171 |
|
| 1172 |
> nameEx("scale_colour_binned_sequential") |
| 1173 |
> ### * scale_colour_binned_sequential |
| 1174 |
> |
| 1175 |
> flush(stderr()); flush(stdout()) |
| 1176 |
> |
| 1177 |
> ### Name: scale_colour_binned_sequential |
| 1178 |
> ### Title: HCL-Based Binned Sequential Color Scales for ggplot2 |
| 1179 |
> ### Aliases: scale_colour_binned_sequential scale_color_binned_sequential |
| 1180 |
> ### scale_fill_binned_sequential |
| 1181 |
> |
| 1182 |
> ### ** Examples |
| 1183 |
> |
| 1184 |
> library("ggplot2") |
| 1185 |
> |
| 1186 |
> # volcano plot |
| 1187 |
> df <- data.frame(height = c(volcano), x = c(row(volcano)), y = c(col(volcano))) |
| 1188 |
> ggplot(df, aes(x, y, fill = height)) + |
| 1189 |
+ geom_raster() + scale_fill_binned_sequential(palette = "Terrain", rev = FALSE) + |
| 1190 |
+ coord_fixed(expand = FALSE) |
| 1191 |
> |
| 1192 |
> |
| 1193 |
> |
| 1194 |
> cleanEx() |
| 1195 |
|
| 1196 |
detaching ‘package:ggplot2’ |
| 1197 |
|
| 1198 |
> nameEx("scale_colour_continuous_diverging") |
| 1199 |
> ### * scale_colour_continuous_diverging |
| 1200 |
> |
| 1201 |
> flush(stderr()); flush(stdout()) |
| 1202 |
> |
| 1203 |
> ### Name: scale_colour_continuous_diverging |
| 1204 |
> ### Title: HCL-Based Continuous Diverging Color Scales for ggplot2 |
| 1205 |
> ### Aliases: scale_colour_continuous_diverging |
| 1206 |
> ### scale_color_continuous_diverging scale_fill_continuous_diverging |
| 1207 |
> |
| 1208 |
> ### ** Examples |
| 1209 |
> |
| 1210 |
> # adapted from stackoverflow: https://stackoverflow.com/a/20127706/4975218 |
| 1211 |
> |
| 1212 |
> library("ggplot2") |
| 1213 |
> |
| 1214 |
> # generate dataset and base plot |
| 1215 |
> set.seed(100) |
| 1216 |
> df <- data.frame(country = LETTERS, V = runif(26, -40, 40)) |
| 1217 |
> df$country = factor(LETTERS, LETTERS[order(df$V)]) # reorder factors |
| 1218 |
> gg <- ggplot(df, aes(x = country, y = V, fill = V)) + |
| 1219 |
+ geom_bar(stat = "identity") + |
| 1220 |
+ labs(y = "Under/over valuation in %", x = "Country") + |
| 1221 |
+ coord_flip() + theme_minimal() |
| 1222 |
> |
| 1223 |
> # plot with default diverging scale |
| 1224 |
> gg + scale_fill_continuous_diverging() |
| 1225 |
> |
| 1226 |
> # plot with alternative scale |
| 1227 |
> gg + scale_fill_continuous_diverging(palette = "Purple-Green") |
| 1228 |
> |
| 1229 |
> # plot with modified alternative scale |
| 1230 |
> gg + scale_fill_continuous_diverging(palette = "Blue-Red 3", l1 = 30, l2 = 100, p1 = .9, p2 = 1.2) |
| 1231 |
> |
| 1232 |
> |
| 1233 |
> |
| 1234 |
> cleanEx() |
| 1235 |
|
| 1236 |
detaching ‘package:ggplot2’ |
| 1237 |
|
| 1238 |
> nameEx("scale_colour_continuous_divergingx") |
| 1239 |
> ### * scale_colour_continuous_divergingx |
| 1240 |
> |
| 1241 |
> flush(stderr()); flush(stdout()) |
| 1242 |
> |
| 1243 |
> ### Name: scale_colour_continuous_divergingx |
| 1244 |
> ### Title: HCL-Based Continuous Flexible Diverging Scales for ggplot2 |
| 1245 |
> ### Aliases: scale_colour_continuous_divergingx |
| 1246 |
> ### scale_color_continuous_divergingx scale_fill_continuous_divergingx |
| 1247 |
> |
| 1248 |
> ### ** Examples |
| 1249 |
> |
| 1250 |
> library("ggplot2") |
| 1251 |
> |
| 1252 |
> # volcano plot (difference from mean height) |
| 1253 |
> nx = 87 |
| 1254 |
> ny = 61 |
| 1255 |
> df <- data.frame(diff = c(volcano) - mean(volcano), x = rep(1:nx, ny), y = rep(1:ny, each = nx)) |
| 1256 |
> ggplot(df, aes(x, y, fill=diff)) + |
| 1257 |
+ geom_raster() + scale_fill_continuous_divergingx(palette = "Fall", rev = TRUE) + |
| 1258 |
+ coord_fixed(expand = FALSE) |
| 1259 |
> |
| 1260 |
> |
| 1261 |
> # adapted from stackoverflow: https://stackoverflow.com/a/20127706/4975218 |
| 1262 |
> |
| 1263 |
> # generate dataset and base plot |
| 1264 |
> set.seed(100) |
| 1265 |
> df <- data.frame(country = LETTERS, V = runif(26, -40, 40)) |
| 1266 |
> df$country = factor(LETTERS, LETTERS[order(df$V)]) # reorder factors |
| 1267 |
> gg <- ggplot(df, aes(x = country, y = V, fill = V)) + |
| 1268 |
+ geom_bar(stat = "identity") + |
| 1269 |
+ labs(y = "Under/over valuation in %", x = "Country") + |
| 1270 |
+ coord_flip() + theme_minimal() |
| 1271 |
> |
| 1272 |
> # plot with diverging scale "Geyser" |
| 1273 |
> gg + scale_fill_continuous_divergingx(palette = "Geyser") |
| 1274 |
> |
| 1275 |
> # plot with diverging scale "ArmyRose" |
| 1276 |
> gg + scale_fill_continuous_divergingx(palette = "ArmyRose") |
| 1277 |
> |
| 1278 |
> |
| 1279 |
> |
| 1280 |
> cleanEx() |
| 1281 |
|
| 1282 |
detaching ‘package:ggplot2’ |
| 1283 |
|
| 1284 |
> nameEx("scale_colour_continuous_qualitative") |
| 1285 |
> ### * scale_colour_continuous_qualitative |
| 1286 |
> |
| 1287 |
> flush(stderr()); flush(stdout()) |
| 1288 |
> |
| 1289 |
> ### Name: scale_colour_continuous_qualitative |
| 1290 |
> ### Title: HCL-Based Continuous Qualitative Color Scales for ggplot2 |
| 1291 |
> ### Aliases: scale_colour_continuous_qualitative |
| 1292 |
> ### scale_color_continuous_qualitative scale_fill_continuous_qualitative |
| 1293 |
> |
| 1294 |
> ### ** Examples |
| 1295 |
> |
| 1296 |
> library("ggplot2") |
| 1297 |
> |
| 1298 |
> # none of these examples are necessarily good ideas |
| 1299 |
> gg <- ggplot(iris, aes(x = Species, y = Sepal.Width, color = Sepal.Length)) + |
| 1300 |
+ geom_jitter(width = 0.3) + theme_minimal() |
| 1301 |
> |
| 1302 |
> gg + scale_color_continuous_qualitative(palette = "Warm") |
| 1303 |
> gg + scale_color_continuous_qualitative(palette = "Cold", l1 = 60) |
| 1304 |
> gg + scale_color_continuous_qualitative(palette = "Harmonic", rev = TRUE) |
| 1305 |
> |
| 1306 |
> nx = 87 |
| 1307 |
> ny = 61 |
| 1308 |
> df <- data.frame(height = c(volcano), x = rep(1:nx, ny), y = rep(1:ny, each = nx)) |
| 1309 |
> ggplot(df, aes(x, y, fill=height)) + |
| 1310 |
+ geom_raster() + scale_fill_continuous_qualitative(palette = "Dark 3") + |
| 1311 |
+ coord_fixed(expand = FALSE) |
| 1312 |
> |
| 1313 |
> |
| 1314 |
> |
| 1315 |
> cleanEx() |
| 1316 |
|
| 1317 |
detaching ‘package:ggplot2’ |
| 1318 |
|
| 1319 |
> nameEx("scale_colour_continuous_sequential") |
| 1320 |
> ### * scale_colour_continuous_sequential |
| 1321 |
> |
| 1322 |
> flush(stderr()); flush(stdout()) |
| 1323 |
> |
| 1324 |
> ### Name: scale_colour_continuous_sequential |
| 1325 |
> ### Title: HCL-Based Continuous Sequential Color Scales for ggplot2 |
| 1326 |
> ### Aliases: scale_colour_continuous_sequential |
| 1327 |
> ### scale_color_continuous_sequential scale_fill_continuous_sequential |
| 1328 |
> |
| 1329 |
> ### ** Examples |
| 1330 |
> |
| 1331 |
> library("ggplot2") |
| 1332 |
> |
| 1333 |
> # base plot |
| 1334 |
> gg <- ggplot(iris, aes(x = Species, y = Sepal.Width, color = Sepal.Length)) + |
| 1335 |
+ geom_jitter(width = 0.3) + theme_minimal() |
| 1336 |
> |
| 1337 |
> # default settings |
| 1338 |
> gg + scale_color_continuous_sequential() |
| 1339 |
> |
| 1340 |
> # switch palette and overwrite some default values |
| 1341 |
> gg + scale_color_continuous_sequential(palette = "Reds", l1 = 20, c2 = 70, p1 = 1) |
| 1342 |
> |
| 1343 |
> # select a range out of the entire palette |
| 1344 |
> gg + scale_color_continuous_sequential(palette = "Heat", begin = 0.2, end = 0.8) |
| 1345 |
> |
| 1346 |
> # volcano plot |
| 1347 |
> df <- data.frame(height = c(volcano), x = c(row(volcano)), y = c(col(volcano))) |
| 1348 |
> ggplot(df, aes(x, y, fill = height)) + |
| 1349 |
+ geom_raster() + scale_fill_continuous_sequential(palette = "Terrain", rev = FALSE) + |
| 1350 |
+ coord_fixed(expand = FALSE) |
| 1351 |
> |
| 1352 |
> |
| 1353 |
> |
| 1354 |
> cleanEx() |
| 1355 |
|
| 1356 |
detaching ‘package:ggplot2’ |
| 1357 |
|
| 1358 |
> nameEx("scale_colour_discrete_diverging") |
| 1359 |
> ### * scale_colour_discrete_diverging |
| 1360 |
> |
| 1361 |
> flush(stderr()); flush(stdout()) |
| 1362 |
> |
| 1363 |
> ### Name: scale_colour_discrete_diverging |
| 1364 |
> ### Title: HCL-Based Discrete Diverging Color Scales for ggplot2 |
| 1365 |
> ### Aliases: scale_colour_discrete_diverging scale_color_discrete_diverging |
| 1366 |
> ### scale_fill_discrete_diverging |
| 1367 |
> |
| 1368 |
> ### ** Examples |
| 1369 |
> |
| 1370 |
> library("ggplot2") |
| 1371 |
> |
| 1372 |
> # default colors with slightly darkened midpoint |
| 1373 |
> ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + |
| 1374 |
+ geom_point() + theme_minimal() + |
| 1375 |
+ scale_color_discrete_diverging(l2=75) |
| 1376 |
> |
| 1377 |
> # color scale "Green-Orange" |
| 1378 |
> ggplot(iris, aes(Sepal.Length, fill = Species)) + |
| 1379 |
+ geom_density(alpha = 0.7) + theme_classic() + |
| 1380 |
+ scale_fill_discrete_diverging(palette = "Green-Orange", rev = TRUE) |
| 1381 |
> |
| 1382 |
> # use `nmax` and `order` to skip some colors |
| 1383 |
> ggplot(iris, aes(Sepal.Length, fill = Species)) + |
| 1384 |
+ geom_density(alpha = 0.7) + theme_classic() + |
| 1385 |
+ scale_fill_discrete_diverging(palette = "Green-Orange", nmax = 5, order = c(1, 4, 5)) |
| 1386 |
> |
| 1387 |
> |
| 1388 |
> |
| 1389 |
> cleanEx() |
| 1390 |
|
| 1391 |
detaching ‘package:ggplot2’ |
| 1392 |
|
| 1393 |
> nameEx("scale_colour_discrete_divergingx") |
| 1394 |
> ### * scale_colour_discrete_divergingx |
| 1395 |
> |
| 1396 |
> flush(stderr()); flush(stdout()) |
| 1397 |
> |
| 1398 |
> ### Name: scale_colour_discrete_divergingx |
| 1399 |
> ### Title: HCL-Based Discrete Flexible Diverging Scales for ggplot2 |
| 1400 |
> ### Aliases: scale_colour_discrete_divergingx |
| 1401 |
> ### scale_color_discrete_divergingx scale_fill_discrete_divergingx |
| 1402 |
> |
| 1403 |
> ### ** Examples |
| 1404 |
> |
| 1405 |
> library("ggplot2") |
| 1406 |
> |
| 1407 |
> # default color scale |
| 1408 |
> ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + |
| 1409 |
+ geom_point() + theme_minimal() + |
| 1410 |
+ scale_color_discrete_divergingx() |
| 1411 |
> |
| 1412 |
> # color scale "Tropic" |
| 1413 |
> ggplot(iris, aes(Sepal.Length, fill = Species)) + |
| 1414 |
+ geom_density(alpha = 0.7) + theme_classic() + |
| 1415 |
+ scale_fill_discrete_divergingx(palette = "Tropic", rev = TRUE) |
| 1416 |
> |
| 1417 |
> # use `nmax` and `order` to skip some colors |
| 1418 |
> ggplot(iris, aes(Sepal.Length, fill = Species)) + |
| 1419 |
+ geom_density(alpha = 0.7) + theme_classic() + |
| 1420 |
+ scale_fill_discrete_divergingx(palette = "Tropic", nmax = 5, order = c(1, 4, 5)) |
| 1421 |
> |
| 1422 |
> |
| 1423 |
> |
| 1424 |
> cleanEx() |
| 1425 |
|
| 1426 |
detaching ‘package:ggplot2’ |
| 1427 |
|
| 1428 |
> nameEx("scale_colour_discrete_qualitative") |
| 1429 |
> ### * scale_colour_discrete_qualitative |
| 1430 |
> |
| 1431 |
> flush(stderr()); flush(stdout()) |
| 1432 |
> |
| 1433 |
> ### Name: scale_colour_discrete_qualitative |
| 1434 |
> ### Title: HCL-Based Discrete Qualitative Color Scales for ggplot2 |
| 1435 |
> ### Aliases: scale_colour_discrete_qualitative |
| 1436 |
> ### scale_color_discrete_qualitative scale_fill_discrete_qualitative |
| 1437 |
> |
| 1438 |
> ### ** Examples |
| 1439 |
> |
| 1440 |
> library("ggplot2") |
| 1441 |
> |
| 1442 |
> # default colors |
| 1443 |
> ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + |
| 1444 |
+ geom_point() + theme_minimal() + |
| 1445 |
+ scale_color_discrete_qualitative() |
| 1446 |
> |
| 1447 |
> # color scale "Harmonic" |
| 1448 |
> ggplot(iris, aes(Sepal.Length, fill = Species)) + |
| 1449 |
+ geom_density(alpha = 0.7) + scale_fill_discrete_qualitative(palette = "Harmonic") |
| 1450 |
> |
| 1451 |
> |
| 1452 |
> |
| 1453 |
> cleanEx() |
| 1454 |
|
| 1455 |
detaching ‘package:ggplot2’ |
| 1456 |
|
| 1457 |
> nameEx("scale_colour_discrete_sequential") |
| 1458 |
> ### * scale_colour_discrete_sequential |
| 1459 |
> |
| 1460 |
> flush(stderr()); flush(stdout()) |
| 1461 |
> |
| 1462 |
> ### Name: scale_colour_discrete_sequential |
| 1463 |
> ### Title: HCL-Based Discrete Sequential Color Scales for ggplot2 |
| 1464 |
> ### Aliases: scale_colour_discrete_sequential |
| 1465 |
> ### scale_color_discrete_sequential scale_fill_discrete_sequential |
| 1466 |
> |
| 1467 |
> ### ** Examples |
| 1468 |
> |
| 1469 |
> library("ggplot2") |
| 1470 |
> |
| 1471 |
> # default colors |
| 1472 |
> ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + |
| 1473 |
+ geom_point() + scale_color_discrete_sequential() + theme_classic() |
| 1474 |
> |
| 1475 |
> # customization of named palette |
| 1476 |
> ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + |
| 1477 |
+ geom_point() + scale_colour_discrete_sequential(palette = "Reds", nmax = 4, p2 = 1.5) + |
| 1478 |
+ theme_classic() |
| 1479 |
> |
| 1480 |
> # color scale "Terrain" |
| 1481 |
> ggplot(iris, aes(Sepal.Length, fill = Species)) + |
| 1482 |
+ geom_density(alpha = 0.7) + scale_fill_discrete_sequential(palette = "Terrain") + theme_minimal() |
| 1483 |
> |
| 1484 |
> |
| 1485 |
> |
| 1486 |
> cleanEx() |
| 1487 |
|
| 1488 |
detaching ‘package:ggplot2’ |
| 1489 |
|
| 1490 |
> nameEx("simulate_cvd") |
| 1491 |
> ### * simulate_cvd |
| 1492 |
> |
| 1493 |
> flush(stderr()); flush(stdout()) |
| 1494 |
> |
| 1495 |
> ### Name: simulate_cvd |
| 1496 |
> ### Title: Simulate Color Vision Deficiency |
| 1497 |
> ### Aliases: simulate_cvd deutan protan tritan interpolate_cvd_transform |
| 1498 |
> ### Keywords: colorblind colors cvd |
| 1499 |
> |
| 1500 |
> ### ** Examples |
| 1501 |
> |
| 1502 |
> # simulate color-vision deficiency by calling `simulate_cvd` with specified matrix |
| 1503 |
> simulate_cvd(c("#005000", "blue", "#00BB00"), tritanomaly_cvd["6"][[1]]) |
| 1504 |
[1] "#004F2C" "#0046D7" "#00B96F" |
| 1505 |
> |
| 1506 |
> # simulate color-vision deficiency by calling the shortcut high-level function |
| 1507 |
> tritan(c("#005000", "blue", "#00BB00"), severity = 0.6) |
| 1508 |
[1] "#004F2C" "#0046D7" "#00B96F" |
| 1509 |
> |
| 1510 |
> # simulate color-vision deficiency by calling `simulate_cvd` with interpolated cvd matrix |
| 1511 |
> simulate_cvd(c("#005000", "blue", "#00BB00"), |
| 1512 |
+ interpolate_cvd_transform(tritanomaly_cvd, severity = 0.6)) |
| 1513 |
[1] "#004F2C" "#0046D7" "#00B96F" |
| 1514 |
> |
| 1515 |
> # apply CVD directly on wide RGB matrix (with R/G/B channels in rows) |
| 1516 |
> RGB <- diag(3) * 255 |
| 1517 |
> rownames(RGB) <- c("R", "G", "B") |
| 1518 |
> deutan(RGB) |
| 1519 |
[,1] [,2] [,3] |
| 1520 |
R 93.66711 219.4647 0.00000 |
| 1521 |
G 71.42167 171.4878 12.09031 |
| 1522 |
B 0.00000 10.9497 247.06465 |
| 1523 |
> |
| 1524 |
> |
| 1525 |
> |
| 1526 |
> |
| 1527 |
> cleanEx() |
| 1528 |
> nameEx("specplot") |
| 1529 |
> ### * specplot |
| 1530 |
> |
| 1531 |
> flush(stderr()); flush(stdout()) |
| 1532 |
> |
| 1533 |
> ### Name: specplot |
| 1534 |
> ### Title: Color Spectrum Plot |
| 1535 |
> ### Aliases: specplot |
| 1536 |
> ### Keywords: hplot |
| 1537 |
> |
| 1538 |
> ### ** Examples |
| 1539 |
> |
| 1540 |
> ## spectrum of the (in)famous RGB rainbow palette (in both RGB and HCL) |
| 1541 |
> specplot(rainbow(100), rgb = TRUE) |
| 1542 |
> |
| 1543 |
> ## spectrum of HCL-based palettes: qualitative/sequential/diverging |
| 1544 |
> specplot(qualitative_hcl(100, "Set 2")) |
| 1545 |
> specplot(sequential_hcl(100, "Blues 2")) |
| 1546 |
> specplot(diverging_hcl(100, "Blue-Red")) |
| 1547 |
> |
| 1548 |
> ## return computed RGB and HCL coordinates |
| 1549 |
> res <- specplot(rainbow(10), plot = FALSE) |
| 1550 |
> print(res) |
| 1551 |
$HCL |
| 1552 |
H C L |
| 1553 |
[1,] 12.17395 179.04076 53.24059 |
| 1554 |
[2,] 39.43554 109.90223 72.26076 |
| 1555 |
[3,] 102.90782 109.54965 93.60562 |
| 1556 |
[4,] 126.52223 133.56847 88.07440 |
| 1557 |
[5,] 132.97247 118.65166 88.19667 |
| 1558 |
[6,] 192.16714 72.09794 91.11330 |
| 1559 |
[7,] 259.85512 127.32455 47.90415 |
| 1560 |
[8,] 267.22822 132.04235 33.81769 |
| 1561 |
[9,] 291.97946 133.06241 51.90335 |
| 1562 |
[10,] 346.98811 133.87809 55.65064 |
| 1563 |
|
| 1564 |
$RGB |
| 1565 |
R G B |
| 1566 |
[1,] 1.0 0.0 0.0 |
| 1567 |
[2,] 1.0 0.6 0.0 |
| 1568 |
[3,] 0.8 1.0 0.0 |
| 1569 |
[4,] 0.2 1.0 0.0 |
| 1570 |
[5,] 0.0 1.0 0.4 |
| 1571 |
[6,] 0.0 1.0 1.0 |
| 1572 |
[7,] 0.0 0.4 1.0 |
| 1573 |
[8,] 0.2 0.0 1.0 |
| 1574 |
[9,] 0.8 0.0 1.0 |
| 1575 |
[10,] 1.0 0.0 0.6 |
| 1576 |
|
| 1577 |
$hex |
| 1578 |
[1] "#FF0000" "#FF9900" "#CCFF00" "#33FF00" "#00FF66" "#00FFFF" "#0066FF" |
| 1579 |
[8] "#3300FF" "#CC00FF" "#FF0099" |
| 1580 |
|
| 1581 |
> |
| 1582 |
> |
| 1583 |
> |
| 1584 |
> cleanEx() |
| 1585 |
> nameEx("swatchplot") |
| 1586 |
> ### * swatchplot |
| 1587 |
> |
| 1588 |
> flush(stderr()); flush(stdout()) |
| 1589 |
> |
| 1590 |
> ### Name: swatchplot |
| 1591 |
> ### Title: Palette Swatch Plot |
| 1592 |
> ### Aliases: swatchplot |
| 1593 |
> ### Keywords: hplot |
| 1594 |
> |
| 1595 |
> ### ** Examples |
| 1596 |
> |
| 1597 |
> ## swatches of several palette vectors |
| 1598 |
> swatchplot( |
| 1599 |
+ "Hue" = sequential_hcl(5, h = c(0, 300), c = c(60, 60), l = 65), |
| 1600 |
+ "Chroma" = sequential_hcl(5, h = 0, c = c(100, 0), l = 65, rev = TRUE, power = 1), |
| 1601 |
+ "Luminance" = sequential_hcl(5, h = 260, c = c(25, 25), l = c(25, 90), rev = TRUE, power = 1), |
| 1602 |
+ off = 0 |
| 1603 |
+ ) |
| 1604 |
> |
| 1605 |
> ## swatches of named palette matrices |
| 1606 |
> bprg <- c("Blues", "Purples", "Reds", "Greens") |
| 1607 |
> swatchplot( |
| 1608 |
+ "Single-hue" = t(sapply(paste(bprg, 2), sequential_hcl, n = 7)), |
| 1609 |
+ "Single-hue (advanced)" = t(sapply(paste(bprg, 3), sequential_hcl, n = 7)), |
| 1610 |
+ "Multi-hue (advanced)" = t(sapply(bprg, sequential_hcl, n = 7)), |
| 1611 |
+ nrow = 5 |
| 1612 |
+ ) |
| 1613 |
> |
| 1614 |
> ## swatches with color vision deficiency emulation |
| 1615 |
> swatchplot(sequential_hcl(7, "Viridis"), cvd = TRUE) |
| 1616 |
> swatchplot( |
| 1617 |
+ "YlGnBu" = sequential_hcl(7, "YlGnBu"), |
| 1618 |
+ "Viridis" = sequential_hcl(7, "Viridis"), |
| 1619 |
+ cvd = c("deutan", "desaturate") |
| 1620 |
+ ) |
| 1621 |
> |
| 1622 |
> |
| 1623 |
> |
| 1624 |
> cleanEx() |
| 1625 |
> nameEx("whitepoint") |
| 1626 |
> ### * whitepoint |
| 1627 |
> |
| 1628 |
> flush(stderr()); flush(stdout()) |
| 1629 |
> |
| 1630 |
> ### Name: whitepoint |
| 1631 |
> ### Title: Access or Modify the Whitepoint |
| 1632 |
> ### Aliases: whitepoint |
| 1633 |
> ### Keywords: color |
| 1634 |
> |
| 1635 |
> ### ** Examples |
| 1636 |
> |
| 1637 |
> # query current whitepoint (D65 by default) |
| 1638 |
> whitepoint() |
| 1639 |
X Y Z |
| 1640 |
[1,] 95.047 100 108.883 |
| 1641 |
> |
| 1642 |
> # Illuminant E |
| 1643 |
> whitepoint(XYZ(100, 100, 100)) |
| 1644 |
> |
| 1645 |
> # equivalently |
| 1646 |
> whitepoint(100, 100, 100) |
| 1647 |
> whitepoint(c(100, 100, 100)) |
| 1648 |
> whitepoint(cbind(100, 100, 100)) |
| 1649 |
> |
| 1650 |
> whitepoint() |
| 1651 |
X Y Z |
| 1652 |
[1,] 100 100 100 |
| 1653 |
> |
| 1654 |
> ## reset |
| 1655 |
> whitepoint(NULL) |
| 1656 |
> whitepoint() |
| 1657 |
X Y Z |
| 1658 |
[1,] 95.047 100 108.883 |
| 1659 |
> |
| 1660 |
> |
| 1661 |
> |
| 1662 |
> cleanEx() |
| 1663 |
> nameEx("writehex") |
| 1664 |
> ### * writehex |
| 1665 |
> |
| 1666 |
> flush(stderr()); flush(stdout()) |
| 1667 |
> |
| 1668 |
> ### Name: writehex |
| 1669 |
> ### Title: Write Hexadecimal Color Descriptions |
| 1670 |
> ### Aliases: writehex |
| 1671 |
> ### Keywords: color |
| 1672 |
> |
| 1673 |
> ### ** Examples |
| 1674 |
> |
| 1675 |
> set.seed(1) |
| 1676 |
> x <- sRGB(runif(10), runif(10), runif(10)) |
| 1677 |
> ## IGNORE_RDIFF_BEGIN |
| 1678 |
> writehex(x, file.path(tempdir(), "random.txt")) |
| 1679 |
[1] "/tmp/RtmpcyMdPS/random.txt" |
| 1680 |
> ## IGNORE_RDIFF_END |
| 1681 |
> |
| 1682 |
> |
| 1683 |
> |
| 1684 |
> ### * <FOOTER> |
| 1685 |
> ### |
| 1686 |
> cleanEx() |
| 1687 |
> options(digits = 7L) |
| 1688 |
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") |
| 1689 |
Time elapsed: 8.482 0.084 8.567 0 0 |
| 1690 |
> grDevices::dev.off() |
| 1691 |
null device |
| 1692 |
1 |
| 1693 |
> ### |
| 1694 |
> ### Local variables: *** |
| 1695 |
> ### mode: outline-minor *** |
| 1696 |
> ### outline-regexp: "\\(> \\)?### [*]+" *** |
| 1697 |
> ### End: *** |
| 1698 |
> quit('no') |