I want to plot a scatter plot with facets and quadrants - and I want to display basic statistics like the mean, median, number of points in each quadrant etc on each facet + quadrant. My search lead me to stat_mean() function from ggpubr package, geom_quadrant_lines, and stat_quadrant_counts() from the ggpp package
However, with the stat_mean function I am able to print only the "mean" for the entire facet BUT not able to plot the mean for each quadrant. I am also unable to figure out the right way to get other statistics like median, correlation etc - both facet wise as well as quadrant wise.
Any help with this is highly appreciated!
library(ggplot2)
library(ggpubr)
library(ggpp)
#>
#> Attaching package: 'ggpp'
#> The following object is masked from 'package:ggplot2':
#>
#> annotate
data <- data.frame(
xlabel = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ylabel = c(10, 12, 14, 16, 18, 6, 5, 4, 3, 2),
facets = c("a", "a", "a", "a", "a", "b", "b", "b", "b", "b")
)
ggplot(data = data, aes(x = xlabel, y = ylabel, color = facets)) +
geom_point() +
facet_wrap(facets ~ ., ) +
stat_mean(color = "black") +
stat_quadrant_counts(xintercept = 3, yintercept = 9) +
geom_quadrant_lines(xintercept = 3, yintercept = 9)

Created on 2021-11-17 by the reprex package (v2.0.1)
