Search code examples
rggplot2kernel-density

ggplot2 logdensity kernel estimation


What is the best way to achieve the same result as: Kernel estimation of log-pdf

using ggplot2 instead of base graphics? I would like to do it with something similar to stat_density as otherwise things get quickly complicated when combined with faceting etc.


Solution

  • library(ggplot2)
    
    x = rnorm(100)
    
    dev.new(width=4, height=4)
    qplot(x, stat='density', geom='line') + scale_y_log10()
    

    enter image description here