Question

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.

Was it helpful?

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

OTHER TIPS

Couldn't you just assign dlog_y= log(density(x)$y) and call gglplot with that as your y-variable?

x = rnorm(100); dlog_y= log()
dev.new(width=4, height=4)
qplot(x = density(x)$x, y=dlog_y)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top