-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Currently in StatChaikin the data being used consists only of x and y columns returned by get_chaikin(). However, colour, size and other aesthetics are part of the layer data:
set.seed(42)
dat <- data.frame(
x = [seq.int](https://seq.int/)(10),
y = sample(15:30, 10),
group = rep(c("A", "B"), each = 5)
)
p <- ggplot(dat, aes(x, y)) + ggpointless::geom_chaikin(aes(colour = group))
pb <- ggplot_build(p)
head(pb@data[[1]])
x y colour PANEL group linewidth linetype alpha
1 1.000000 15.00000 #F8766D 1 1 0.5 1 NA
2 1.237305 15.94922 #F8766D 1 1 0.5 1 NA
3 1.356445 16.43262 #F8766D 1 1 0.5 1 NA
4 1.436523 16.76660 #F8766D 1 1 0.5 1 NA
5 1.503906 17.05664 #F8766D 1 1 0.5 1 NA
6 1.558594 17.30273 #F8766D 1 1 0.5 1 NAThanks to ggplot2 there is no problem for a user; internally ggplot2 adds stats to the data, if these are not already included](https://github.com/tidyverse/ggplot2/blob/b5163bcf29d5fe5e6fc42c05c4ed3a777d2edc19/R/stat-.R#L252).
We can improve this and make it explicit in StatChaikin like so inside compute_group:
# Preserve aesthetics (group, colour, linewidth, linetype)
aesthetics <- data[1, setdiff(names(data), c("x", "y")), drop = FALSE]
# Recycle aesthetics across the newly generated path
cbind(new_coords, aesthetics, row.names = NULL)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels