tinyplot
tinyplot copied to clipboard
Support bg = <numeric> as shortcut for adjustcolor(col, <numeric>)?
Should we support setting bg = <numeric> in [0, 1] as a shortcut for bg = adjustcolor(col, <numeric>) (as discussed in https://github.com/grantmcdermott/tinyplot/pull/122)?
This would be handy when we want to use pch = 21:25 with some border col and then automatically use a semi-transparent version of the same color as the bg fill. But maybe this is too specialized and esoteric to implement a special shortcut.
Application example:
p <- hcl.colors(120, rev = TRUE)[11:110]
tinyplot(lat ~ long | depth, data = quakes, pch = 21, cex = 3, lwd = 2, col = p, bg = adjustcolor(p, 0.1))
The idea would be to abbreviate the last argument to just bg = 0.1.
Related to this, I wonder if we should support an alpha = <[0,1]> argument for easy transparency of colours?
On a recent project, I find myself doing variants of plt(many_points, col = adjustcolor("black", 0.1). It would be nicer to just write plt(many_points, alpha = 0.1). I'm not sure if this could be easily integrated with your fill = [0,1] idea, or whether they should exist as separate arguments. Probably the latter.
I think that this will be nifty for some - and not confusing for those who don't need it. So it sounds like a useful addition to me.
... and I agree that it should be a separate argument.
FWIW, this now works in the cran branch.
library(tinyplot)
tinyplot(lat ~ long | depth, data = quakes, cex = 3, pch = 21, bg = 0.2)

Similarly, for the alpha argument (which affects both the main col and fill, if applicable):
tinyplot(lat ~ long | depth, data = quakes, cex = 3, pch = 19, alpha = 0.2)

Created on 2024-06-17 with reprex v2.1.0