How ggside works with ggplot2
mainThe ggside package extends ggplot2 by allowing you to add side panels that display graphical information relative to the main panel's axes. This is useful for showing metadata for discrete axes or summary statistics (like boxplots or density distributions) for continuous axes.
Geometries follow a naming pattern: geom_xside* adds a layer to the x-side panel, and geom_yside* adds a layer to the y-side panel. By default, an xside geometry is positioned above the main panel and shares the same x-axis but has an independent y-axis.
library(ggplot2)
library(ggside)
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point(size = 2) +
geom_xsidedensity(aes(y = after_stat(density)), position = "stack") +
geom_ysidedensity(aes(x = after_stat(density)), position = "stack") +
theme(axis.text.x = element_text(angle = 90, vjust = .5))