I assume the ggplot scales creates some sort of function which reads the appropriate aes
value and returns the colour
, size
, etc. Can this be used as a standalone function?
For example, to this function I will pass the necessary arguments (range
, limits
, high
, low
, etc.) and a value which I want to get the mapping for, and the output of the function will be the colour
/ size
/ etc.
# example of usage
HypotheticalScaleFunction(
range = c(0,10),
high = '#000000',
low = '#222222',
ValueToLookup = 5
)
# this should return -
"#111111"
You can find this by reading through the source, by typing in scale functions. For example, if you read through the source for
ggplot2::scale_color_continuous
, you will find that it usesseq_gradient_pal
from thescales
package.So, for color on a continious scale, we can define the following function (with the defaults that
ggplot
uses):This results in the typical dark blue colors that you get by default, in heatmaps for example.
It produces
#161616
on your example though.