# NOT RUN {
library(gginnards)
set.seed(123456)
my.df <- data.frame(X = rep(1:20,2),
Y = runif(40),
category = rep(c("A","B"), each = 20))
# make sure row are ordered for X as we will use functions that rely on this
my.df <- my.df[order(my.df[["X"]]), ]
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_apply_group(.fun.y = cumsum)
# Use of geom_debug() to inspect the computed values
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_apply_group(.fun.y = cumsum, geom = "debug")
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_apply_group(.fun.y = cummax)
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_apply_group(.fun.x = cumsum, .fun.y = cumsum)
# diff returns a shorter vector by 1 for each group
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_apply_group(.fun.y = diff, na.rm = TRUE)
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
geom_point() +
stat_apply_group(.fun.y = runmed, .fun.y.args = list(k = 5))
# Rescaling per group
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_apply_group(.fun.y = function(x) {(x - min(x)) / (max(x) - min(x))})
# Joint rescaling for whole panel
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_apply_panel(.fun.y = function(x) {(x - min(x)) / (max(x) - min(x))})
# Centroid
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_centroid(shape = "cross", size = 6) +
geom_point()
# Centroid
ggplot(my.df, aes(x = X, y = Y, colour = category)) +
stat_centroid(geom = "text", aes(label = category)) +
geom_point()
# }
Run the code above in your browser using DataLab