# generate artificial data
set.seed(67821)
x <- 1:100
y <- rnorm(length(x), mean = 10)
my.data <- data.frame(x, y)
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_panel_counts()
# We use geom_debug() to see the computed values
gginnards.installed <- requireNamespace("gginnards", quietly = TRUE)
if (gginnards.installed) {
library(gginnards)
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_panel_counts(geom = "debug")
}
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_panel_counts(aes(label = sprintf("%i observations", after_stat(count)))) +
expand_limits(y = 12.7)
ggplot(my.data, aes(y)) +
stat_panel_counts(label.x = "left") +
stat_density()
# generate artificial data
set.seed(67821)
x <- 1:100
y <- rnorm(length(x), mean = 10)
group <- factor(rep(c("A", "B"), times = 50))
my.data <- data.frame(x, y, group)
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_panel_counts()
ggplot(my.data, aes(x, y, colour = group)) +
geom_point() +
stat_panel_counts()
ggplot(my.data, aes(x, y, colour = group)) +
geom_point() +
stat_group_counts()
ggplot(my.data, aes(x, y, colour = group)) +
geom_point() +
stat_group_counts(label.x = "left", hstep = 0.06, vstep = 0)
# We use geom_debug() to see the computed values
gginnards.installed <- requireNamespace("gginnards", quietly = TRUE)
if (gginnards.installed) {
library(gginnards)
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_panel_counts(geom = "debug")
ggplot(my.data, aes(x, y, colour = group)) +
geom_point() +
stat_group_counts(geom = "debug")
}
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_panel_counts(aes(label = sprintf("%i observations", after_stat(count)))) +
expand_limits(y = 12.7)
ggplot(my.data, aes(y)) +
stat_panel_counts(label.x = "left") +
stat_density()
ggplot(my.data, aes(y, colour = group)) +
stat_group_counts(label.y = "top") +
stat_density(aes(fill = group))
Run the code above in your browser using DataLab