alpha support in ttheme constructors, geom_table() and geom_table_npc()
Easily modifying a table theme to add alpha to the core of the table seems useful. It could be rather easily implemented in all existing ttheme constructors as in the example below.
#' @rdname ttheme_gtdefault
#'
#' @export
#'
ttheme_gtbw_alpha <- function (base_size = 10,
base_colour = "black",
base_family = "",
parse = FALSE,
padding = unit(c(1, 0.6), "char"),
fill.alpha = 0.5,
colour.alpha = 0.8,
...)
{
core <-
list(bg_params =
list(fill = ggplot2::alpha("white", fill.alpha),
lwd = 1.5,
col = ggplot2::alpha("grey90", colour.alpha)))
colhead <-
rowhead <-
list(bg_params = list(fill = ggplot2::alpha("grey80", fill.alpha),
lwd = 1.5,
col = ggplot2::alpha("grey90", colour.alpha)))
default <-
gridExtra::ttheme_default(base_size = base_size,
base_colour = base_colour,
base_family = base_family,
parse = parse,
padding = padding,
core = core,
colhead = colhead,
rowhead = rowhead)
utils::modifyList(default, list(...))
}
I need to check if there have been any updates in 'gridExtra' that already support alpha. It is a long time since I implemented this geom.
'gridExtra' has not been updated for quite some time. Thus, this can be implemented as in the example above. The reason to use ggplot2::alpha() instead of just passing alpha to gpar is that it accepts NA as a no op and providing behaviour consistent with that of 'ggplot2', thus better matching expected users' expectations.
- [x] Update all ttheme constructors adding formal parameters
base.alpha,rules.alphaandcanvas.alphato make it easier for users to create semitransparent table themes. - [x] Update
geom_table()andgeom_table_npc()to support similar control through formal parameteralpha.target. - [x] Ensure alpha.target and colour.target work consistently, with mappings to alpha, colour and fill aesthetics.
- [x] Run existing unit tests.
- [x] Add new unit tests for
geom_table()and test ensuring enough code coverage. - [x] Add new unit tests for
geom_table_npc()and test ensuring enough code coverage - [x] Add unit tests for table theme constructors supporting
alpha. (added for default theme) - [x] Update documentation.
- [x] Update vignette.
Getting the logic for defaulting to ttheme but supporting both colour, fill, and alpha in a way the mapped or constant alpha aesthetic is applied to the theme defaults when colour or fill from the theme are in use resulted in rather extense code. Room remains for factoring out table building code shared by geom_table() and geom_table_npc().
- [ ] Factor out duplicated code in the tow draw functions.
- [ ] Test with existing unit tests.