Is there a general way to draw densities (violin plots) or histograms showing the distribution of x
along a smooth (x,y)
curve? I use this approach to show the marginal distribution of x
when there are multiple groups (e.g., different curves on one panel, delineated by differing colors).
Here is an example using the Hmisc
package's plsmo
function to get stratified loess curves and spike histograms showing the sex
-specific data density for age
.
require(Hmisc)
set.seed(1)
age <- rnorm(500, 50, 15)
y <- sample(0:1, 500, TRUE)
sex <- sample(c('female','male'), 500, TRUE)
plsmo(age, y, group=sex, col=1:2,
datadensity=TRUE, scat1d.opts=list(nhistSpike=20))