Search code examples
rggplot2density-plot

adding density on axes in ggplot2


I was doing some pretty plots with these density bars on the axes, but since there I've lost the code and the ability to reproduce the bars.

It would be wonderful if someone could point me to the right command

Thanks


Solution

  • I believe you're looking for geom_rug; here is an example:

    ggplot(mtcars, aes(wt, mpg, colour = as.factor(am))) + geom_point() + geom_rug()
    

    enter image description here