How can I remove the lines at the end of the limits in calls to geom_density
?
Here is an example:
library(ggplot2)
set.seed(1234)
dfGamma = data.frame(nu75 = rgamma(100, 0.75),
nu1 = rgamma(100, 1),
nu2 = rgamma(100, 2))
dfGamma = stack(dfGamma)
ggplot(dfGamma, aes(x = values)) +
geom_density(aes(group = ind, color = ind))
which produces,
How would I get rid of the vertical blue lines at the edges of the plot, and the horizontal one running along the x-axis?
A multiplicate bandwidth adjustment. This makes it possible to adjust the bandwidth while still using the a bandwidth estimator. For example, adjust = 1/2 means use half of the default bandwidth. kernel. Kernel.
10 mins. Data Visualization using GGPlot2. A density plot is an alternative to Histogram used for visualizing the distribution of a continuous variable. The peaks of a Density Plot help to identify where values are concentrated over the interval of the continuous variable.
geom_density.Rd. Computes and draws kernel density estimate, which is a smoothed version of the histogram. This is a useful alternative to the histogram for continuous data that comes from an underlying smooth distribution.
You can use stat_density()
instead of geom_density()
and add arguments geom="line"
and position="identity"
.
ggplot(dfGamma, aes(x = values)) +
stat_density(aes(group = ind, color = ind),position="identity",geom="line")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With