colorspace/0000755000175400001440000000000012131471105012572 5ustar zeileisuserscolorspace/MD50000644000175400001440000000361512131471105013107 0ustar zeileisusers565e7e39d8f1d7ece5ba51af1476de53 *DESCRIPTION 8356d81d3acea4ea672da7460af3d3b8 *NAMESPACE 5d53f964af4c14ace93b3b1f90370f44 *NEWS c6c875275843995d9248203492947030 *R/choose_palette.R 80515b1bd7ff7ff1c16e878da4707b4e *R/colorspace.R 10a677fb3fab53866727fc5993376399 *R/desaturate.R b7788dc1f7c99950911f1847ac6e8241 *R/palettes.R 3a283ed0d640d9c7b0760a1511f8c399 *data/USSouthPolygon.rda 2f81a499669b3966aef1d712f47eabb9 *inst/CITATION 5570f26f8ccc2e170c9ba90653c864d9 *inst/doc/hcl-colors.R 699d2594e53622a6c995d057150bb321 *inst/doc/hcl-colors.Rnw c502e371c3e66e6a7c0076e5db190b42 *inst/doc/hcl-colors.pdf db9d5f422710029852c85b7252875e15 *man/HLS.Rd 83d2c121d21919e319c2ef45a42c60c7 *man/HSV.Rd 17a8655e3d0150245fe6c3e366b7b859 *man/LAB.Rd a5e28e910a7efcb2edc858cc83fdd756 *man/LUV.Rd f81edfe81f2b7ba56c7e69c728e8803d *man/RGB.Rd 68ee370e967fb411055f83486ea9fb6b *man/USSouthPolygon.Rd f8cf179f4beaec7c9c0886dbe8362c1e *man/XYZ.Rd 3b9853af14eba79bda1a02a07046b79e *man/choose_palette.Rd a95c1d83aa72d7650e7c72bd58173b46 *man/color-class.Rd 697427e94cd84f974d2048f69d67c288 *man/coords.Rd 60ba73e731b4ce246224ae3d771b9d10 *man/desaturate.Rd 05a98bce053da27aea61296a394cd720 *man/hex.Rd a12b550bcdf2c719a99132b4683c96c5 *man/hex2RGB.Rd 84869c345ed5ee4e61fec49e1f8df9cd *man/mixcolor.Rd 4c01a5fd7e38dbc79499538de5cc8222 *man/polarLAB.Rd b2c936ba8346e188e0d86ba1899c4690 *man/polarLUV.Rd cfb5413117c4f41acae6ee5081e37da5 *man/rainbow_hcl.Rd 147ebd4fe4a1e8e3c1e19cc6bffaf26b *man/readRGB.Rd b6275a64f3eec4a08e58e5a6eb35601f *man/readhex.Rd 522ccf01a4815cbedb855878bc9ceb26 *man/sRGB.Rd b4625d7530ef5eb1177b2675681ad966 *man/writehex.Rd bd45219bdc0fb1283375105ceab84b12 *src/colorspace.c e81bcb1204076a8ceebf3dcc8790d1bf *tests/Examples/colorspace-Ex.Rout.save 31c484288b1a00186d42d3e04b2dfb2e *vignettes/color.bib 699d2594e53622a6c995d057150bb321 *vignettes/hcl-colors.Rnw 9708d048f12e5d18809e621317b53fc8 *vignettes/hcl-colors.Rout.save colorspace/vignettes/0000755000175400001440000000000012131470042014601 5ustar zeileisuserscolorspace/vignettes/hcl-colors.Rout.save0000644000175400001440000000760012077677107020505 0ustar zeileisusers > options(prompt = "R> ", continue = "+ ") > library("colorspace") > library("vcd") Loading required package: MASS Loading required package: grid > library("mvtnorm") > library("kernlab") > library("KernSmooth") KernSmooth 2.23 loaded Copyright M. P. Wand 1997-2009 > pal <- function(col, border = "light gray", ...) { + n <- length(col) + plot(0, 0, type = "n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, .... [TRUNCATED] > par(mfrow = c(2, 2), mar = c(0, 0, 3, 0)) > pal(rainbow_hcl(4, start = 30, end = 300), main = "dynamic") > pal(rainbow_hcl(4, start = 60, end = 240), main = "harmonic") > pal(rainbow_hcl(4, start = 270, end = 150), main = "cold") > pal(rainbow_hcl(4, start = 90, end = -30), main = "warm") > par(mfrow = c(5, 1), mar = c(0, 0, 0, 0)) > pal(sequential_hcl(12, c = 0, power = 2.2)) > pal(sequential_hcl(12, power = 2.2)) > pal(heat_hcl(12, c = c(80, 30), l = c(30, 90), power = c(1/5, + 2))) > pal(terrain_hcl(12, c = c(65, 0), l = c(45, 90), power = c(1/2, + 1.5))) > pal(rev(heat_hcl(12, h = c(0, -100), c = c(40, 80), + l = c(75, 40), power = 1))) > par(mfrow = c(4, 1), mar = c(0, 0, 0, 0)) > pal(diverge_hcl(7)) > pal(diverge_hcl(7, c = 100, l = c(50, 90), power = 1)) > pal(diverge_hcl(7, h = c(130, 43), c = 100, l = c(70, + 90))) > pal(diverge_hcl(7, h = c(180, 330), c = 59, l = c(75, + 95))) > seats <- structure(c(226, 61, 54, 51, 222), .Names = c("CDU/CSU", + "FDP", "Linke", "Gruene", "SPD")) > seats CDU/CSU FDP Linke Gruene SPD 226 61 54 51 222 > parties <- rainbow_hcl(6, c = 60, l = 75)[c(5, 2, + 6, 3, 1)] > names(parties) <- names(seats) > par(mar = rep(0.8, 4)) > pie(seats, clockwise = TRUE, col = parties, radius = 1) > data("Bundestag2005", package = "vcd") > votes <- Bundestag2005[c(1, 3:5, 9, 11, 13:16, 2, + 6:8, 10, 12), c("CDU/CSU", "FDP", "SPD", "Gruene", "Linke")] > mosaic(votes, gp = gpar(fill = parties[colnames(votes)]), + spacing = spacing_highlighting, labeling = labeling_left, + labeling_args = li .... [TRUNCATED] > library("KernSmooth") > data("geyser", package = "MASS") > dens <- bkde2D(geyser[, 2:1], bandwidth = c(0.2, 3), + gridsize = c(201, 201)) > par(mfrow = c(1, 2)) > image(dens$x1, dens$x2, dens$fhat, xlab = "duration", + ylab = "waiting time", col = rev(heat_hcl(33, c = 0, l = c(30, + 90), power = .... [TRUNCATED] > box() > image(dens$x1, dens$x2, dens$fhat, xlab = "duration", + ylab = "waiting time", col = rev(heat_hcl(33, c = c(80, 30), + l = c(30, 90), .... [TRUNCATED] > box() > library("KernSmooth") > geyser2 <- cbind(geyser$duration[-299], geyser$waiting[-1]) > dens2 <- bkde2D(geyser2, bandwidth = c(0.2, 3), gridsize = c(201, + 201)) > par(mfrow = c(1, 2)) > image(dens2$x1, dens2$x2, dens2$fhat, xlab = "duration", + ylab = "waiting time", col = rev(heat_hcl(33, c = 0, l = c(30, + 90), power .... [TRUNCATED] > box() > image(dens2$x1, dens2$x2, dens2$fhat, xlab = "duration", + ylab = "waiting time", col = rev(heat_hcl(33, c = c(80, 30), + l = c(30, 90 .... [TRUNCATED] > box() > art <- xtabs(~Treatment + Improved, data = Arthritis, + subset = Sex == "Female") > set.seed(1071) > mosaic(art, gp = shading_max, gp_args = list(n = 5000)) > library("mvtnorm") > set.seed(123) > x1 <- rmvnorm(75, mean = c(1.5, 1.5), sigma = matrix(c(1, + 0.8, 0.8, 1), ncol = 2)) > x2 <- rmvnorm(75, mean = c(-1, -1), sigma = matrix(c(1, + -0.3, -0.3, 1), ncol = 2)) > X <- rbind(x1, x2) > ex1 <- data.frame(class = factor(c(rep("a", 75), rep("b", + 75))), x1 = X[, 1], x2 = X[, 2]) > library("kernlab") > fm <- ksvm(class ~ ., data = ex1, C = 0.5) Using automatic sigma estimation (sigest) for RBF or laplace kernel > plot(fm, data = ex1) *** Run successfully completed *** > proc.time() user system elapsed 4.772 0.144 4.922 colorspace/vignettes/hcl-colors.Rnw0000644000175400001440000005067212077677107017374 0ustar zeileisusers\documentclass[nojss]{jss} %% need no \usepackage{Sweave} \SweaveOpts{engine=R, eps=FALSE, echo=FALSE, results=hide, keep.source = TRUE, pdf = TRUE, png = FALSE, resolution = 100} \title{HCL-Based Color Palettes in \proglang{R}} \Plaintitle{HCL-Based Color Palettes in R} \author{Achim Zeileis\\Universit\"at Innsbruck \And Kurt Hornik\\WU Wirtschafts-\\universit\"at Wien \And Paul Murrell\\The University\\of Auckland} \Plainauthor{Achim Zeileis, Kurt Hornik, Paul Murrell} \Keywords{HCL colors, qualitative palette, sequential palette, diverging palette} \Abstract{ The package \pkg{colorspace} provides various functions providing perceptually-based color palettes for coding categorical data (qualitative palettes) and numerical variables (sequential and diverging palettes). We illustrate how these functions can be employed to generate various flavours of these palettes (with different emphases) and how they can be plugged into \proglang{R} graphics functions. } \Address{ Achim Zeileis\\ Department of Statistics\\ Faculty of Economics and Statistics\\ Universit\"at Innsbruck\\ Universit\"atsstra{\ss}e~15\\ 6020 Innsbruck, Austria\\ E-mail: \email{Achim.Zeileis@R-project.org}\\ URL: \url{http://eeecon.uibk.ac.at/~zeileis/}\\ Kurt Hornik\\ Institute for Statistics and Mathematics\\ Department of Finance, Accounting and Statistics\\ WU Wirtschaftsuniversit\"at Wien\\ Augasse 2--6\\ 1090 Wien, Austria\\ E-mail: \email{Kurt.Hornik@R-project.org}\\ URL: \url{http://statmath.wu.ac.at/~hornik/}\\ Paul Murrell\\ Department of Statistics\\ The University of Auckland\\ Private Bag 92019\\ Auckland, New Zealand\\ E-mail: \email{paul@stat.auckland.ac.nz}\\ URL: \url{http://www.stat.auckland.ac.nz/~paul/} } \begin{document} %\VignetteIndexEntry{HCL-Based Color Palettes in R} %\VignetteDepends{colorspace,vcd,MASS,KernSmooth,mvtnorm,kernlab} %\VignetteKeywords{HCL colors, qualitative palette, sequential palette, diverging palette} %\VignettePackage{colorspace} <>= options(prompt = "R> ", continue = "+ ") library("colorspace") library("vcd") library("mvtnorm") library("kernlab") library("KernSmooth") @ \section{Introduction} \label{sec:intro} This is a companion vignette to \cite{color:Zeileis+Hornik+Murrell:2009} providing further technical details on the construction of the palettes as well as \proglang{R} code illustrating the use of varying palettes in practice. The palettes as well as some graphical functions demonstrated are contained in the package \pkg{colorspace}.\footnote{In addition to the discussion here, a graphical user interface for choosing colors based on the ideas of \cite{color:Zeileis+Hornik+Murrell:2009} is provided in the package as \code{choose\_palette()}.} As a simple convenience function we will use the function <>= pal <- function(col, border = "light gray", ...) { n <- length(col) plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "", ...) rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border) } @ which displays a set of colors using a sequence of shaded rectangles. In the remainder of this vignette, we first outline how different types of palettes can be constructed and generated using the tools from \pkg{colorspace}. Subsequently, we present a collection of examples illustrating the tools in practice. \pagebreak \section{Color palettes} \label{sec:palettes} \subsection{Qualitative palettes} \label{sec:qualitative} Qualitative palettes are sets of colors for depicting different categories, i.e., for coding a categorical variable. To give the same perceptual weight to each category, chroma and luminance are kept constant and only the hue is varied for obtaining different colors (which are consequently all balanced towards the same gray). In \pkg{colorspace}, qualitative palettes are implemented in the function \begin{Soutput} rainbow_hcl(n, c = 50, l = 70, start = 0, end = 360*(n-1)/n, ...) \end{Soutput} where \code{n} controls the number of colors in the palette. The arguments \code{c} and \code{l} give the fixed chroma and luminance levels, respectively, and \code{start} and \code{end} specify the range of hue angles. The function is named after the base \proglang{R} function \code{rainbow()} which has a similar interface but chooses colors in HSV coordinates. Figure~\ref{fig:pal-q-examples} depicts examples for generating qualitative sets of colors $(H, 50, 70)$ produced by <>= pal(rainbow_hcl(4, start = 30, end = 300), main = "dynamic") pal(rainbow_hcl(4, start = 60, end = 240), main = "harmonic") pal(rainbow_hcl(4, start = 270, end = 150), main = "cold") pal(rainbow_hcl(4, start = 90, end = -30), main = "warm") @ From left to right and top to down, this shows a palette from the full spectrum ($H = 30, 120, 210, 300$) creating a `dynamic' set of colors, a `harmonic' set with $H = 60, 120, 180, 240$, cold colors (from the blue/green part of the spectrum: $H = 270, 230, 190, 150$) and warm colors (from the yellow/red part of the spectrum: $H = 90, 50, 10, 330$), respectively. \setkeys{Gin}{width=0.75\textwidth} \begin{figure}[p!] \begin{center} <>= par(mfrow = c(2, 2), mar = c(0, 0, 3, 0)) <> @ \caption{\label{fig:pal-q-examples} Examples for qualitative palettes. Hue is varied in different intervals for given $C = 50$ and $L = 70$.} \end{center} \end{figure} \subsection{Sequential palettes} \label{sec:sequential} Sequential palettes are used for coding numerical information that ranges in a certain interval where low values are considered to be uninteresting and high values are interesting. Suppose we need to visualize an intensity or interestingness $i$ which (without loss of generality) is scaled to the unit interval. Potentially, all three dimensions of HCL space can be used for coding the intensity, leading to colors from an interval of hues (i.e., differing types of colors), an interval of chroma values (i.e., differing colorfulness) and an interval of luminance (i.e., differing intensity of gray). If we allow chroma and luminance to increase non-linearly via a function of type $i^p$, the resulting formula is: \[ (H_2 - i \cdot (H_1 - H_2), C_{\max} - i^{p_1} \cdot (C_{\max} - C_{\min}), L_{\max} - i^{p_2} \cdot (L_{\max} - L_{\min})). \] Two different ``flavors'' of this formula are readily implemented in \pkg{colorspace}, employing different defaults. For single hue palettes with $H_1 = H_2$ the function \begin{Soutput} sequential_hcl(n, h = 260, c = c(80, 0), l = c(30, 90), power = 1.5, ...) \end{Soutput} is provided where the first element of \code{c} and \code{l} give the starting chroma and luminance coordinate (by default colorful and dark) and the second element the ending coordinate (by default gray and light). The \code{power} argument implements the parameter $p$ from the $i^p$ function (and can be a vector of length 2). Sequential palettes using an interval of hues are provided by \begin{Soutput} heat_hcl(n, h = c(0, 90), c = c(100, 30), l = c(50, 90), power = c(1/5, 1), ...) \end{Soutput} named after the HSV-based \proglang{R} function \code{heat.colors()} and by default starts from a red and going to a yellow hue. The defaults in \code{heat_hcl()} are set differently compared to \code{sequential_hcl()} as to make the default HCL heat colors more similar to the HSV version. The defaults of \code{sequential_hcl()}, on the other hand, are set as to achieve a large contrast on the luminance axis. In addition \code{terrain_hcl()} is a wrapper for \code{heat_hcl()} producing colors similar to the HSV-based \code{terrain.colors()} from base \proglang{R}. Various palettes produced from these functions are shown in Figure~\ref{fig:pal-s-examples} using different pairs of hues as well as different chroma and luminance contrasts. <>= pal(sequential_hcl(12, c = 0, power = 2.2)) pal(sequential_hcl(12, power = 2.2)) pal(heat_hcl(12, c = c(80, 30), l = c(30, 90), power = c(1/5, 2))) pal(terrain_hcl(12, c = c(65, 0), l = c(45, 90), power = c(1/2, 1.5))) pal(rev(heat_hcl(12, h = c(0, -100), c = c(40, 80), l = c(75, 40), power = 1))) @ \setkeys{Gin}{width=.75\textwidth} \begin{figure}[p!] \begin{center} <>= par(mfrow = c(5, 1), mar = c(0, 0, 0, 0)) <> @ \caption{\label{fig:pal-s-examples} Examples for sequential palettes, varying only luminance (first panel), chroma and luminance (second panel), and hue, chroma and luminance (remaining panels).} \end{center} \end{figure} \subsection{Diverging palettes} \label{sec:diverging} Diverging palettes are also used for coding numerical information ranging in a certain interval---however, this interval includes a neutral value. Analogously to the previous section, we suppose that we want to visualize an intensity or interestingness $i$ from the interval $[-1, 1]$ (without loss of generality). Given useful sequential palettes, deriving diverging palettes is easy: two different hues are chosen for adding color to the same amount of `gray' at a given intensity $|i|$. Diverging palettes are implemented in the function \begin{Soutput} diverge_hcl(n, h = c(260, 0), c = 80, l = c(30, 90), power = 1.5, ...) \end{Soutput} which has the same arguments as \code{sequential_hcl()} but takes a pair of hues \code{h}. Figure~\ref{fig:pal-d-examples} shows various examples of conceivable combinations of hue, chroma and luminance. The first palette uses a broader range on the luminance axis whereas the others mostly rely on chroma contrasts. <>= pal(diverge_hcl(7)) pal(diverge_hcl(7, c = 100, l = c(50, 90), power = 1)) pal(diverge_hcl(7, h = c(130, 43), c = 100, l = c(70, 90))) pal(diverge_hcl(7, h = c(180, 330), c = 59, l = c(75, 95))) @ \setkeys{Gin}{width=.8\textwidth} \begin{figure}[t!] \begin{center} <>= par(mfrow = c(4, 1), mar = c(0, 0, 0, 0)) <> @ \caption{\label{fig:pal-d-examples} Examples for diverging palettes with different pairs of hues and decreasing luminance contrasts.} \end{center} \end{figure} \pagebreak \section{Illustrations} \label{sec:illustrations} \subsection{Qualitative palettes: Seats and votes in the German Bundestag} In this section, we show a collection of examples for the various types of palettes applied to statistical graphics. The first example illustrates qualitative palettes and visualizes data from the 2005 election for the German parliament ``Bundestag''. In this election, five parties were able to obtain enough votes to enter the Bundestag, the numbers of seats are given by <>= seats <- structure(c(226, 61, 54, 51, 222), .Names = c("CDU/CSU", "FDP", "Linke", "Gruene", "SPD")) seats @ We choose colors that are rough metaphors for the political parties, using a red hue $H = 0$ for the social democrats SPD, a blue hue $H = 240$ for the conservative CDU/CSU, a yellow hue $H = 60$ for the liberal FDP, a green hue $H = 120$ for the green party ``Die Gr\"unen'' and a purple hue $H = 300$ for the leftist party ``Die Linke''. To obtain rather intense colors, we set chroma to $C = 60$ and luminance to $L = 75$: <>= parties <- rainbow_hcl(6, c = 60, l = 75)[c(5, 2, 6, 3, 1)] names(parties) <- names(seats) @ The distribution of seats is depicted in a pie chart in Figure~\ref{fig:seats}. showing clearly that neither the governing coalition of SPD and Gr\"une nor the opposition of CDU/CSU and FDP could assemble a majority. Given that no party would enter a coalition with the leftists, this lead to a big coalition of CDU/CSU and SPD. <>= pie(seats, clockwise = TRUE, col = parties, radius = 1) @ \setkeys{Gin}{width=.6\textwidth} \begin{figure}[p] \begin{center} <>= par(mar = rep(0.8, 4)) <> @ \caption{\label{fig:seats} Seats in the German parliament.} \end{center} \end{figure} To take a closer look at the regional distribution, we load the \code{Bundestag2005} data set containing a contingency table with the number of votes for each party stratified by province (Bundesland). Then, we re-order the provinces from north to south, first the 10 western provinces (the former Federal Republic of Germany, FRG), then the 6 eastern provinces (the former German Democratic Republic, GDR). <>= data("Bundestag2005", package = "vcd") votes <- Bundestag2005[c(1, 3:5, 9, 11, 13:16, 2, 6:8, 10, 12), c("CDU/CSU", "FDP", "SPD", "Gruene", "Linke")] @ The data can then be visualized using a highlighted mosaic display via <>= mosaic(votes, gp = gpar(fill = parties[colnames(votes)])) @ The annotation for this plot is clearly sub-optimal, hence we use the flexible \code{strucplot()} framework provided by \pkg{vcd} and display the data via <>= mosaic(votes, gp = gpar(fill = parties[colnames(votes)]), spacing = spacing_highlighting, labeling = labeling_left, labeling_args = list(rot_labels = c(0, 90, 0, 0), varnames = FALSE, pos_labels = "center", just_labels = c("center", "center", "center", "right")), margins = unit(c(2.5, 1, 1, 12), "lines"), keep_aspect_ratio = FALSE) @ The output is shown in Figure~\ref{fig:votes} highlighting that the SPD performed better in the north and the CDU/CSU better in the south; furthermore, Die Linke performed particularly well in the eastern provinces and in Saarland. \setkeys{Gin}{width=.8\textwidth} \begin{figure}[p] \begin{center} <>= <> @ \caption{\label{fig:votes} Votes in the German election 2005.} \end{center} \end{figure} \subsection{Sequential palettes: Old Faithful geyser eruptions} To illustrate sequential palettes, a bivariate density estimation for the Old Faithful geyser eruptions data \code{geyser} from \pkg{MASS} is visualized. The Old Faithful geyser is one of the most popular sites in Yellowstone National Park and it is of some interest to understand the relation ship between the duration of a geyser eruption and the waiting time for this eruption. To look at the data, we use a bivariate kernel density estimate provided by the function \code{bkde2D()} from package \pkg{KernSmooth}. <>= library("KernSmooth") data("geyser", package = "MASS") dens <- bkde2D(geyser[,2:1], bandwidth = c(0.2, 3), gridsize = c(201, 201)) @ Subsequently, we look at the estimated kernel density by means of a heatmap (produced via \code{image()}) using two different sequential palettes: first with only gray colors <>= image(dens$x1, dens$x2, dens$fhat, xlab = "duration", ylab = "waiting time", col = rev(heat_hcl(33, c = 0, l = c(30, 90), power = c(1/5, 1.3)))) @ and then using heat colors balanced towards the sam gray levels as above <>= image(dens$x1, dens$x2, dens$fhat, xlab = "duration", ylab = "waiting time", col = rev(heat_hcl(33, c = c(80, 30), l = c(30, 90), power = c(1/5, 1.3)))) @ Figure~\ref{fig:bkde} shows the resulting heatmaps revealing a multi-modal bivariate distribution: short waiting times (around 50 minutes) are typically followed by a long eruption (around 4 minutes) whereas long waiting times (around 80 minutes) can be followed by either a long or short eruption (around 4 minutes). \setkeys{Gin}{width=\textwidth} \begin{figure}[t!] \begin{center} <>= par(mfrow = c(1, 2)) <> box() <> box() @ \caption{\label{fig:bkde} Bivariate density estimation for duration and waiting time for an eruption.} \end{center} \end{figure} Another interesting question in this data set would be ask how long the waiting time for the next eruption is following a short or long eruption respectively. This can be visualized using another bivarate density estimate for the transformed data set matching the previous duration with the following waiting time: <>= library("KernSmooth") geyser2 <- cbind(geyser$duration[-299], geyser$waiting[-1]) dens2 <- bkde2D(geyser2, bandwidth = c(0.2, 3), gridsize = c(201, 201)) @ Again, we look at this density using two heatmaps generated via <>= image(dens2$x1, dens2$x2, dens2$fhat, xlab = "duration", ylab = "waiting time", col = rev(heat_hcl(33, c = 0, l = c(30, 90), power = c(1/5, 1.3)))) @ and <>= image(dens2$x1, dens2$x2, dens2$fhat, xlab = "duration", ylab = "waiting time", col = rev(heat_hcl(33, c = c(80, 30), l = c(30, 90), power = c(1/5, 1.3)))) @ Figure~\ref{fig:bkde2} shows the result that illustrates that long and short waiting times follow long and short eruption durations, resepectively. \setkeys{Gin}{width=\textwidth} \begin{figure}[t!] \begin{center} <>= par(mfrow = c(1, 2)) <> box() <> box() @ \caption{\label{fig:bkde2} Bivariate density estimation for previous duration and following waiting time for an eruption.} \end{center} \end{figure} \subsection{Diverging palettes: Arthritis and SVM classification} Diverging palettes are particularly useful when visualizing residuals or correlations (with natural neutral value 0) or probabilities in 2-class supervised learning (with neutral value 0.5). Examples for both situations are provided here. First, we look at the outcome for the female patients from a double-blind clinical trial investigating a new treatment for rheumatoid arthritis. <>= art <- xtabs(~ Treatment + Improved, data = Arthritis, subset = Sex == "Female") @ For visualizing the data, we use a mosaic display with maximum shading \citep[as derived by][]{color:Zeileis+Meyer+Hornik:2007} via <>= set.seed(1071) mosaic(art, gp = shading_max, gp_args = list(n = 5000)) @ The mosaic rectangles in Figure~\ref{fig:arthritis} signal that the treatment lead to higher improvement compared to the placebo group; this effect is shown to be significant by the shading that codes the size of the Pearon residuals. Positive residuals, corresponding to more observations in the corresponding cell than expected under independence, are depicted in blue, negative residuals in red. Light colors signal significance at 10\% level, full colors significance at 1\% level. The palette implicitly used in this plot is \code{diverge_hcl(5, c = c(100, 0), l = c(50, 90), power = 1)}, it can be modified using the arguments of \code{shading_max()} which has an interface similar to \code{diverge_hcl()}. \setkeys{Gin}{width=.7\textwidth} \begin{figure}[p] \begin{center} <>= <> @ \caption{\label{fig:arthritis} Extended mosaic display for arthritis data.} \end{center} \end{figure} To illustrate the use of diverging palettes in 2-class classification, we generate some artificial date from a mixture of two bivariate normal distributions with different means and covariance matrices. The data are generated using \pkg{mvtnorm} and collected in a data frame \code{ex1}: <>= library("mvtnorm") set.seed(123) x1 <- rmvnorm(75, mean = c(1.5, 1.5), sigma = matrix(c(1, 0.8, 0.8, 1), ncol = 2)) x2 <- rmvnorm(75, mean = c(-1, -1), sigma = matrix(c(1, -0.3, -0.3, 1), ncol = 2)) X <- rbind(x1, x2) ex1 <- data.frame(class = factor(c(rep("a", 75), rep("b", 75))), x1 = X[,1], x2 = X[,2]) @ We fit a support vector machine (SVM) with a radial basis function kernel to this data set, using the function \code{ksvm()} from \pkg{kernlab} <>= library("kernlab") fm <- ksvm(class ~ ., data = ex1, C = 0.5) @ which can subsequently be easily visualized via <>= plot(fm, data = ex1) @ The resulting plot in Figure~\ref{fig:class} shows a heatmap with the fit of the SVM. The circles and triangles show the original observations, solid symbols correspond to the support vectors found. The shading underlying the plot visualizes the fitted decision values: values around 0 are on the decision boundary and are shaded in light gray, while regions that are firmly classified to one or the other class are shaded in full blue and red respectively. The palette used by the \code{plot()} method for \code{ksvm} objects cannot be easily modified---however, the colors employed are equivalent to \code{diverge_hcl(n, c = c(100, 0), l = c(50, 90), power = 1.3)}. \setkeys{Gin}{width=.7\textwidth} \begin{figure}[p] \begin{center} <>= <> @ \caption{\label{fig:class} SVM classification plot.} \end{center} \end{figure} \bibliography{color} \end{document} colorspace/vignettes/color.bib0000644000175400001440000004221412077677107016424 0ustar zeileisusers%%% three blocks of entries: color, software, examples, own %% color @Misc{color:Pascale:2003, author = {Danny Pascale}, title = {A Review of {RGB} Color Spaces ... from xyY to R'G'B'}, year = {2003}, howpublished = {URL \url{http://www.babelcolor.com/download/A%20review%20of%20RGB%20color%20spaces.pdf}, accessed 2007-11-22} } @Misc{color:Ford+Roberts:1998, author = {Adrian Ford and Alan Roberts}, title = {Colour Space Conversions}, year = {1998}, howpublished = {URL \url{http://www.poynton.com/PDFs/coloureq.pdf}, accessed 2007-11-22} } @Misc{color:Lindbloom:2003, author = {Bruce Lindbloom}, title = {BruceLindbloom.com}, year = {2003}, howpublished = {URL \url{http://www.BruceLindbloom.com/}, accessed 2007-11-22} } @Misc{color:Poynton:2000, author = {Charles Poynton}, title = {Frequently-Asked Questions About Color}, year = {2000}, howpublished = {URL \url{http://www.poynton.com/ColorFAQ.html}, accessed 2007-11-06} } @Misc{color:Wiki+CIEXYZ:2007, author = {Wikipedia}, title = {{CIE} 1931 Color Space --- {W}ikipedia{,} The Free Encyclopedia}, year = {2007}, howpublished = {URL \url{http://en.wikipedia.org/wiki/CIE_1931_color_space}, accessed 2007-11-06} } @Misc{color:Wiki+CIELUV:2007, author = {Wikipedia}, title = {{CIELUV} Color Space --- {W}ikipedia{,} The Free Encyclopedia}, year = {2007}, howpublished = {URL \url{http://en.wikipedia.org/wiki/CIELUV_color_space}, accessed 2007-11-06} } @Misc{color:Wiki+CIELAB:2007, author = {Wikipedia}, title = {{Lab} Color Space --- {W}ikipedia{,} The Free Encyclopedia}, year = {2007}, howpublished = {URL \url{http://en.wikipedia.org/wiki/Lab_color_space}, accessed 2007-11-06} } @Misc{color:Wiki+HSV:2007, author = {Wikipedia}, title = {{HSV} Color Space --- {W}ikipedia{,} The Free Encyclopedia}, year = {2007}, howpublished = {URL \url{http://en.wikipedia.org/wiki/HSV_color_space}, accessed 2007-11-06} } @Misc{color:Wiki+RGB:2007, author = {Wikipedia}, title = {{RGB} Color Model --- {W}ikipedia{,} The Free Encyclopedia}, year = {2007}, howpublished = {URL \url{http://en.wikipedia.org/wiki/RGB_color_model}, accessed 2007-11-06} } @InProceedings{color:Brewer:1999, author = {Cynthia A. Brewer}, title = {Color Use Guidelines for Data Representation}, booktitle = {Proceedings of the Section on Statistical Graphics, American Statistical Association}, address = {Alexandria, VA}, year = {1999}, pages = {55--60}, url = {http://www.personal.psu.edu/faculty/c/a/cab38/ColorSch/ASApaper.html} } @Article{color:Lumley:2006, author = {Thomas Lumley}, title = {Color Coding and Color Blindness in Statistical Graphics}, journal = {ASA Statistical Computing \& Graphics Newsletter}, year = {2006}, volume = {17}, number = {2}, pages = {4--7}, url = {http://stat-computing.org/newletter/issues/scgn-17-2.pdf} } @InProceedings{color:Ihaka:2003, author = {Ross Ihaka}, title = {Colour for Presentation Graphics}, booktitle = {Proceedings of the 3rd International Workshop on Distributed Statistical Computing, Vienna, Austria}, editor = {Kurt Hornik and Friedrich Leisch and Achim Zeileis}, year = {2003}, url = {http://www.ci.tuwien.ac.at/Conferences/DSC-2003/Proceedings/}, note = {{ISSN 1609-395X}}, } @Book{color:Munsell:1905, author = {Albert H. Munsell}, title = {A Color Notation}, publisher = {Munsell Color Company}, year = {1905}, address = {Boston, Massachusetts} } @Book{color:Kaiser+Boynton:1996, author = {Peter K. Kaiser and Robert M. Boynton}, title = {Human Color Vision}, publisher = {Optical Society of America}, year = {1996}, edition = {2nd}, address = {Washington, DC} } @Article{color:Harrower+Brewer:2003, author = {Mark A. Harrower and Cynthia A. Brewer}, title = {\textbf{ColorBrewer.org}: An Online Tool for Selecting Color Schemes for Maps}, journal = {The Cartographic Journal}, year = {2003}, volume = {40}, pages = {27--37}, url = {http://ColorBrewer.org/} } @Article{color:Cleveland+McGill:1983, author = {William S. Cleveland and Robert McGill}, title = {A Color-Caused Optical Illusion on a Statistical Graph}, journal = {The American Statistician}, year = {1983}, volume = {37}, pages = {101--105} } @Book{color:Tufte:1990, author = {Edward R. Tufte}, title = {Envisioning Information}, year = {1990}, publisher = {Graphics Press}, address = {Cheshire, CT} } @Book{color:CIE:2004, author = {{Commission Internationale de l'\'Eclairage}}, title = {Colorimetry}, edition = {3rd}, publisher = {Publication CIE 15:2004}, address = {Vienna, Austria}, year = {2004}, note = {{ISBN} 3-901-90633-9} } @InProceedings{color:Moretti+Lyons:2002, author = {Giovanni Moretti and Paul Lyons}, title = {Tools for the Selection of Colour Palettes}, booktitle = {Proceedings of the New Zealand Symposium On Computer-Human Interaction (SIGCHI 2002)}, address = {University of Waikato, New Zealand}, month = {July}, year = {2002} } @Article{color:MacAdam:1942, author = {D. L. MacAdam}, title = {Visual Sensitivities to Color Differences in Daylight}, journal = {Journal of the Optical Society of America}, year = {1942}, volume = {32}, number = {5}, pages = {247--274}, } @Book{color:Wyszecki+Stiles:2000, author = {G\"unter Wyszecki and W. S. Stiles}, title = {Color Science}, edition = {2nd}, publisher = {Wiley}, year = {2000}, note = {{ISBN} 0-471-39918-3} } @Article{color:Smith:1978, author = {Alvy Ray Smith}, title = {Color Gamut Transform Pairs}, journal = {Computer Graphics}, pages = {12--19}, year = {1978}, volume = {12}, number = {3}, note = {ACM SIGGRAPH 78 Conference Proceedings}, url = {http://www.alvyray.com/}, } @Article{color:Meier+Spalter+Karelitz:2004, author = {Barbara J. Meier and Anne Morgan Spalter and David B. Karelitz}, title = {Interactive Color Palette Tools}, journal = {{IEEE} Computer Graphics and Applications}, volume = {24}, number = {3}, year = {2004}, pages = {64--72}, url = {http://graphics.cs.brown.edu/research/color/} } @InCollection{color:Mollon:1995, author = {J. Mollon}, editor = {T. Lamb and J. Bourriau}, booktitle = {Colour: Art and Science}, title = {Seeing Color}, publisher = {Cambridge Univesity Press}, year = 1995 } @InCollection{color:Knoblauch:2002, author = {Kenneth Knoblauch}, title = {Color Vision}, booktitle = {Steven's Handbook of Experimental Psychology -- Sensation and Perception}, editor = {Steven Yantis and Hal Pashler}, year = {2002}, edition = {Third}, volume = {1}, publisher = {John Wiley \& Sons}, address = {New York}, pages = {41--75} } @Article{color:Levkowitz+Herman:1992, author = {Haim Levkowitz and Gabor T. Herman}, title = {Color Scales for Image Data}, journal = {IEEE Computer Graphics and Applications}, year = {1992}, volume = {12}, number = {1}, pages = {72--80}, doi = {10.1109/38.135886}, } @Article{color:Ware:1988, author = {Colin Ware}, title = {Color Sequences for Univariate Maps: Theory, Experiments and Principles}, journal = {IEEE Computer Graphics and Applications}, year = {1988}, volume = {8}, number = {5}, pages = {41--49}, doi = {10.1109/38.7760}, } @Article{color:Zhang+Montag:2006, author = {Hongqin Zhang and Ethan D. Montag}, title = {How Well Can People Use Different Color Attributes?}, journal = {Color Research \& Application}, year = {2006}, volume = {31}, number = {6}, pages = {445--457}, doi = {10.1002/col.20257}, } @Article{color:Robertson+OCallaghan:1988, author = {Philip Robertson and John O'Callaghan}, title = {The Generation of Color Sequences for Univariate and Bivariate Mapping}, journal = {IEEE Computer Graphics and Applications}, year = {1986}, volume = {6}, number = {2}, pages = {24--32}, doi = {10.1109/MCG.1986.276688}, } @Article{color:Trumbo:1981, author = {Bruce E. Trumbo}, title = {A Theory for Coloring Bivariate Statistical Maps}, journal = {The American Statistician}, year = {1981}, volume = {35}, number = {4}, pages = {220--226} } @Article{color:Christ:1975, author = {Richard E. Christ}, title = {Review and Analysis of Color Coding Research for Visual Displays}, journal = {Human Factors}, year = {1975}, volume = {17}, number = {6}, pages = {542--570} } @Article{color:, author = {Allen L. Nagy and Robert R. Sanchez}, title = {Chromaticity and Luminance as Coding Dimensions in Visual Search}, journal = {Human Factors}, year = {1992}, volume = {34}, number = {5}, pages = {601--614} } %% software @Manual{color:R:2007, title = {\textsf{R}: {A} Language and Environment for Statistical Computing}, author = {{\textsf{R} Development Core Team}}, organization = {\textsf{R} Foundation for Statistical Computing}, address = {Vienna, Austria}, year = {2007}, note = {{ISBN} 3-900051-07-0}, url = {http://www.R-project.org/} } @Manual{color:R:2008, title = {\textsf{R}: {A} Language and Environment for Statistical Computing}, author = {{\textsf{R} Development Core Team}}, organization = {\textsf{R} Foundation for Statistical Computing}, address = {Vienna, Austria}, year = {2008}, note = {{ISBN} 3-900051-07-0}, url = {http://www.R-project.org/} } @Article{color:Murrell:2002, author = {Paul Murrell}, title = {The \textbf{grid} Graphics Package}, journal = {\textsf{R} News}, year = {2002}, volume = {2}, number = {2}, pages = {14--19}, month = {June}, url = {http://CRAN.R-project.org/doc/Rnews/} } @Book{color:Murrell:2006, author = {Paul Murrell}, title = {\textsf{R} Graphics}, publisher = {Chapman \& Hall/CRC}, address = {Boca Raton, Florida}, year = {2006}, } @Manual{color:Ihaka:2006, title = {\textbf{colorspace}: Colorspace Manipulation}, author = {Ross Ihaka}, year = {2006}, note = {\textsf{R}~package version~0.95}, url = {http://CRAN.R-project.org/package=colorspace} } @Manual{color:Ihaka+Murrell+Hornik+Zeileis:2008, title = {\textbf{colorspace}: Color Space Manipulation}, author = {Ross Ihaka and Paul Murrell and Kurt Hornik and Achim Zeileis}, year = {2008}, note = {\textsf{R}~package version~1.0-0}, url = {http://CRAN.R-project.org/package=colorspace} } @Manual{color:Meyer+Zeileis+Hornik:2008, title = {\textbf{vcd}: Visualizing Categorical Data}, author = {David Meyer and Achim Zeileis and Kurt Hornik}, year = {2008}, note = {\textsf{R}~package version~1.1-2}, url = {http://CRAN.R-project.org/package=vcd} } @Manual{color:Lumley:2007, title = {\textbf{dichromat}: Color Schemes for Dichromats}, author = {Thomas Lumley}, year = {2007}, note = {\textsf{R}~package version~1.2-2}, url = {http://CRAN.R-project.org/package=dichromat} } @Manual{color:Wickham:2008, title = {\textbf{ggplot2}: An Implementation of the {G}rammar of {G}raphics}, author = {Hadley Wickham}, year = {2008}, note = {\textsf{R}~package version~0.7}, url = {http://CRAN.R-project.org/package=ggplot2} } %% examples @Article{color:Kneib:2006, author = {Thomas Kneib}, title = {Mixed Model-Based Inference in Geoadditive Hazard Regression for Interval-censored Survival Times}, year = {2006}, journal = {Computational Statistics \& Data Analysis}, volume = {51}, pages = {777--792}, doi = {10.1016/j.csda.2006.06.019}, note = {Figure~5 (left)} } @Article{color:Harezlak+Coull+Laird:2007, author = {Jaroslaw Harezlak and Brent A. Coull and Nan M. Laird and Shannon R. Magari and David C. Christiani}, title = {Penalized Solutions to Functional Regression Problems}, year = {2007}, journal = {Computational Statistics \& Data Analysis}, volume = {51}, pages = {4911--4925}, doi = {10.1016/j.csda.2006.09.034}, note = {Figure~8} } @Article{color:Tenenhaus+Giron+Viennet:2007, author = {Arthur Tenenhaus and Alain Giron and Emmanuel Viennet and Michel B{\'e}ra and Gilbert Saporta and Bernard Fertil}, title = {Kernel Logistic {PLS}: A Tool for Supervised Nonlinear Dimensionality Reduction and Binary Classification}, year = {2007}, journal = {Computational Statistics \& Data Analysis}, volume = {51}, pages = {4083--4100}, doi = {10.1016/j.csda.2007.01.004}, note = {Figure~2} } @Article{color:Gelfand+Banerjee+Sirmans:2007, author = {Alan E. Gelfand and Sudipto Banerjee and C. F. Sirmans and Yong Tu and Seow Eng Ong}, title = {Multilevel Modeling Using Spatial Processes: Application to the {S}ingapore Housing Market}, year = {2007}, journal = {Computational Statistics \& Data Analysis}, volume = {51}, pages = {3567--3579}, doi = {10.1016/j.csda.2006.11.019}, note = {Figure~3} } @Article{color:Gneiting+Sevcikova+Percival:2006, author = {Tilmann Gneiting and Hana \v{S}ev\v{c}\'ikov\'a and Donald B. Percival and Martin Schlather and Yindeng Jiang}, title = {Fast and Exact Simulation of Large Gaussian Lattice Systems in {$\mathbb{R}^2$}: Exploring the Limits}, year = {2006}, journal = {Journal of Computational and Graphical Statistics}, volume = {15}, number = {3}, pages = {483--501}, doi = {10.1198/106186006X128551}, note = {Figures~1--4} } @Article{color:Yang+Buckley+Dudoit:2002, author = {Yee Hwa Yang and Michael J. Buckley and Sandrine Dudoit and Terence P. Speed}, title = {Comparison of Methods for Image Analysis on {cDNA} Microarray Data}, year = {2002}, journal = {Journal of Computational and Graphical Statistics}, volume = {11}, number = {1}, pages = {108--136}, note = {Figure~4a} } @Article{color:Friendly:2002, author = {Michael Friendly}, title = {A Brief History of the Mosaic Display}, year = {2002}, journal = {Journal of Computational and Graphical Statistics}, volume = {11}, number = {1}, pages = {89--107}, note = {Figure~11 (left, middle)} } @Article{color:Celeux+Hurn+Robert:2000, author = {Gilles Celeux and Merrilee Hurn and Christian P. Robert}, title = {Computational and Inferential Difficulties with Mixture Posterior Distributions}, year = {2000}, journal = {Journal of the American Statistical Association}, volume = {95}, number = {451}, pages = {957--970}, note = {Figure~3} } @Article{color:Azzalini+Bowman:1990, author = {A. Azzalini and A. W. Bowman}, title = {A Look at Some Data on the {O}ld {F}aithful Geyser}, journal = {Applied Statistics}, year = {1990}, volume = {39}, pages = {357--365}, } %% own @Article{color:Zeileis+Meyer+Hornik:2007, author = {Achim Zeileis and David Meyer and Kurt Hornik}, title = {Residual-Based Shadings for Visualizing (Conditional) Independence}, journal = {Journal of Computational and Graphical Statistics}, year = {2007}, volume = {16}, number = {3}, pages = {507--525}, doi = {10.1198/106186007X237856} } @Article{color:Meyer+Zeileis+Hornik:2006, author = {David Meyer and Achim Zeileis and Kurt Hornik}, title = {The Strucplot Framework: Visualizing Multi-way Contingency Tables with \textbf{vcd}}, year = {2006}, journal = {Journal of Statistical Software}, volume = {17}, number = {3}, pages = {1--48}, url = {http://www.jstatsoft.org/v17/i03/} } @InCollection{color:Meyer+Zeileis+Hornik:2008a, author = {David Meyer and Achim Zeileis and Kurt Hornik}, title = {Visualizing Contingency Tables}, editor = {Chun-Houh Chen and Wolfang H\"ardle and Antony Unwin}, booktitle = {Handbook of Data Visualization}, series = {Springer Handbooks of Computational Statistics}, year = {2008}, pages = {589--616}, publisher = {Springer-Verlag}, address = {New York}, note = {{ISBN} 978-3-540-33036-3} } @TechReport{color:Zeileis+Hornik:2006, author = {Achim Zeileis and Kurt Hornik}, title = {Choosing Color Palettes for Statistical Graphics}, institution = {Department of Statistics and Mathematics, Wirtschaftsuniversit\"at Wien, Research Report Series}, year = {2006}, type = {Report}, number = {41}, month = {October}, url = {http://epub.wu-wien.ac.at/} } @TechReport{color:Zeileis+Hornik+Murrell:2007, author = {Achim Zeileis and Kurt Hornik and Paul Murrell}, title = {Escaping {RGB}land: Selecting Colors for Statistical Graphics}, institution = {Department of Statistics and Mathematics, Wirtschaftsuniversit\"at Wien, Research Report Series}, year = {2007}, type = {Report}, number = {61}, month = {November}, url = {http://epub.wu-wien.ac.at/} } @Article{color:Zeileis+Hornik+Murrell:2009, author = {Achim Zeileis and Kurt Hornik and Paul Murrell}, title = {Escaping {RGB}land: Selecting Colors for Statistical Graphics}, journal = {Computational Statistics \& Data Analysis}, year = {2009}, volume = {53}, pages = {3259--3270}, doi = {10.1016/j.csda.2008.11.033} } colorspace/tests/0000755000175400001440000000000012131470042013733 5ustar zeileisuserscolorspace/tests/Examples/0000755000175400001440000000000012131470042015511 5ustar zeileisuserscolorspace/tests/Examples/colorspace-Ex.Rout.save0000644000175400001440000003414212131470020022025 0ustar zeileisusers R version 3.0.0 (2013-04-03) -- "Masked Marvel" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > pkgname <- "colorspace" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('colorspace') > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > cleanEx() > nameEx("HLS") > ### * HLS > > flush(stderr()); flush(stdout()) > > ### Name: HLS > ### Title: Create HLS Colors > ### Aliases: HLS > ### Keywords: color > > ### ** Examples > > # A rainbow of full-intensity hues > HLS(seq(0, 360, length=13)[-13], 0.5, 1) H L S [1,] 0 0.5 1 [2,] 30 0.5 1 [3,] 60 0.5 1 [4,] 90 0.5 1 [5,] 120 0.5 1 [6,] 150 0.5 1 [7,] 180 0.5 1 [8,] 210 0.5 1 [9,] 240 0.5 1 [10,] 270 0.5 1 [11,] 300 0.5 1 [12,] 330 0.5 1 > > > > cleanEx() > nameEx("HSV") > ### * HSV > > flush(stderr()); flush(stdout()) > > ### Name: HSV > ### Title: Create HSV Colors > ### Aliases: HSV > ### Keywords: color > > ### ** Examples > > # A rainbow of full-intensity hues > HSV(seq(0, 360, length=13)[-13], 1, 1) H S V [1,] 0 1 1 [2,] 30 1 1 [3,] 60 1 1 [4,] 90 1 1 [5,] 120 1 1 [6,] 150 1 1 [7,] 180 1 1 [8,] 210 1 1 [9,] 240 1 1 [10,] 270 1 1 [11,] 300 1 1 [12,] 330 1 1 > > > > cleanEx() > nameEx("LAB") > ### * LAB > > flush(stderr()); flush(stdout()) > > ### Name: LAB > ### Title: Create LAB Colors > ### Aliases: LAB > ### Keywords: color > > ### ** Examples > > ## Show the LAB space > set.seed(1) > x <- RGB(runif(1000), runif(1000), runif(1000)) > y <- as(x, "LAB") > head(x) R G B [1,] 0.2655087 0.5308088 0.871805 > head(y) L A B [1,] 76.00763 -4.987872 -28.84153 > plot(y) > > > > cleanEx() > nameEx("LUV") > ### * LUV > > flush(stderr()); flush(stdout()) > > ### Name: LUV > ### Title: Create LUV Colors > ### Aliases: LUV > ### Keywords: color > > ### ** Examples > > ## Show the LUV space > set.seed(1) > x <- RGB(runif(1000), runif(1000), runif(1000)) > y <- as(x, "LUV") > head(x) R G B [1,] 0.2655087 0.5308088 0.871805 > head(y) L U V [1,] 76.00763 -25.7427 -45.3886 > plot(y) > > > > cleanEx() > nameEx("RGB") > ### * RGB > > flush(stderr()); flush(stdout()) > > ### Name: RGB > ### Title: Create RGB Colors > ### Aliases: RGB > ### Keywords: color > > ### ** Examples > > # Create a random set of colors > set.seed(1) > RGB(R = runif(20), G = runif(20), B = runif(20)) R G B [1,] 0.26550866 0.93470523 0.82094629 [2,] 0.37212390 0.21214252 0.64706019 [3,] 0.57285336 0.65167377 0.78293276 [4,] 0.90820779 0.12555510 0.55303631 [5,] 0.20168193 0.26722067 0.52971958 [6,] 0.89838968 0.38611409 0.78935623 [7,] 0.94467527 0.01339033 0.02333120 [8,] 0.66079779 0.38238796 0.47723007 [9,] 0.62911404 0.86969085 0.73231374 [10,] 0.06178627 0.34034900 0.69273156 [11,] 0.20597457 0.48208012 0.47761962 [12,] 0.17655675 0.59956583 0.86120948 [13,] 0.68702285 0.49354131 0.43809711 [14,] 0.38410372 0.18621760 0.24479728 [15,] 0.76984142 0.82737332 0.07067905 [16,] 0.49769924 0.66846674 0.09946616 [17,] 0.71761851 0.79423986 0.31627171 [18,] 0.99190609 0.10794363 0.51863426 [19,] 0.38003518 0.72371095 0.66200508 [20,] 0.77744522 0.41127443 0.40683019 > > > > cleanEx() > nameEx("USSouthPolygon") > ### * USSouthPolygon > > flush(stderr()); flush(stdout()) > > ### Name: USSouthPolygon > ### Title: Polygon for County Map of US South States: Alabama, Georgia, and > ### South Carolina > ### Aliases: USSouthPolygon > ### Keywords: datasets > > ### ** Examples > > ## generate color palette > pal <- diverge_hcl(9) > n <- length(pal) > > ## draw shaded polygons > plot(0, 0, type = "n", xlab = "", ylab = "", xaxt = "n", yaxt = "n", bty = "n", + xlim = c(-88.5, -78.6), ylim = c(30.2, 35.2), asp = 1) > polygon(USSouthPolygon, col = pal[cut(na.omit(USSouthPolygon$z), breaks = 0:n/n)]) > > > > cleanEx() > nameEx("XYZ") > ### * XYZ > > flush(stderr()); flush(stdout()) > > ### Name: XYZ > ### Title: Create XYZ Colors > ### Aliases: XYZ > ### Keywords: color > > ### ** Examples > > ## Generate white in XYZ space > XYZ(95.047, 100.000, 108.883) X Y Z [1,] 95.047 100 108.883 > > > > cleanEx() > nameEx("choose_palette") > ### * choose_palette > > flush(stderr()); flush(stdout()) > > ### Name: choose_palette > ### Title: Graphical User Interface for Choosing HCL Color Palettes > ### Aliases: choose_palette > ### Keywords: misc > > ### ** Examples > > > > > cleanEx() > nameEx("color-class") > ### * color-class > > flush(stderr()); flush(stdout()) > > ### Name: color-class > ### Title: Class "color" > ### Aliases: color-class RGB-class sRGB-class XYZ-class HSV-class HLS-class > ### LAB-class LUV-class polarLAB-class polarLUV-class [,color-method > ### coerce,color,RGB-method coerce,color,sRGB-method > ### coerce,color,XYZ-method coerce,color,LAB-method > ### coerce,color,polarLAB-method coerce,color,HSV-method > ### coerce,color,HLS-method coerce,color,LUV-method > ### coerce,color,polarLUV-method coords,color-method plot,color-method > ### show,color-method > ### Keywords: classes > > ### ** Examples > > x = RGB(runif(1000),runif(1000),runif(1000)) > plot(as(x, "LUV")) > > > > cleanEx() > nameEx("coords") > ### * coords > > flush(stderr()); flush(stdout()) > > ### Name: coords > ### Title: Extract the numerical coordinates of a color > ### Aliases: coords > ### Keywords: color > > ### ** Examples > > x <- RGB(1, 0, 0) > coords(as(x, "HSV")) H S V [1,] 360 1 1 > > > > cleanEx() > nameEx("desaturate") > ### * desaturate > > flush(stderr()); flush(stdout()) > > ### Name: desaturate > ### Title: Desaturate Colors by Chroma Removal in HCL Space > ### Aliases: desaturate > ### Keywords: color > > ### ** Examples > > ## rainbow of colors and their desaturated counterparts > rainbow_hcl(12) [1] "#E495A5" "#DB9D85" "#C7A76C" "#ABB065" "#86B875" "#5CBD92" "#39BEB1" [8] "#4CB9CC" "#7DB0DD" "#ACA4E2" "#CD99D8" "#E093C3" > desaturate(rainbow_hcl(12)) [1] "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" [8] "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" "#ABABAB" > > ## convenience demo function > wheel <- function(col, radius = 1, ...) + pie(rep(1, length(col)), col = col, radius = radius, ...) > > ## compare base and colorspace palettes > ## (in color and desaturated) > par(mar = rep(0, 4), mfrow = c(2, 2)) > ## rainbow color wheel > wheel(rainbow_hcl(12)) > wheel(rainbow(12)) > wheel(desaturate(rainbow_hcl(12))) > wheel(desaturate(rainbow(12))) > > > > graphics::par(get("par.postscript", pos = 'CheckExEnv')) > cleanEx() > nameEx("hex") > ### * hex > > flush(stderr()); flush(stdout()) > > ### Name: hex > ### Title: Convert Colors To Hexadecimal Strings > ### Aliases: hex > ### Keywords: color > > ### ** Examples > > hsv = HSV(seq(0, 360, length = 7)[-7], 1, 1) > hsv H S V [1,] 0 1 1 [2,] 60 1 1 [3,] 120 1 1 [4,] 180 1 1 [5,] 240 1 1 [6,] 300 1 1 > hex(hsv) [1] "#FF0000" "#FFFF00" "#00FF00" "#00FFFF" "#0000FF" "#FF00FF" > barplot(rep(1,6), col = hex(hsv)) > > > > cleanEx() > nameEx("hex2RGB") > ### * hex2RGB > > flush(stderr()); flush(stdout()) > > ### Name: hex2RGB > ### Title: Convert Hexadecimal Color Specifications To RGB Objects > ### Aliases: hex2RGB > ### Keywords: color > > ### ** Examples > > hex2RGB(c("#FF0000","#00FF00", "#0000FF")) R G B [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 > > > > cleanEx() > nameEx("mixcolor") > ### * mixcolor > > flush(stderr()); flush(stdout()) > > ### Name: mixcolor > ### Title: Compute the convex combination of two colors > ### Aliases: mixcolor > ### Keywords: color > > ### ** Examples > > mixcolor(0.5, RGB(1, 0, 0), RGB(0, 1, 0)) R G B [1,] 0.5 0.5 0 > > > > cleanEx() > nameEx("polarLAB") > ### * polarLAB > > flush(stderr()); flush(stdout()) > > ### Name: polarLAB > ### Title: Create polarLAB Colors > ### Aliases: polarLAB > ### Keywords: color > > ### ** Examples > > ## Show the polarLAB space > set.seed(1) > x <- RGB(runif(1000), runif(1000), runif(1000)) > y <- as(x, "polarLAB") > head(x) R G B [1,] 0.2655087 0.5308088 0.871805 > head(y) L C H [1,] 76.00763 29.26965 260.1883 > plot(y) > > > > cleanEx() > nameEx("polarLUV") > ### * polarLUV > > flush(stderr()); flush(stdout()) > > ### Name: polarLUV > ### Title: Create polarLUV Colors > ### Aliases: polarLUV > ### Keywords: color > > ### ** Examples > > ## Show the polarLUV space > set.seed(1) > x <- RGB(runif(1000), runif(1000), runif(1000)) > y <- as(x, "polarLUV") > head(x) R G B [1,] 0.2655087 0.5308088 0.871805 > head(y) L C H [1,] 76.00763 52.18057 240.4397 > plot(y) > > > > cleanEx() > nameEx("rainbow_hcl") > ### * rainbow_hcl > > flush(stderr()); flush(stdout()) > > ### Name: rainbow_hcl > ### Title: HCL and HSV Color Palettes > ### Aliases: rainbow_hcl diverge_hcl diverge_hsv heat_hcl sequential_hcl > ### terrain_hcl > ### Keywords: color > > ### ** Examples > > ## convenience demo functions > wheel <- function(col, radius = 1, ...) + pie(rep(1, length(col)), col = col, radius = radius, ...) > > pal <- function(col, border = "light gray") + { + n <- length(col) + plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "") + rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border) + } > > ## qualitative palette > wheel(rainbow_hcl(12)) > > ## a few useful diverging HCL palettes > par(mar = rep(0, 4), mfrow = c(4, 1)) > pal(diverge_hcl(7)) > pal(diverge_hcl(7, h = c(246, 40), c = 96, l = c(65, 90))) > pal(diverge_hcl(7, h = c(130, 43), c = 100, l = c(70, 90))) > pal(diverge_hcl(7, h = c(180, 70), c = 70, l = c(90, 95))) > pal(diverge_hcl(7, h = c(180, 330), c = 59, l = c(75, 95))) > pal(diverge_hcl(7, h = c(128, 330), c = 98, l = c(65, 90))) > pal(diverge_hcl(7, h = c(255, 330), l = c(40, 90))) > pal(diverge_hcl(7, c = 100, l = c(50, 90), power = 1)) > > ## sequential palettes > pal(sequential_hcl(12)) > pal(heat_hcl(12, h = c(0, -100), l = c(75, 40), c = c(40, 80), power = 1)) > pal(terrain_hcl(12, c = c(65, 0), l = c(45, 95), power = c(1/3, 1.5))) > pal(heat_hcl(12, c = c(80, 30), l = c(30, 90), power = c(1/5, 1.5))) > > ## compare base and colorspace palettes > ## (in color and desaturated) > par(mar = rep(0, 4), mfrow = c(2, 2)) > ## rainbow color wheel > wheel(rainbow_hcl(12)) > wheel(rainbow(12)) > wheel(desaturate(rainbow_hcl(12))) > wheel(desaturate(rainbow(12))) > > ## diverging red-blue colors > pal(diverge_hsv(7)) > pal(diverge_hcl(7, c = 100, l = c(50, 90))) > pal(desaturate(diverge_hsv(7))) > pal(desaturate(diverge_hcl(7, c = 100, l = c(50, 90)))) > > ## diverging cyan-magenta colors > pal(cm.colors(7)) > pal(diverge_hcl(7, h = c(180, 330), c = 59, l = c(75, 95))) > pal(desaturate(cm.colors(7))) > pal(desaturate(diverge_hcl(7, h = c(180, 330), c = 59, l = c(75, 95)))) > > ## heat colors > pal(heat.colors(12)) > pal(heat_hcl(12)) > pal(desaturate(heat.colors(12))) > pal(desaturate(heat_hcl(12))) > > ## terrain colors > pal(terrain.colors(12)) > pal(terrain_hcl(12)) > pal(desaturate(terrain.colors(12))) > pal(desaturate(terrain_hcl(12))) > > > > graphics::par(get("par.postscript", pos = 'CheckExEnv')) > cleanEx() > nameEx("readRGB") > ### * readRGB > > flush(stderr()); flush(stdout()) > > ### Name: readRGB > ### Title: Read RGB Color Descriptions > ### Aliases: readRGB > ### Keywords: color > > ### ** Examples > > ## Not run: > ##D rgb <- readRGB("pastel.rgb") > ##D hsv <- readRGB("pastel.rgb", "HSV") > ## End(Not run) > > > > cleanEx() > nameEx("readhex") > ### * readhex > > flush(stderr()); flush(stdout()) > > ### Name: readhex > ### Title: Read Hexadecimal Color Descriptions > ### Aliases: readhex > ### Keywords: color > > ### ** Examples > > ## Not run: > ##D rgb <- readhex("pastel.txt") > ##D hsv <- readhex("pastel.txt", "HSV") > ## End(Not run) > > > > cleanEx() > nameEx("sRGB") > ### * sRGB > > flush(stderr()); flush(stdout()) > > ### Name: sRGB > ### Title: Create sRGB Colors > ### Aliases: sRGB > ### Keywords: color > > ### ** Examples > > # Create a random set of colors > set.seed(1) > sRGB(R = runif(20), G = runif(20), B = runif(20)) R G B [1,] 0.26550866 0.93470523 0.82094629 [2,] 0.37212390 0.21214252 0.64706019 [3,] 0.57285336 0.65167377 0.78293276 [4,] 0.90820779 0.12555510 0.55303631 [5,] 0.20168193 0.26722067 0.52971958 [6,] 0.89838968 0.38611409 0.78935623 [7,] 0.94467527 0.01339033 0.02333120 [8,] 0.66079779 0.38238796 0.47723007 [9,] 0.62911404 0.86969085 0.73231374 [10,] 0.06178627 0.34034900 0.69273156 [11,] 0.20597457 0.48208012 0.47761962 [12,] 0.17655675 0.59956583 0.86120948 [13,] 0.68702285 0.49354131 0.43809711 [14,] 0.38410372 0.18621760 0.24479728 [15,] 0.76984142 0.82737332 0.07067905 [16,] 0.49769924 0.66846674 0.09946616 [17,] 0.71761851 0.79423986 0.31627171 [18,] 0.99190609 0.10794363 0.51863426 [19,] 0.38003518 0.72371095 0.66200508 [20,] 0.77744522 0.41127443 0.40683019 > > > > cleanEx() > nameEx("writehex") > ### * writehex > > flush(stderr()); flush(stdout()) > > ### Name: writehex > ### Title: Write Hexadecimal Color Descriptions > ### Aliases: writehex > ### Keywords: color > > ### ** Examples > > set.seed(1) > x <- RGB(runif(10), runif(10), runif(10)) > writehex(x, "random.txt") [1] "random.txt" > > > > ### *