Title: | Optimized Rendering of Fold Changes and Confidence Values |
---|---|
Description: | Shows color patches for encoding fold changes (e.g. log ratios) together with confidence values within a single diagram. This is especially useful for rendering gene expression data as well as other types of differential experiments. In addition to different rendering methods (ggplot extensions) functionality for perceptually optimizing color palettes are provided. Furthermore the package provides extension methods of the colorspace color-class in order to simplify the work with palettes (a.o. length, as.list, and append are supported). |
Authors: | Andre Mueller [aut, cre], Hans Kestler [aut] |
Maintainer: | Andre Mueller <[email protected]> |
License: | Artistic-2.0 |
Version: | 0.1.2 |
Built: | 2025-03-01 05:38:05 UTC |
Source: | https://github.com/cran/colorpatch |
The colorpatch package provides functions for plotting color patch grids rendering the two channels fold change and confidence value within a single diagram. This is especially useful for analyzing gene expression data as well as other types of "change" data such as gains/losses in stock exchange or analyzing the agricultural output.
The packages consists of:
ggplot extensions for visualizing color patch grids colorpatch::stat_colorpatch()
and colorpatch::stat_bicolor()
Functionality for rearranging data for a better readable map colorpatch::OrderData()
Perceptual optimization functions for sub-sampling non-uniform bicolored palettes colorpatch::OptimizeBiColor()
For more details see the vignette
Maintainer: Andre Mueller [email protected]
Authors:
Hans Kestler [email protected]
Useful links:
vignette("introduction", package = "colorpatch")
vignette("introduction", package = "colorpatch")
Applies to the colorspace::color class.
## S4 method for signature 'color' append(x, values, after = length(x))
## S4 method for signature 'color' append(x, values, after = length(x))
x |
the color palette to be modified. |
values |
another color palette to be appended |
after |
currently unimplemented. |
Applies a function to each entry of a colorspace::color palette.
apply.color(X, FUN, ...)
apply.color(X, FUN, ...)
X |
the color palette |
FUN |
the function to be applied |
... |
extra arguments to FUN |
a list of each result of FUN applied to each entry in X
Applies to the colorspace::color class.
data("OptimGreenRedLAB") as(OptimGreenRedLAB, "list")
data("OptimGreenRedLAB") as(OptimGreenRedLAB, "list")
Applies to the colorspace::color class.
as.list(x, ...) ## S4 method for signature 'color' as.list(x, ...)
as.list(x, ...) ## S4 method for signature 'color' as.list(x, ...)
x |
color object to be coerced to a list |
... |
ignored for this class |
data("OptimGreenRedLAB") as.list(OptimGreenRedLAB)
data("OptimGreenRedLAB") as.list(OptimGreenRedLAB)
Computes the perceptional distance between two neighboring colors
ColorDistance(pal, color.space = "LAB")
ColorDistance(pal, color.space = "LAB")
pal |
the color palette |
color.space |
color space in which the distance shall be computed (default "LAB") |
a vector of distances
data("OptimGreenRedLAB") dd <- ColorDistance(OptimGreenRedLAB)
data("OptimGreenRedLAB") dd <- ColorDistance(OptimGreenRedLAB)
Creates a color function mapping (ratio, conf) tuples to a single color
ColorPatchColorFun(palette = "OptimGreenRedLAB")
ColorPatchColorFun(palette = "OptimGreenRedLAB")
palette |
name of the palette (see |
A function mapping (ratio, conf) to a color.
fn <- ColorPatchColorFun("OptimBlueYelloLAB")
fn <- ColorPatchColorFun("OptimBlueYelloLAB")
Creates a size function mapping (ratio, conf) to a single color
ColorPatchSizeFun(type = "linear")
ColorPatchSizeFun(type = "linear")
type |
defaults to "linear" |
A function mapping (ratio, conf) to a size.
Creates a color mapping function
ColorRgbFun(pal, xmin = -1, xmax = 1, coerce.fun = colorspace::hex)
ColorRgbFun(pal, xmin = -1, xmax = 1, coerce.fun = colorspace::hex)
pal |
the color palette |
xmin |
minimum value to be mapped to the first entry of the palette |
xmax |
maximum value to be mapped to the last entry of the palette |
coerce.fun |
the color coercing function (e.g. for ggplot2 |
a function mapping a value to a color
data("OptimGreenRedLAB") fn <- ColorRgbFun(OptimGreenRedLAB)
data("OptimGreenRedLAB") fn <- ColorRgbFun(OptimGreenRedLAB)
Computes the symmetry of a given bi-variate color palette
ComputeSymmetry(pal, color.space = "LAB")
ComputeSymmetry(pal, color.space = "LAB")
pal |
A two-sided input palette colorspace::color |
color.space |
Color space where the distances shall be computed (default "LAB") |
a data frame with index, side (pos/neg) and distance
data("OptimGreenRedLAB") df <- ComputeSymmetry(OptimGreenRedLAB) print(df)
data("OptimGreenRedLAB") df <- ComputeSymmetry(OptimGreenRedLAB) print(df)
Creates clustered random data
CreateClusteredData(nrow = 30, ncol = 12, nrow.clusters = 2, ncol.clusters = 2, alpha = 4)
CreateClusteredData(nrow = 30, ncol = 12, nrow.clusters = 2, ncol.clusters = 2, alpha = 4)
nrow |
Number of rows (default: 30) |
ncol |
Number of columns (default: 12) |
nrow.clusters |
Number of row cluster |
ncol.clusters |
Number of column clusters (default: 2) |
alpha |
Scaling facor (default: 4) |
A data set with $ratio and $conf values
Creates demonstration data of the colorpatch package
CreateExampleData(nrow = 30, ncol = 12)
CreateExampleData(nrow = 30, ncol = 12)
nrow |
number of rows (default 30) |
ncol |
number of columns (default 12) |
the data set
library(ggplot2) library(colorpatch) dat <- CreateExampleData() df <- ToDataFrame(dat) p <- ggplot(df, aes(x = x, y = y, ratio = ratio, conf = conf)) p <- p + theme_colorpatch() + coord_fixed(ratio = 1) + stat_colorpatch() plot(p)
library(ggplot2) library(colorpatch) dat <- CreateExampleData() df <- ToDataFrame(dat) p <- ggplot(df, aes(x = x, y = y, ratio = ratio, conf = conf)) p <- p + theme_colorpatch() + coord_fixed(ratio = 1) + stat_colorpatch() plot(p)
Computes the distance of to colors within a certain colorspace
DistColor(x, y, color.space = "LAB")
DistColor(x, y, color.space = "LAB")
x |
First color to be compared |
y |
Second color to be compared |
color.space |
Defaults to "LAB" (can be anything within the colorspace package) see colorspace::color |
L2 distance of the two colors within the given coordinate space
colorspace::color, DistColorFun()
library(colorspace) library(colorpatch) DistColor(sRGB(0.1,0.5,0), sRGB(0.2,0.7,1.0), "LUV")
library(colorspace) library(colorpatch) DistColor(sRGB(0.1,0.5,0), sRGB(0.2,0.7,1.0), "LUV")
Creates a color distance function
DistColorFun(color.space = "LAB")
DistColorFun(color.space = "LAB")
color.space |
Color space to be used (see colorspace::color) |
A function mapping two color values of a color class colorspace::color to a numeric value.
library(colorspace) library(colorpatch) fn <- DistColorFun("LUV") a <- sRGB(1,0,0) b <- sRGB(0.8,0.1,0) my.distance <- fn(a,b)
library(colorspace) library(colorpatch) fn <- DistColorFun("LUV") a <- sRGB(1,0,0) b <- sRGB(0.8,0.1,0) my.distance <- fn(a,b)
Finds a uniform color sequence within a non-uniform palette by subsampling that palette
FindUniformSequence(P, n.out, reverse = FALSE, delta = NULL, col.dist.fun = DistColorFun("LAB"))
FindUniformSequence(P, n.out, reverse = FALSE, delta = NULL, col.dist.fun = DistColorFun("LAB"))
P |
input color palette (must be a class derived from colorspace::color) |
n.out |
number of output colors (must be less than length(P)) |
reverse |
shall the searching be performed from the end of the palette to the beginning |
delta |
the perceptual difference to be achieved between two adjecent colors |
col.dist.fun |
function mapping two colors to a numeric distance |
a optimized palette (sub-set of P)
Creates color palettes and saves them as files
GeneratePalettes(col.dist.fun = DistColorFun("LAB"), ...)
GeneratePalettes(col.dist.fun = DistColorFun("LAB"), ...)
col.dist.fun |
Color distance function. |
... |
Additional arguments forwarded to |
Nothing - this function is used for its side effects (creating files in data).
A two-sided color scale left side: green, center: black, right side: red.
GreenRedRGB
GreenRedRGB
An object of class colorspace::color.
Creates a color function mapping ratio/conf values to a HSV colorspace
HsvColorFun(coerce.fn = colorspace::hex, hue.offset = 60, hue.scale = -60, saturation = 1)
HsvColorFun(coerce.fn = colorspace::hex, hue.offset = 60, hue.scale = -60, saturation = 1)
coerce.fn |
coerces each HSV color with this function (defaults |
hue.offset |
hue offset (defaults to 60) |
hue.scale |
hue scale (defaults to 60) |
saturation |
HSV saturation (defaults to 1) |
a color mapping function (ratio,conf) -> color
Creates a size function mapping ratio/conf to a patch size for bicolorings
HsvSizeFun()
HsvSizeFun()
a size mapping function (ratio,conf) -> size
This function can be used together with ggplot2 for mapping values onto colorspace::color palettes.
The color is then coerced with coerce.fun
.
InterpolateColorFun(pal, xmin = -1, xmax = +1, coerce.fun = colorspace::hex)
InterpolateColorFun(pal, xmin = -1, xmax = +1, coerce.fun = colorspace::hex)
pal |
The input palette (must be of class colorspace::color) |
xmin |
minimum of the numeric range to be mapped onto |
xmax |
maximum of the numeric range to be mapped onto |
coerce.fun |
each color will be coerced by this function (defaults to |
A function mapping a numeric value value
onto a color value.
library(colorspace) library(colorpatch) data("OptimGreenRedLAB") fn <- InterpolateColorFun(OptimGreenRedLAB) cols <- fn(seq(-1, 1, by = 0.1)) specplot(cols)
library(colorspace) library(colorpatch) data("OptimGreenRedLAB") fn <- InterpolateColorFun(OptimGreenRedLAB) cols <- fn(seq(-1, 1, by = 0.1)) specplot(cols)
Applies to the colorspace::color class.
## S4 method for signature 'color' length(x)
## S4 method for signature 'color' length(x)
x |
an color object |
Creates a linear color space between two colors
LinColorSpace(color1, color2, n.out)
LinColorSpace(color1, color2, n.out)
color1 |
the first color (must be of the class colorspace::color) |
color2 |
the second color (must be of the class colorspace::color) |
n.out |
number of output colors |
a palette
library(colorspace) library(colorpatch) pal <- LinColorSpace(sRGB(0,1,0), sRGB(0,0.1,0), 32) pal <- append(pal, sRGB(0,0,0)) pal <- append(pal, LinColorSpace(sRGB(0.1,0,0), sRGB(1,0,0), 32)) PlotUniformity(pal) print(pal)
library(colorspace) library(colorpatch) pal <- LinColorSpace(sRGB(0,1,0), sRGB(0,0.1,0), 32) pal <- append(pal, sRGB(0,0,0)) pal <- append(pal, LinColorSpace(sRGB(0.1,0,0), sRGB(1,0,0), 32)) PlotUniformity(pal) print(pal)
A two-sided color scale left side: blue, center: black, right side: yellow.
OptimBlueYellowLAB
OptimBlueYellowLAB
An object of class colorspace::color.
A two-sided color scale left side: green, center: black, right side: red.
OptimGreenRedLAB
OptimGreenRedLAB
An object of class colorspace::color.
Optimizes a bicolor palette
OptimizeBiColor(neg.col.min = colorspace::sRGB(0, 0.01, 0), neg.col.max = colorspace::sRGB(0, 1, 0), pos.col.min = colorspace::sRGB(0.01, 0, 0), pos.col.max = colorspace::sRGB(1, 0, 0), center.col = colorspace::sRGB(0, 0, 0), n.out = 64, oversampling = 128, col.dist.fun = DistColorFun("LAB"), reverse = FALSE)
OptimizeBiColor(neg.col.min = colorspace::sRGB(0, 0.01, 0), neg.col.max = colorspace::sRGB(0, 1, 0), pos.col.min = colorspace::sRGB(0.01, 0, 0), pos.col.max = colorspace::sRGB(1, 0, 0), center.col = colorspace::sRGB(0, 0, 0), n.out = 64, oversampling = 128, col.dist.fun = DistColorFun("LAB"), reverse = FALSE)
neg.col.min |
color representing the negative mininum value |
neg.col.max |
color representing the negative maximum value |
pos.col.min |
color for the positive minimum value |
pos.col.max |
color representing the positive maximum value |
center.col |
center color which maps to 0 (default: black) |
n.out |
size of each half-palette |
oversampling |
the oversampling rate |
col.dist.fun |
color distance function (default: DistColorFun("LAB")) for optimizing the palette |
reverse |
shall the palette be searched starting from the minimum color to the maximum
( |
bicolor palette
pal <- OptimizeBiColor(n.out = 8, oversampling = 32) PlotUniformity(pal)
pal <- OptimizeBiColor(n.out = 8, oversampling = 32) PlotUniformity(pal)
Orders rows and columns of data.
OrderData(dat, orderFn = OrderDataHclust, distFn = stats::dist)
OrderData(dat, orderFn = OrderDataHclust, distFn = stats::dist)
dat |
Ratio data |
orderFn |
Ordering method (default: OrderDataHclust) |
distFn |
Distance function (Idefault stats::dist) |
ordered data
stats::hclust()
Orders rows and column distances with stats::hclust()
OrderDataHclust(row.dist, col.dist, ...)
OrderDataHclust(row.dist, col.dist, ...)
row.dist |
row distances |
col.dist |
column distances |
... |
optional parameters forwarded to the |
a list with irow and icol containing the orders of rows and columns
Orders rows and column distances with traveling salesman ordering TSP
OrderDataTSP(row.dist, col.dist, ...)
OrderDataTSP(row.dist, col.dist, ...)
row.dist |
row distances |
col.dist |
column distances |
... |
optional parameters fed to the |
a list with irow and icol containing the orders of rows and columns
Orders a data set given a distance matrix with TSP
OrderWithTSP(dist, ...)
OrderWithTSP(dist, ...)
dist |
distance object or distance matrix |
... |
extra arguments fed to |
a path (vector of integers)
Plots the symmetry of a bivariate color scale
PlotSymmetry(pal, color.space = "LAB")
PlotSymmetry(pal, color.space = "LAB")
pal |
A two-sided input palette colorspace::color |
color.space |
Color space where the distances shall be computed (default "LAB") |
a ggplot object
data("OptimGreenRedLAB") PlotSymmetry(OptimGreenRedLAB)
data("OptimGreenRedLAB") PlotSymmetry(OptimGreenRedLAB)
Plots the uniformity of a color palette
PlotUniformity(pal, color.space = "LAB")
PlotUniformity(pal, color.space = "LAB")
pal |
A colorspace palette |
color.space |
the color space (see colorspace::color) |
a ggplot instance
data("OptimGreenRedLAB") p <- PlotUniformity(OptimGreenRedLAB) plot(p)
data("OptimGreenRedLAB") p <- PlotUniformity(OptimGreenRedLAB) plot(p)
Reads a sRGB color table as CSV file
ReadArraySRGB(file.name)
ReadArraySRGB(file.name)
file.name |
the color file |
a colorspace palette
Plots a ratio/confidence plot using a bivariate colormap
stat_bicolor(mapping = NULL, data = NULL, geom = "tile", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, color.fun = HsvColorFun(), size.fun = HsvSizeFun(), ...)
stat_bicolor(mapping = NULL, data = NULL, geom = "tile", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, color.fun = HsvColorFun(), size.fun = HsvSizeFun(), ...)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. |
geom |
Defaults to |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
color.fun |
Color function mapping a (ratio,conf) pair to a color (defaults to |
size.fun |
Size function mapping a (ratio,conf) pair to a rectangle size (defaults to |
... |
further arguments given to the |
a ggplot statistics layer for showing bicolored maps
library(ggplot2) library(colorpatch) dat <- CreateExampleData() df <- ToDataFrame(dat) p <- ggplot(df) + theme_colorpatch() + stat_bicolor(aes(ratio=ratio,conf=conf,x=x,y=y))
library(ggplot2) library(colorpatch) dat <- CreateExampleData() df <- ToDataFrame(dat) p <- ggplot(df) + theme_colorpatch() + stat_bicolor(aes(ratio=ratio,conf=conf,x=x,y=y))
A stat function for the use with ggplot2
stat_colorpatch(mapping = NULL, data = NULL, geom = "tile", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, color.fun = ColorPatchColorFun(), size.fun = ColorPatchSizeFun(), ...)
stat_colorpatch(mapping = NULL, data = NULL, geom = "tile", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, color.fun = ColorPatchColorFun(), size.fun = ColorPatchSizeFun(), ...)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. |
geom |
Defaults to |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
color.fun |
Color function mapping a (ratio,conf) pair to a color (defaults to |
size.fun |
Size function mapping a (ratio,conf) pair to a rectangle size (defaults to |
... |
Further arguments given to the colorpatch::StatColorPatch ggproto object. Here thresh.ratio, thresh.conf are the most important parameters. |
a ggplot statistics layer for showing color patches
A ggplot2::ggproto class for showing color patches.
StatColorPatch
StatColorPatch
An object of class StatColorPatch
(inherits from Stat
, ggproto
) of length 4.
A ggplot2 theme for rendering colorpatches (black background)
theme_colorpatch(fill = "black", plot.background = fill)
theme_colorpatch(fill = "black", plot.background = fill)
fill |
background fill color (default: "black") |
plot.background |
background fill color (default: "black") |
a theme function for showing color patches
library(ggplot2) library(colorpatch) dat <- CreateExampleData() df <- ToDataFrame(dat) p <- ggplot(df) + theme_colorpatch() + stat_colorpatch(aes(ratio=ratio,conf=conf,x=x,y=y))
library(ggplot2) library(colorpatch) dat <- CreateExampleData() df <- ToDataFrame(dat) p <- ggplot(df) + theme_colorpatch() + stat_colorpatch(aes(ratio=ratio,conf=conf,x=x,y=y))
Transforms a ratio/conf data set to a ggplot dataframe
ToDataFrame(dat)
ToDataFrame(dat)
dat |
must be a list with two matrices |
a data frame