| 1 |
## ----preliminaries, echo=FALSE, message=FALSE--------------------------------- |
| 2 |
library("colorspace") |
| 3 |
library("ggplot2") |
| 4 |
theme_set(theme_minimal()) |
| 5 |
prefix <- "https://colorspace.R-Forge.R-project.org/articles/" ## "" |
| 6 |
|
| 7 |
## ----hcl-properties, echo = FALSE, message = FALSE, warning = FALSE, fig.width = 4, fig.height = 2.2, fig.align = "center", dev = "png"---- |
| 8 |
swatchplot( |
| 9 |
"Hue" = sequential_hcl(5, h = c(0, 300), c = c(60, 60), l = 65), |
| 10 |
"Chroma" = sequential_hcl(5, h = 0, c = c(100, 0), l = 65, rev = TRUE, power = 1), |
| 11 |
"Luminance" = sequential_hcl(5, h = 260, c = c(25, 25), l = c(25, 90), rev = TRUE, power = 1), |
| 12 |
off = 0 |
| 13 |
) |
| 14 |
|
| 15 |
## ----installation-cran, eval=FALSE-------------------------------------------- |
| 16 |
# install.packages("colorspace") |
| 17 |
|
| 18 |
## ----installation-rforge, eval=FALSE------------------------------------------ |
| 19 |
# install.packages("colorspace", repos = "https://R-Forge.R-project.org") |
| 20 |
|
| 21 |
## ----hcl-palettes, message = FALSE, warning = FALSE, fig.align = "left", fig.height = 9, fig.width = 16, dpi = 48, out.width = "100%"---- |
| 22 |
library("colorspace") |
| 23 |
hcl_palettes(plot = TRUE) |
| 24 |
|
| 25 |
## ----qualitative-hcl-4-------------------------------------------------------- |
| 26 |
q4 <- qualitative_hcl(4, palette = "Dark 3") |
| 27 |
q4 |
| 28 |
|
| 29 |
## ----eustockmarkets, eval = FALSE--------------------------------------------- |
| 30 |
# plot(log(EuStockMarkets), plot.type = "single", col = q4, lwd = 2) |
| 31 |
# legend("topleft", colnames(EuStockMarkets), col = q4, lwd = 3, bty = "n") |
| 32 |
|
| 33 |
## ----eustockmarkets-plot, echo = FALSE, message = FALSE, warning = FALSE, fig.align = "left", fig.height = 4, fig.width = 6, dpi = 48, out.width = "100%"---- |
| 34 |
q4 <- qualitative_hcl(4) |
| 35 |
par(mar = c(5, 4, 1, 1)) |
| 36 |
plot(log(EuStockMarkets), plot.type = "single", col = q4, lwd = 2) |
| 37 |
legend("topleft", colnames(EuStockMarkets), col = q4, lwd = 3, bty = "n") |
| 38 |
|
| 39 |
## ----titanic, eval = FALSE---------------------------------------------------- |
| 40 |
# ttnc <- margin.table(Titanic, c(1, 4)) |
| 41 |
# spineplot(ttnc, col = sequential_hcl(2, palette = "Purples 3")) |
| 42 |
|
| 43 |
## ----titanic-plot, echo = FALSE, message = FALSE, warning = FALSE, fig.align = "left", fig.height = 4, fig.width = 6, dpi = 48, out.width = "100%"---- |
| 44 |
ttnc <- margin.table(Titanic, c(1, 4)) |
| 45 |
par(mar = c(5, 4, 1, 1)) |
| 46 |
spineplot(ttnc, col = sequential_hcl(2, "Purples 3")) |
| 47 |
|
| 48 |
## ----iris-ggplot, message = FALSE, warning = FALSE, fig.align = "left", fig.height = 4, fig.width = 6, dpi = 48, out.width = "100%"---- |
| 49 |
library("ggplot2") |
| 50 |
ggplot(iris, aes(x = Sepal.Length, fill = Species)) + geom_density(alpha = 0.6) + |
| 51 |
scale_fill_discrete_qualitative(palette = "Dark 3") |
| 52 |
|
| 53 |
## ----diamonds-ggplot, message = FALSE, warning = FALSE, fig.align = "left", fig.height = 4, fig.width = 6, dpi = 48, out.width = "100%"---- |
| 54 |
dsamp <- diamonds[1 + 1:1000 * 50, ] |
| 55 |
ggplot(dsamp, aes(carat, price, color = cut)) + geom_point() + |
| 56 |
scale_color_discrete_sequential(palette = "Purples 3", nmax = 6, order = 2:6) |
| 57 |
|
| 58 |
## ----visualiation-qualitative, eval = FALSE----------------------------------- |
| 59 |
# demoplot(q4, "bar") |
| 60 |
# hclplot(q4) |
| 61 |
# specplot(q4, type = "o") |
| 62 |
|
| 63 |
## ----allplots-qualitative, echo = FALSE, fig.height = 4.5, fig.width = 14, fig.align = "center", dev = "png", dpi = 48, out.width = "100%"---- |
| 64 |
allplots <- function(palette, ...) { |
| 65 |
layout(cbind(1, 2, 3:4), heights = c(2, 10)) |
| 66 |
par(oma = c(2, 5, 2, 3), mar = rep(0.5, 4)) |
| 67 |
demoplot(palette, ...) |
| 68 |
hclplot(palette) |
| 69 |
par(xaxt = "n", yaxt = "n", mar = c(0.2, 3, 0.2, 0), cex = 1) |
| 70 |
image(matrix(seq_along(palette), ncol = 1L), col = palette) |
| 71 |
par(yaxt = "s") |
| 72 |
specplot(palette, type = "o", palette = FALSE, oma = FALSE, mar = c(0.2, 3, 0.2, 0)) |
| 73 |
} |
| 74 |
allplots(q4, "bar") |
| 75 |
|
| 76 |
## ----visualization-sequential, eval = FALSE----------------------------------- |
| 77 |
# s9 <- sequential_hcl(9, "Purples 3") |
| 78 |
# demoplot(s9, "heatmap") |
| 79 |
# hclplot(s9) |
| 80 |
# specplot(s9, type = "o") |
| 81 |
|
| 82 |
## ----allplots-sequential, echo = FALSE, fig.height = 4.5, fig.width = 14, fig.align = "center", dev = "png", dpi = 48, out.width = "100%"---- |
| 83 |
s9 <- sequential_hcl(9, "Purples 3") |
| 84 |
allplots(s9, "heatmap") |
| 85 |
|