Title: | Creation and Manipulation of Color Palettes |
---|---|
Description: | Functions for creating color palettes, visualizing palettes, modifying colors, and assigning colors for plotting. |
Authors: | Brody Sandel [aut, cre] |
Maintainer: | Brody Sandel <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-11-01 11:16:05 UTC |
Source: | https://github.com/cran/painter |
These functions are intended to be used to color plotting symbols according to some numeric values or pair of numeric values associated with each point
ColorBy(x, palette) ColorBy2(x,y,palette1, palette2, mode = "RGB")
ColorBy(x, palette) ColorBy2(x,y,palette1, palette2, mode = "RGB")
x |
A vector of numeric values to color the points by |
y |
A vector of numeric values to color the points by, must be of the same length as x |
palette |
A vector of colors |
palette1 |
A vector of colors |
palette2 |
A vector of colors |
mode |
Specifies whether color mixtures should be in "RGB" or "HSV" mode |
A vector of colors of the same length as x
Brody Sandel
x = runif(100) y = runif(100) colors = ColorBy(x,rainbow(100)) plot(x,y,col=colors,pch=16,cex=2) colors = ColorBy2(x,y,SetSaturation("Red",seq(0,1,0.1)),SetSaturation("Blue",seq(0,1,0.1))) plot(x,y,col=colors,pch=16,cex=2)
x = runif(100) y = runif(100) colors = ColorBy(x,rainbow(100)) plot(x,y,col=colors,pch=16,cex=2) colors = ColorBy2(x,y,SetSaturation("Red",seq(0,1,0.1)),SetSaturation("Blue",seq(0,1,0.1))) plot(x,y,col=colors,pch=16,cex=2)
Given a color, Complement() maintains the same value and saturation, but returns a color of the opposite hue. ComplementPalette() creates a color palette that ramps between a color and its complement.
Complement(color) ComplementPalette(color,n=100)
Complement(color) ComplementPalette(color,n=100)
color |
A color or (for Complement) possibly a vector of colors |
n |
The number of colors to produce |
For Complement(), a vector of colors with the same length as color. For ComplementPalette() a vector of n colors
Brody Sandel
TestPalette(Complement(terrain.colors(100))) TestPalette(ComplementPalette("blue"))
TestPalette(Complement(terrain.colors(100))) TestPalette(ComplementPalette("blue"))
These functions simply extact information about a given color or vector of colors, given either as names (e.g. "red") or hex codes (e.g. "FF0000")
GetOpacity(color) GetHue(color) GetSaturation(color) GetValue(color)
GetOpacity(color) GetHue(color) GetSaturation(color) GetValue(color)
color |
A color or vector of colors |
Numeric value(s) between 0 and 1, with the same length as color
Brody Sandel
GetValue("red") GetOpacity("blue") GetHue(rainbow(100))
GetValue("red") GetOpacity("blue") GetHue(rainbow(100))
Creates a mixture between pairs of colors by averaging their red/green/blue components (RGB mode), or hue/saturation/value components (HSV mode)
Mix(color1, color2, mode = "RGB",circular = TRUE)
Mix(color1, color2, mode = "RGB",circular = TRUE)
color1 |
A color or vector of colors, either specified by name (e.g. "red") or hex code (e.g. "FF0000") |
color2 |
A second color or vector of colors. If color1 and color2 are not the same length, but one is an integer multiple of the other, the shorter one will be recycled. |
mode |
Either "RGB" or "HSV", specifies whether to find the intermediate color in RGB space or HSV space. |
circular |
If using mode = "HSV", specifies whether to ramp between hues using circular means. This is usually a good idea because hues are essentially circular (a hue of 0.01 is very similar to 0.99). |
A color
Brody Sandel
TestPalette(Mix("Red","Yellow")) TestPalette(c("Red",Mix("Red","Yellow"),"Yellow")) TestPalette(c("salmon",Mix("salmon","turquoise"),"turquoise")) TestPalette(c("salmon",Mix("salmon","turquoise",mode = "HSV"),"turquoise")) TestPalette(Mix(rainbow(10),terrain.colors(10)))
TestPalette(Mix("Red","Yellow")) TestPalette(c("Red",Mix("Red","Yellow"),"Yellow")) TestPalette(c("salmon",Mix("salmon","turquoise"),"turquoise")) TestPalette(c("salmon",Mix("salmon","turquoise",mode = "HSV"),"turquoise")) TestPalette(Mix(rainbow(10),terrain.colors(10)))
Generates a vector of n colors that ramp between the two specified colors, evenly spaced in either RGB space (mode = "RGB") or HSV space (mode = "HSV")
Palette(color1, color2, n, mode = "RGB",circular = TRUE)
Palette(color1, color2, n, mode = "RGB",circular = TRUE)
color1 |
A color, either specified by name (e.g. "red") or hex code (e.g. "FF0000") |
color2 |
A second color |
n |
The number of colors to produce |
mode |
Either "RGB" or "HSV", specifies whether to ramp between the colors in RGB space or HSV space. |
circular |
If using mode = "HSV", specifies whether to ramp between hues using circular means. This is usually a good idea because hues are essentially circular (a hue of 0.01 is very similar to 0.99), but produces results with a clear break if the span of hues covers more than half of the circle. |
A vector of n colors.
Brody Sandel
TestPalette(Palette("Green","Red",100)) TestPalette(Palette("Green","Red",100,"HSV"))
TestPalette(Palette("Green","Red",100)) TestPalette(Palette("Green","Red",100,"HSV"))
Change the charactistics of a color or vector of colors
SetOpacity(color,opacity) SetHue(color,hue) SetSaturation(color,saturation) SetValue(color,value)
SetOpacity(color,opacity) SetHue(color,hue) SetSaturation(color,saturation) SetValue(color,value)
color |
a vector of colors |
opacity |
a vector of new opacity values |
hue |
a vector of new hues |
saturation |
a vector of new saturations |
value |
a vector of new values |
These functions accept colors specified by name (e.g. "red") or hex codes (e.g. "FF0000"). If the color argument and the other argument both have length n, then each color will be assigned the corresponding new opacity, hue, saturation or value. Otherwise, at least one of the arguments should have length 1, in which case each it will be recycled to length n.
A vector of colors of length n.
Brody Sandel
TestPalette(SetOpacity("red",seq(0,1,0.02))) TestPalette(SetHue("red",seq(0,1,0.02))) TestPalette(SetSaturation("red",seq(0,1,0.02))) TestPalette(SetValue("red",seq(0,1,0.02))) x = runif(200) y = runif(200) color = SetHue("red",x) color = SetValue(color,y) plot(x,y,col = color,pch = 16,cex = 2)
TestPalette(SetOpacity("red",seq(0,1,0.02))) TestPalette(SetHue("red",seq(0,1,0.02))) TestPalette(SetSaturation("red",seq(0,1,0.02))) TestPalette(SetValue("red",seq(0,1,0.02))) x = runif(200) y = runif(200) color = SetHue("red",x) color = SetValue(color,y) plot(x,y,col = color,pch = 16,cex = 2)
TestPalette() simply produces a row of bars of colors, with as many bars as there are elements of the supplied color vector. VisPalette() displays the HSV values of the palette.
TestPalette(color) VisPalette(color)
TestPalette(color) VisPalette(color)
color |
A vector of colors. |
Nothing is returned.
Brody Sandel
pal = Palette("Red","Blue",100) TestPalette(pal) VisPalette(pal)
pal = Palette("Red","Blue",100) TestPalette(pal) VisPalette(pal)