Title: | Simplified Plotting for Data Exploration |
---|---|
Description: | Automates common plotting tasks to ease data exploration. Makes density plots (potentially overlaid on histograms), scatter plots with prediction lines, or bar or line plots with error bars. For each type, y, or x and y variables can be plotted at levels of other variables, all with minimal specification. |
Authors: | Micah Iserman [aut, cre, cph] |
Maintainer: | Micah Iserman <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.5.5 |
Built: | 2025-02-17 04:45:12 UTC |
Source: | https://github.com/miserman/splot |
A plotting function aimed at automating some common visualization tasks in order to ease data exploration.
splot(y, data = NULL, su = NULL, type = "", split = "median", levels = list(), sort = NULL, error = "standard", error.color = "#585858", error.lwd = 2, lim = 9, lines = TRUE, ..., colors = "pastel", colorby = NULL, colorby.leg = TRUE, color.lock = FALSE, color.offset = 1.1, color.summary = "mean", opacity = 1, dark = getOption("splot.dark", FALSE), x = NULL, by = NULL, between = NULL, cov = NULL, line.type = "l", mv.scale = "none", mv.as.x = FALSE, save = FALSE, format = cairo_pdf, dims = dev.size(), file.name = "splot", myl = NULL, mxl = NULL, autori = TRUE, xlas = 0, ylas = 1, xaxis = TRUE, yaxis = TRUE, breaks = "sturges", density.fill = TRUE, density.opacity = 0.4, density.args = list(), leg = "outside", lpos = "auto", lvn = TRUE, leg.title = TRUE, leg.args = list(), title = TRUE, labx = TRUE, laby = TRUE, lty = TRUE, lwd = 2, sub = TRUE, ndisp = TRUE, note = TRUE, font = c(title = 2, sud = 1, leg = 1, leg.title = 2, note = 3), cex = c(title = 1.5, sud = 0.9, leg = 0.9, note = 0.7, points = 1), sud = TRUE, labels = TRUE, labels.filter = "_", labels.trim = 20, points = TRUE, points.first = TRUE, byx = TRUE, drop = c(x = TRUE, by = TRUE, bet = TRUE), prat = c(1, 1), check.height = TRUE, model = FALSE, options = NULL, add = NULL)
splot(y, data = NULL, su = NULL, type = "", split = "median", levels = list(), sort = NULL, error = "standard", error.color = "#585858", error.lwd = 2, lim = 9, lines = TRUE, ..., colors = "pastel", colorby = NULL, colorby.leg = TRUE, color.lock = FALSE, color.offset = 1.1, color.summary = "mean", opacity = 1, dark = getOption("splot.dark", FALSE), x = NULL, by = NULL, between = NULL, cov = NULL, line.type = "l", mv.scale = "none", mv.as.x = FALSE, save = FALSE, format = cairo_pdf, dims = dev.size(), file.name = "splot", myl = NULL, mxl = NULL, autori = TRUE, xlas = 0, ylas = 1, xaxis = TRUE, yaxis = TRUE, breaks = "sturges", density.fill = TRUE, density.opacity = 0.4, density.args = list(), leg = "outside", lpos = "auto", lvn = TRUE, leg.title = TRUE, leg.args = list(), title = TRUE, labx = TRUE, laby = TRUE, lty = TRUE, lwd = 2, sub = TRUE, ndisp = TRUE, note = TRUE, font = c(title = 2, sud = 1, leg = 1, leg.title = 2, note = 3), cex = c(title = 1.5, sud = 0.9, leg = 0.9, note = 0.7, points = 1), sud = TRUE, labels = TRUE, labels.filter = "_", labels.trim = 20, points = TRUE, points.first = TRUE, byx = TRUE, drop = c(x = TRUE, by = TRUE, bet = TRUE), prat = c(1, 1), check.height = TRUE, model = FALSE, options = NULL, add = NULL)
y |
a formula (see note), or the primary variable(s) to be shown on the y axis (unless |
data |
a |
su |
a subset to all variables, applied after they are all retrieved from |
type |
determines the type of plot to make, between |
split |
how to split any continuous variables (those with more than |
levels |
a list with entries corresponding to variable names, used to rename and/or reorder factor levels. To
reorder a factor, enter a vector of either numbers or existing level names in the new order (e.g.,
|
sort |
specified the order of character or factor |
error |
string; sets the type of error bars to show in bar or line plots, or turns them off. If |
error.color |
color of the error bars. Default is |
error.lwd |
line weight of error bars. Default is 2. |
lim |
numeric; checked against the number of factor levels of each variable. Used to decide which variables should
be split, which colors to use, and when to turn off the legend. Default is |
lines |
logical or a string specifying the type of lines to be drawn in scatter plots. By default (and whenever
|
... |
passes additional arguments to |
colors |
sets a color theme or manually specifies colors. Default theme is |
colorby |
a variable or list of arguments used to set colors and the legend, alternatively to |
colorby.leg |
logical; if |
color.lock |
logical; if |
color.offset |
how much points or histogram bars should be offset from the initial color used for lines. Default is 1.1; values greater than 1 lighten, and less than 1 darken. |
color.summary |
specifies the function used to collapse multiple colors for a single display. Either a string
matching one of |
opacity |
a number between 0 and 1; sets the opacity of points, lines, and bars. Semi-opaque lines will sometimes not be displayed in the plot window, but will show up when the plot is written to a file. |
dark |
logical; if |
x |
secondary variable, to be shown in on the x axis. If not specified, |
by |
the 'splitting' variable within each plot, by which the plotted values of |
between |
a single object or name, or two in a vector (e.g., |
cov |
additional variables used for adjustment. Bar and line plots include all |
line.type |
a character setting the style of line (e.g., with points at joints) to be drawn in line plots. Default
is |
mv.scale |
determines whether to center and scale multiple |
mv.as.x |
logical; if |
save |
logical; if |
format |
the type of file to save plots as. Default is |
dims |
a vector of 2 values ( |
file.name |
a string with the name of the file to be save (excluding the extension, as this is added depending on
|
myl |
sets the range of the y axis ( |
mxl |
sets the range of the x axis ( |
autori |
logical; if |
xlas , ylas
|
numeric; sets the orientation of the x- and y-axis labels. See |
xaxis , yaxis
|
logical; if |
breaks |
determines the width of histogram bars. See |
density.fill |
logical; |
density.opacity |
opacity of the density polygons, between 0 and 1. |
density.args |
list of arguments to be passed to |
leg |
sets the legend inside or outside the plot frames (when a character matching |
lpos |
sets the position of the legend within its frame (whether inside or outside of the plot frames) based on
keywords (see |
lvn |
level variable name. Logical: if |
leg.title |
sets the title of the legend (which is the by variable name by default), or turns it off with
|
leg.args |
a list passing arguments to the |
title |
logical or a character: if |
labx , laby
|
logical or a character: if |
lty |
logical or a vector: if |
lwd |
numeric; sets the weight of lines in line, density, and scatter plots. Default is 2. See
|
sub |
affects the small title above each plot showing |
ndisp |
logical; if |
note |
logical; if |
font |
named numeric vector: |
cex |
named numeric vector: |
sud |
affects the heading for subset and covariates/line adjustments (su display); text replaces it, and
|
labels |
logical; if |
labels.filter |
a regular expression string to be replaced in label texts with a blank space. Default is
|
labels.trim |
numeric or logical; the maximum length of label texts (in number of characters). Default is 20, with
any longer labels being trimmed. Set to |
points |
logical; if |
points.first |
logical; if |
byx |
logical; if |
drop |
named logical vector: |
prat |
panel ratio, referring to the ratio between plot frames and the legend frame when the legend is out. A
single number will make all panels of equal width. A vector of two numbers will adjust the ratio between plot panels
and the legend panel. For example, |
check.height |
logical; if |
model |
logical; if |
options |
a list with named arguments, useful for setting temporary defaults if you plan on using some of the same
options for multiple plots (e.g., |
add |
evaluated within the function, so you can refer to the objects that are returned, to variable names (those
from an entered data frame or entered as arguments), or entered data by their position, preceded by '.' (e.g.,
|
A list containing data and settings is invisibly returned, which might be useful to check for errors.
Each of these objects can also be pulled from within add
:
dat |
a data.frame of processed, unsegmented data. |
cdat |
a list of list s of data.frame s of processed, segmented data. |
txt |
a list of variable names. used mostly to pull variables from data or the environment. |
ptxt |
a list of processed variable and level names. Used mostly for labeling. |
seg |
a list containing segmentation information (such as levels) for each variable. |
ck |
a list of settings. |
lega |
a list of arguments that were or would have been passed to legend . |
fmod |
an lm object if model is TRUE , and the model succeeded.
|
formulas
When y
is a formula (has a ~
), other variables will be pulled from it:
y ~ x * by * between[1] * between[2] + cov[1] + cov[2] + cov[n]
If y
has multiple variables, by
is used to identify the variable (it becomes a factor with variable names
as levels), so anything entered as by
is treated as between[1]
, between[1]
is moved to
between[2]
, and between[2]
is discarded with a message.
named vectors
Named vector arguments like font
, cex
, and drop
can be set with a single value, positionally, or
with names. If a single value is entered (e.g., drop = FALSE
), this will be applied to each level (i.e.,
c(x = FALSE, by = FALSE, bet = FALSE)
). If more than one value is entered, these will be treated positionally
(e.g., cex =
c(2, 1.2)
would be read as c(title = 2, sud = 1.2, leg = .9, note = .7, points = 1)
).
If values are named, only named values will be set, with other defaults retained (e.g., cex =
c(note = 1.2)
would be read as c(title = 1.5, sud = .9, leg = .9, note = 1.2, points = 1)
).
x-axis levels text
If the text of x-axis levels (those corresponding to the levels of x
) are too long, they are hidden before
overlapping. To try and avoid this, by default longer texts are trimmed (dictated by labels.trim
), and at some
point the orientation of level text is changed (settable with xlas
), but you may still see level text missing.
To make these visible, you can reduce labels.trim
from the default of 20 (or rename the levels of that variable),
make the level text vertical (xlas = 3
), or expand your plot window if possible.
missing levels, lines, and/or error bars
By default (if drop = TRUE
), levels of x
with no data are dropped, so you may not see every level of your
variable, at all or at a level of by
or between
. Sometimes error bars cannot be estimated (if, say, there
is only one observation at the given level), but lines are still drawn in these cases, so you may sometimes see levels
without error bars even when error bars are turned on. Sometimes (particularly when drop['x']
is FALSE
),
you might see floating error bars with no lines drawn to them, or what appear to be completely empty levels. This
happens when there is a missing level of x
between two non-missing levels, potentially making an orphaned level
(if a non-missing level is surrounded by missing levels). If there are no error bars for this orphaned level, by default
nothing will be drawn to indicate it. If you set line.type
to 'b'
(or any other type with points), a point
will be drawn at such error-bar-less, orphaned levels.
unexpected failures
splot tries to clean up after itself in the case of an error, but you may still run into errors that break things before
this can happen. If after a failed plot you find that you're unable to make any new plots, or new plots are drawn over
old ones, you might try entering dev.off()
into the console. If new plots look off (splot's
par
settings didn't get reset), you may have to close the plot window to reset
par
(if you're using RStudio, Plots > "Remove Plot..." or "Clear All..."), or restart R.
# simulating data n <- 2000 dat <- data.frame(sapply(c("by", "bet1", "bet2"), function(c) sample(0:1, n, TRUE))) dat$x <- with( dat, rnorm(n) + by * -.4 + by * bet1 * -.3 + by * bet2 * .3 + bet1 * bet2 * .9 - .8 + rnorm(n, 0, by) ) dat$y <- with( dat, x * .2 + by * .3 + bet2 * -.6 + bet1 * bet2 * .8 + x * by * bet1 * -.5 + x * by * bet1 * bet2 * -.5 + rnorm(n, 5) + rnorm(n, -1, .1 * x^2) ) # looking at the distribution of y between bets split by by splot(y, by = by, between = c(bet1, bet2), data = dat) # looking at quantile splits of y in y by x splot(y ~ x * y, dat, split = "quantile") # looking at y by x between bets splot(y ~ x, dat, between = c(bet1, bet2)) # sequentially adding levels of split splot(y ~ x * by, dat) splot(y ~ x * by * bet1, dat) splot(y ~ x * by * bet1 * bet2, dat) # same as the last but entered by name splot(y, x = x, by = by, between = c(bet1, bet2), data = dat) # zooming in on one of the windows splot(y ~ x * by, dat, bet1 == 1 & bet2 == 0) # comparing an adjusted lm prediction line with a loess line # this could also be entered as y ~ poly(x,3) splot(y ~ x + x^2 + x^3, dat, bet1 == 1 & bet2 == 0 & by == 1, add = { lines(x[order(x)], loess(y ~ x)$fitted[order(x)], lty = 2) legend("topright", c("lm", "loess"), lty = c(1, 2), lwd = c(2, 1), bty = "n") }) # looking at different versions of x added to y splot(cbind( Raw = y + x, Sine = y + sin(x), Cosine = y + cos(x), Tangent = y + tan(x) ) ~ x, dat, myl = c(-10, 15), lines = "loess", laby = "y + versions of x")
# simulating data n <- 2000 dat <- data.frame(sapply(c("by", "bet1", "bet2"), function(c) sample(0:1, n, TRUE))) dat$x <- with( dat, rnorm(n) + by * -.4 + by * bet1 * -.3 + by * bet2 * .3 + bet1 * bet2 * .9 - .8 + rnorm(n, 0, by) ) dat$y <- with( dat, x * .2 + by * .3 + bet2 * -.6 + bet1 * bet2 * .8 + x * by * bet1 * -.5 + x * by * bet1 * bet2 * -.5 + rnorm(n, 5) + rnorm(n, -1, .1 * x^2) ) # looking at the distribution of y between bets split by by splot(y, by = by, between = c(bet1, bet2), data = dat) # looking at quantile splits of y in y by x splot(y ~ x * y, dat, split = "quantile") # looking at y by x between bets splot(y ~ x, dat, between = c(bet1, bet2)) # sequentially adding levels of split splot(y ~ x * by, dat) splot(y ~ x * by * bet1, dat) splot(y ~ x * by * bet1 * bet2, dat) # same as the last but entered by name splot(y, x = x, by = by, between = c(bet1, bet2), data = dat) # zooming in on one of the windows splot(y ~ x * by, dat, bet1 == 1 & bet2 == 0) # comparing an adjusted lm prediction line with a loess line # this could also be entered as y ~ poly(x,3) splot(y ~ x + x^2 + x^3, dat, bet1 == 1 & bet2 == 0 & by == 1, add = { lines(x[order(x)], loess(y ~ x)$fitted[order(x)], lty = 2) legend("topright", c("lm", "loess"), lty = c(1, 2), lwd = c(2, 1), bty = "n") }) # looking at different versions of x added to y splot(cbind( Raw = y + x, Sine = y + sin(x), Cosine = y + cos(x), Tangent = y + tan(x) ) ~ x, dat, myl = c(-10, 15), lines = "loess", laby = "y + versions of x")
Time one or more expressions over several iteration, then plot the distributions of their times.
splot.bench(..., runs = 20, runsize = 200, cleanup = FALSE, print.names = FALSE, limit.outliers = TRUE, check_output = TRUE, check_args = list(), options = list())
splot.bench(..., runs = 20, runsize = 200, cleanup = FALSE, print.names = FALSE, limit.outliers = TRUE, check_output = TRUE, check_args = list(), options = list())
... |
accepts any number of expressions to be timed. See examples. |
runs |
the number of overall iterations. Increase to stabilize estimates. |
runsize |
the number of times each expression is evaluated within each run. Increase to differentiate estimates (particularly for very fast operations). |
cleanup |
logical; if |
print.names |
logical; if |
limit.outliers |
logical; if |
check_output |
logical; if |
check_args |
a list of arguments to be passed to |
options |
a list of options to pass on to splot. |
A list:
plot | splot output |
checks | a list of result from all.equal, if check_output was TRUE
|
expressions | a list of the entered expressions |
summary | a matrix of the printed results |
# increase the number of runs for more stable estimates # compare ways of looping through a vector splot.bench( sapply(1:100, "*", 10), mapply("*", 1:100, 10), vapply(1:100, "*", 0, 10), unlist(lapply(1:100, "*", 10)), runs = 20, runsize = 200 ) # compare ways of setting all but the maximum value of each row in a matrix to 0 if (FALSE) { mat <- matrix(c(rep(1, 4), rep(0, 8)), 4, 3) splot.bench( t(vapply(seq_len(4), function(r) { mat[r, mat[r, ] < max(mat[r, ])] <- 0 mat[r, ] }, numeric(ncol(mat)))), do.call(rbind, lapply(seq_len(4), function(r) { mat[r, mat[r, ] < max(mat[r, ])] <- 0 mat[r, ] })), do.call(rbind, lapply(seq_len(4), function(r) { nr <- mat[r, ] nr[nr < max(nr)] <- 0 nr })), { nm <- mat for (r in seq_len(4)) { nr <- nm[r, ] nm[r, nr < max(nr)] <- 0 } nm }, { nm <- mat for (r in seq_len(4)) nm[r, nm[r, ] < max(nm[r, ])] <- 0 nm }, { nm <- matrix(0, dim(mat)[1], dim(mat)[2]) for (r in seq_len(4)) { m <- which.max(mat[r, ]) nm[r, m] <- mat[r, m] } nm }, { ck <- do.call(rbind, lapply(seq_len(4), function(r) { nr <- mat[r, ] nr < max(nr) })) nm <- mat nm[ck] <- 0 nm }, t(apply(mat, 1, function(r) { r[r < max(r)] <- 0 r })), runs = 50, runsize = 200 ) }
# increase the number of runs for more stable estimates # compare ways of looping through a vector splot.bench( sapply(1:100, "*", 10), mapply("*", 1:100, 10), vapply(1:100, "*", 0, 10), unlist(lapply(1:100, "*", 10)), runs = 20, runsize = 200 ) # compare ways of setting all but the maximum value of each row in a matrix to 0 if (FALSE) { mat <- matrix(c(rep(1, 4), rep(0, 8)), 4, 3) splot.bench( t(vapply(seq_len(4), function(r) { mat[r, mat[r, ] < max(mat[r, ])] <- 0 mat[r, ] }, numeric(ncol(mat)))), do.call(rbind, lapply(seq_len(4), function(r) { mat[r, mat[r, ] < max(mat[r, ])] <- 0 mat[r, ] })), do.call(rbind, lapply(seq_len(4), function(r) { nr <- mat[r, ] nr[nr < max(nr)] <- 0 nr })), { nm <- mat for (r in seq_len(4)) { nr <- nm[r, ] nm[r, nr < max(nr)] <- 0 } nm }, { nm <- mat for (r in seq_len(4)) nm[r, nm[r, ] < max(nm[r, ])] <- 0 nm }, { nm <- matrix(0, dim(mat)[1], dim(mat)[2]) for (r in seq_len(4)) { m <- which.max(mat[r, ]) nm[r, m] <- mat[r, m] } nm }, { ck <- do.call(rbind, lapply(seq_len(4), function(r) { nr <- mat[r, ] nr < max(nr) })) nm <- mat nm[ck] <- 0 nm }, t(apply(mat, 1, function(r) { r[r < max(r)] <- 0 r })), runs = 50, runsize = 200 ) }
Get a prespecified set of 9 colors, or a set of graded or random, potentially grouped colors.
splot.color(x = NULL, by = NULL, seed = "pastel", brightness = 0, luminance = 0, opacity = 1, extend = 0.7, lighten = FALSE, shuffle = FALSE, flat = TRUE, method = "scale", grade = FALSE, decreasing = FALSE, nas = "#000000")
splot.color(x = NULL, by = NULL, seed = "pastel", brightness = 0, luminance = 0, opacity = 1, extend = 0.7, lighten = FALSE, shuffle = FALSE, flat = TRUE, method = "scale", grade = FALSE, decreasing = FALSE, nas = "#000000")
x |
dictates the number and shade of colors. If a single value, returns that many samples of the
first |
by |
a vector to group |
seed |
a vector of color names or codes to adjust from, lining up with levels of |
brightness |
adjusts the RGB values of the seed color, usually between -1 and 1. |
luminance |
adjusts the white levels of the seed color, usually between -1 and 1. |
opacity |
sets the opacity of the seed color, between 0 and 1. |
extend |
if |
lighten |
logical; if |
shuffle |
logical; if |
flat |
logical; if |
method |
a character setting the sampling method: If |
grade |
logical; if |
decreasing |
logical; if |
nas |
value to replace missing values with. |
If x
and by
are not specified (or are characters with a length of 1, in which case they
are treated as seed
), only the seed palette is returned.
To expand on a palette, seed colors are assigned to groups, and variants of each seed are assigned to values or levels within groups, or randomly or as a gradient if there are no values or level to assign to.
Seed colors are assigned to groups. If x
is a character or factor and no by
has been
specified, groups are the unique levels of x
. If by
is specified and is a character or
factor, or has fewer than 10 unique levels, groups are levels of by
. If x
is a list,
groups are list entries.
The number of variants for each seed color is determined either by a value (if the value has a length
of 1; e.g., x=10
), the vector's length (if x
is numeric), or the count of the given level
(if x
is a factor or character vector).
A character vector of color codes, or a list of such vectors if flat
if FALSE
.
# including no arguments or just a palette name will only return # the palette as a character vector pastel_palette <- splot.color() dark_palette <- splot.color("dark") # entering a number for x will generate that many variants of the first seed color red_scale <- splot.color(10, "red") # entering a list of values as x will return that many variants of the associated seed red_and_green_scales <- splot.color(list(10, 10), seed = c("red", "green")) # this shows gradients of each color in the default palette # a list entered as colorby is treated as arguments to splot.color # periods before the position name refer to the internally assembled data splot( rep(splot.color(), each = 100) ~ rep.int(seq.int(.01, 1, .01), 9), colorby = list(.x, .y), lines = FALSE, mar = c(2, 4, 0, 0), cex = c(points = 3), leg = FALSE, pch = 15, title = "'pastel' palette", labx = "value of x", laby = "seed color" ) # colors graded by value, entered in a list plot( 1:30, numeric(30), pch = 15, cex = 10, col = splot.color(list(1:8, c(7:1, 1:7), 8:1)) ) # comparing sampling methods: # on top are 1000 similar colors, with different RGB ratios # on bottom are 268 colors with the same RGB ratio at different levels splot( c(rnorm(1000), rnorm(1000, 10)) ~ rnorm(2000), lines = FALSE, colors = c(splot.color(1000), splot.color(1000, method = "related")) )
# including no arguments or just a palette name will only return # the palette as a character vector pastel_palette <- splot.color() dark_palette <- splot.color("dark") # entering a number for x will generate that many variants of the first seed color red_scale <- splot.color(10, "red") # entering a list of values as x will return that many variants of the associated seed red_and_green_scales <- splot.color(list(10, 10), seed = c("red", "green")) # this shows gradients of each color in the default palette # a list entered as colorby is treated as arguments to splot.color # periods before the position name refer to the internally assembled data splot( rep(splot.color(), each = 100) ~ rep.int(seq.int(.01, 1, .01), 9), colorby = list(.x, .y), lines = FALSE, mar = c(2, 4, 0, 0), cex = c(points = 3), leg = FALSE, pch = 15, title = "'pastel' palette", labx = "value of x", laby = "seed color" ) # colors graded by value, entered in a list plot( 1:30, numeric(30), pch = 15, cex = 10, col = splot.color(list(1:8, c(7:1, 1:7), 8:1)) ) # comparing sampling methods: # on top are 1000 similar colors, with different RGB ratios # on bottom are 268 colors with the same RGB ratio at different levels splot( c(rnorm(1000), rnorm(1000, 10)) ~ rnorm(2000), lines = FALSE, colors = c(splot.color(1000), splot.color(1000, method = "related")) )
Calculates the color contrast ratio between two sets of colors, as defined by the World Wide Web Consortium.
splot.colorcontrast(color, background = "#ffffff", plot = TRUE)
splot.colorcontrast(color, background = "#ffffff", plot = TRUE)
color , background
|
A character vector of colors, or a matrix with RGB values across rows. |
plot |
Logical; if |
A list with entries for ratio
(contrast ratio),
AA
(ratios of at least 4.5), and AAA
(ratios of at least 7).
Each entry contains a matrix with colors in rows and backgrounds in columns.
# check colors against dark and light backgrounds splot.colorcontrast(c("#FF0000", "#00FF00", "#0000FF"), c("black", "white")) # check contrast between colors splot.colorcontrast(c("red", "green", "blue"), c("red", "green", "blue")) # see when shades of a color cross thresholds on a given background splot.colorcontrast(splot.color(1:10, seed = "#a388b5"), "#101010")
# check colors against dark and light backgrounds splot.colorcontrast(c("#FF0000", "#00FF00", "#0000FF"), c("black", "white")) # check contrast between colors splot.colorcontrast(c("red", "green", "blue"), c("red", "green", "blue")) # see when shades of a color cross thresholds on a given background splot.colorcontrast(splot.color(1:10, seed = "#a388b5"), "#101010")
Calculates the average of a set of colors, returning its Hex code.
splot.colormean(...)
splot.colormean(...)
... |
color codes or names as characters. |
The calculated color code.
# average of red and blue plot( 1:3, numeric(3), pch = 15, cex = 20, xlim = c(0, 4), col = c("red", splot.colormean("red", "blue"), "blue") ) # average of a set x <- rnorm(100) set <- splot.color(x, method = "related") splot( x ~ rnorm(100), colors = set, add = points(0, 0, pch = 15, cex = 10, col = splot.colormean(set)) )
# average of red and blue plot( 1:3, numeric(3), pch = 15, cex = 20, xlim = c(0, 4), col = c("red", splot.colormean("red", "blue"), "blue") ) # average of a set x <- rnorm(100) set <- splot.color(x, method = "related") splot( x ~ rnorm(100), colors = set, add = points(0, 0, pch = 15, cex = 10, col = splot.colormean(set)) )