Skip to content

Commit

Permalink
version 0.97
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Ihaka authored and gaborcsardi committed Oct 25, 2008
1 parent 9822e7e commit f9292b6
Show file tree
Hide file tree
Showing 14 changed files with 1,710 additions and 70 deletions.
17 changes: 10 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 1,15 @@
Package: colorspace
Version: 0.95
Date: 2006-11-16
Title: Colorspace Manipulation
Author: Ross Ihaka <[email protected]>
Version: 0.97
Date: 2008-10-25
Title: Color Space Manipulation
Author: Ross Ihaka, Paul Murrell, Kurt Hornik, Achim Zeileis
Maintainer: Ross Ihaka <[email protected]>
Description: Carries out mapping between assorted color spaces including
RGB, HSV, HLS, CIEXYZ, CIELUV, HCL (polar CIELUV),
CIELAB and polar CIELAB. Qualitative, sequential, and
diverging color palettes based on HCL colors are provided.
Depends: R (>= 2.0.0), methods
Description: Carries out mapping between assorted color spaces.
Suggests: KernSmooth, MASS, kernlab, mvtnorm, vcd
License: BSD
URL: http://www.r-project.org
LazyLoad: yes
Packaged: Thu Nov 16 11:47:26 2006; ihaka
Packaged: Fri Oct 24 23:50:24 2008; zeileis
17 changes: 9 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 1,9 @@
useDynLib(colorspace)
import(methods)
importFrom(graphics, plot)
exportClasses(color, RGB, HSV, XYZ, LAB, polarLAB, LUV, polarLUV)
export(RGB, HSV, XYZ, LAB, polarLAB, LUV, polarLUV)
export(mixcolor,coords)
export(hex, hex2RGB, readRGB, readhex, writehex)
exportMethods("[", coerce, coords, plot, show)
useDynLib("colorspace")
import("methods")
importFrom("graphics", "plot")
exportClasses("color", "RGB", "HSV", "HLS", "XYZ", "LAB", "polarLAB", "LUV", "polarLUV")
export("RGB", "HSV", "HLS", "XYZ", "LAB", "polarLAB", "LUV", "polarLUV")
export("mixcolor", "coords")
export("hex", "hex2RGB", "readRGB", "readhex", "writehex")
export("rainbow_hcl", "diverge_hcl", "diverge_hsv", "heat_hcl", "sequential_hcl", "terrain_hcl")
exportMethods("[", "coerce", "coords", "plot", "show")
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 1,8 @@
Changes in Version 0.96

o moved color palettes from vcd to colorspace,
including vignette("hcl-colors")

o added infrastructure for HLS color space

o new CITATION file
23 changes: 22 additions & 1 deletion R/colorspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 9,14 @@
## HSV Hue-Saturation-Value
## LUV CIE-L*u*v*
## polarLUV CIE-L*u*v* in polar coordinates
## HLS Hue-Lightness-Saturation
##
## The ``canonical'' space here is really CIE-XYZ, but in this
## implementation all spaces are treated equally, because
## they are all useful.
##

.onLoad = function(lib, pkg) require(methods, quietly = TRUE)
.onLoad = function(lib, pkg) require("methods", quietly = TRUE)

## The Abstract Color Class

Expand All @@ -28,6 29,7 @@ setClass("XYZ", contains="color")
setClass("LAB", contains="color")
setClass("polarLAB", contains="color")
setClass("HSV", contains="color")
setClass("HLS", contains="color")
setClass("LUV", contains="color")
setClass("polarLUV", contains="color")

Expand Down Expand Up @@ -126,6 128,21 @@ HSV =
new("HSV", coords = coords)
}

HLS =
function(H, L, S, names)
{
if (missing(H)) return(new("HLS"))
if (missing(names)) names = dimnames(H)[[1]]
coords = cbind(H, if (missing(L)) NULL else L,
if (missing(S)) NULL else S)
CheckMatrix(coords)
## CheckBounds(coords[,1], 0, 360)
## CheckBounds(coords[,2], 0, 1)
## CheckBounds(coords[,3], 0, 1)
dimnames(coords) = list(names, c("H", "L", "S"))
new("HLS", coords = coords)
}

LUV =
function(L, U, V, names)
{
Expand Down Expand Up @@ -171,6 188,10 @@ setAs("color", "HSV", function(from)
HSV(.Call("as_HSV", from@coords, class(from), .WhitePoint),
names = dimnames(from@coords)[[1]]))

setAs("color", "HLS", function(from)
HLS(.Call("as_HLS", from@coords, class(from), .WhitePoint),
names = dimnames(from@coords)[[1]]))

setAs("color", "LUV", function(from)
LUV(.Call("as_LUV", from@coords, class(from), .WhitePoint),
names = dimnames(from@coords)[[1]]))
Expand Down
71 changes: 71 additions & 0 deletions R/palettes.R
Original file line number Diff line number Diff line change
@@ -0,0 1,71 @@
rainbow_hcl <- function(n, c = 50, l = 70, start = 0, end = 360*(n-1)/n,
gamma = 2.4, fixup = TRUE, ...)
{
if(n > 0) hex(polarLUV(L = l, C = c, H = seq(start, end, length = n)), gamma = gamma, fixup = fixup, ...)
else character(0)
}

diverge_hcl <- function(n, h = c(260, 0), c = 80, l = c(30, 90), power = 1.5,
gamma = 2.4, fixup = TRUE, ...)
{
if(n < 1) return(character(0))
h <- rep(h, length.out = 2)
c <- c[1]
l <- rep(l, length.out = 2)
power <- rep(power, length.out = 2)
rval <- seq(1, -1, length = n)
rval <- hex(polarLUV(L = l[2] - diff(l) * abs(rval)^power[2],
C = c * abs(rval)^power[1],
H = ifelse(rval > 0, h[1], h[2])),
gamma = gamma, fixup = fixup, ...)
return(rval)
}

diverge_hsv <- function(n, h = c(240, 0), s = 1, v = 1, power = 1,
gamma = 2.4, fixup = TRUE, ...)
{
if(n < 1) return(character(0))
h <- rep(h, length.out = 2)
s <- s[1]
v <- v[1]
power <- power[1]
rval <- seq(-s, s, length = n)
rval <- hex(HSV(H = ifelse(rval > 0, h[2], h[1]), S = abs(rval)^power, V = v, ...),
gamma = gamma, fixup = fixup, ...)
return(rval)
}

sequential_hcl <- function(n, h = 260, c. = c(80, 0), l = c(30, 90), power = 1.5,
gamma = 2.4, fixup = TRUE, ...)
{
if(n < 1) return(character(0))
c <- rep(c., length.out = 2)
l <- rep(l, length.out = 2)
power <- rep(power, length.out = 2)
rval <- seq(1, 0, length = n)
rval <- hex(polarLUV(L = l[2] - diff(l) * rval^power[2],
C = c[2] - diff(c) * rval^power[1],
H = h[1]),
gamm = gamma, fixup = fixup, ...)
return(rval)
}

heat_hcl <- function(n, h = c(0, 90), c. = c(100, 30), l = c(50, 90),
power = c(1/5, 1), gamma = 2.4, fixup = TRUE, ...)
{
if(n < 1) return(character(0))
h <- rep(h, length.out = 2)
c <- rep(c., length.out = 2)
l <- rep(l, length.out = 2)
power <- rep(power, length.out = 2)
rval <- seq(1, 0, length = n)
rval <- hex(polarLUV(L = l[2] - diff(l) * rval^power[2],
C = c[2] - diff(c) * rval^power[1],
H = h[2] - diff(h) * rval),
gamma = gamma, fixup = fixup, ...)
return(rval)
}

terrain_hcl <- function(n, h = c(130, 0), c. = c(80, 0), l = c(60, 95), power = c(1/10, 1),
gamma = 2.4, fixup = TRUE, ...)
heat_hcl(n, h = h, c. = c., l = l, power = power, gamma = gamma, fixup = fixup, ...)
45 changes: 45 additions & 0 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -0,0 1,45 @@
citHeader("To cite colorspace in publications use")

## R >= 2.8.0 passes package metadata to citation().
if(!exists("meta") || is.null(meta)) meta <- packageDescription("colorspace")
year <- sub("-.*", "", meta$Date)
note <- sprintf("R package version %s", meta$Version)

citEntry(entry = "Manual",
title = "{colorspace}: Color Space Manipulation",
author = personList(as.person("Ross Ihaka"),
as.person("Paul Murrell"),
as.person("Kurt Hornik"),
as.person("Achim Zeileis")),
year = year,
note = note,
url = "http://CRAN.R-project.org/package=colorspace",

textVersion =
paste("Ross Ihaka, Paul Murrell, Kurt Hornik, Achim Zeileis",
sprintf("(%s).", year),
"colorspace: Color Space Manipulation.",
paste(note, ".", sep = ""),
"URL http://CRAN.R-project.org/package=colorspace")
)

citEntry(entry = "TechReport",
title = "Escaping {RGB}land: Selecting Colors for Statistical Graphics",
author = personList(as.person("Achim Zeileis"),
as.person("Kurt Hornik"),
as.person("Paul Murrell")),
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/",

textVersion =
paste("Achim Zeileis, Kurt Hornik, Paul Murrell (2007).",
"Escaping RGBland: Selecting Colors for Statistical Graphics.",
"Report 61.",
"Department of Statistics and Mathematics, Wirtschaftsuniversitaet Wien, Research Report Series.",
"URL http://epub.wu-wien.ac.at/."),
header = "If you use HCL-based color palettes, please cite:"
)
Loading

0 comments on commit f9292b6

Please sign in to comment.