I am plotting the same density plot using base plotting system and ggplot2. Density plot in base plotting system has smooth tails:
d = density(iris$Sepal.Length)
plot(d)
Density plot in ggplot2 has chopped tails:
library(ggplot2)
ggplot( iris, aes(x=Sepal.Length)) + geom_density()
Is there any way to force ggplot2 to plot density plot similar to base plotting system (with smooth tails)?
Store the density and use xlim
to set range from it:
library(ggplot2)
d <- density(iris$Sepal.Length)
ggplot(iris, aes(x=Sepal.Length)) +
geom_density() +
xlim(range(d$x))
Plot