col_div_xf | R Documentation |
Divergent color interpolation function with adjustable range and optional color floor
col_div_xf(
x = 1,
floor = 0,
lens = 0,
n = 15,
colramp = "RdBu_r",
open_floor = FALSE,
debug = FALSE,
...
)
x |
|
floor |
|
lens |
|
n |
|
colramp |
|
open_floor |
|
debug |
|
... |
additional arguments are ignored. |
This function is intended to extend the very useful function
circlize::colorRamp2()
which takes a numeric
vector
of
breaks, and a character
vector
of R colors, and returns
a function that maps numeric
values to R colors using
interpolated color gradient. This function is intended for
specific cases using a divergent color gradient, where this
function assumes colors should be mapped to positive and
negative numeric values centered at zero.
A driving use case is with ComplexHeatmap::Heatmap()
, with
argument col
that contains a color function produced by
circlize::colorRamp2()
or a color vector. However, when
supplying a divergent color vector, the colors are not applied
symmetrically above and below zero.
function
that maps a vector of numeric
values
to R colors using the divergent color gradient and numeric
thresholds defined.
Other colorjam gradients:
col_linear_xf()
,
make_jam_divergent()
,
twostep_gradient()
Other colorjam assignment:
col_linear_xf()
,
group2colors()
,
matrix2heatColors()
,
rainbowJamMulti()
,
vals2colorLevels()
,
vibrant_color_by_hue()
col_fn1 <- col_div_xf(x=3, floor=0, n=21)
col_fn2 <- col_div_xf(x=3, floor=1, n=13)
col_fn3 <- col_div_xf(x=3, floor=1, n=9)
col_fn4 <- col_div_xf(x=3, floor=1, n=5)
col_fn2o <- col_div_xf(x=3, floor=1, n=13, open_floor=TRUE)
col_fn3o <- col_div_xf(x=3, floor=1, n=9, open_floor=TRUE)
col_fn4o <- col_div_xf(x=3, floor=1, n=5, open_floor=TRUE)
test_seq <- seq(from=-3, to=3, by=0.05);
names(test_seq) <- round(test_seq, digits=2);
opar <- par("mfrow"=c(1, 1));
bp0 <- barplot(abs(test_seq),
las=2, yaxt="n",
main="floor=0",
col=col_fn1(test_seq),
border="#22222222")
abline(v=bp0[abs(test_seq) == 1,], lty="dashed")
bp1 <- barplot(abs(test_seq),
las=2, yaxt="n",
main="floor=1",
col=col_fn2(test_seq),
border="#22222222")
abline(v=bp1[abs(test_seq) == 1,], lty="dashed")
bp2 <- barplot(abs(test_seq),
las=2, yaxt="n",
main="floor=1\nopen_floor=TRUE",
col=col_fn2o(test_seq),
border="#22222222")
abline(v=bp2[abs(test_seq) == 1,], lty="dashed")
par(opar)
test_seq <- seq(from=-3, to=3, by=0.5);
names(test_seq) <- round(test_seq, digits=2);
test_seq <- c(test_seq,
`-0.999`=-0.999,
`0.999`=0.999);
test_seq <- test_seq[order(test_seq)]
opar <- par("mfrow"=c(1, 2));
bp1 <- barplot((test_seq),
las=2, yaxt="n",
main="floor=1\nn=19",
col=col_fn2(test_seq),
border="#22222244")
abline(v=bp1[abs(test_seq) == 1,], lty="dashed")
bp2 <- barplot((test_seq),
las=2, yaxt="n",
main="floor=1\nn=19\nopen_floor=TRUE",
col=col_fn2o(test_seq),
border="#22222244")
abline(v=bp2[abs(test_seq) == 1,], lty="dashed")
bp3 <- barplot((test_seq),
las=2, yaxt="n",
main="floor=1\nn=9",
col=col_fn3(test_seq),
border="#22222244")
abline(v=bp3[abs(test_seq) == 1,], lty="dashed")
bp3 <- barplot((test_seq),
las=2, yaxt="n",
main="floor=1\nn=9\nopen_floor=TRUE",
col=col_fn3o(test_seq),
border="#22222244")
abline(v=bp3[abs(test_seq) == 1,], lty="dashed")
bp4 <- barplot((test_seq),
las=2, yaxt="n",
main="floor=1\nn=5",
col=col_fn4(test_seq),
border="#22222244")
abline(v=bp4[abs(test_seq) == 1,], lty="dashed")
bp4 <- barplot((test_seq),
las=2, yaxt="n",
main="floor=1\nn=5\nopen_floor=TRUE",
col=col_fn4o(test_seq),
border="#22222244")
abline(v=bp4[abs(test_seq) == 1,], lty="dashed")
par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.