Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2 geom_density limits

Tags:

r

ggplot2

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, enter image description here

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?

like image 618
tchakravarty Avatar asked Jun 09 '13 06:06

tchakravarty


People also ask

What is adjust in geom_density?

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.

What does density mean Ggplot?

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.

What is Geom density in R?

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.


1 Answers

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")

enter image description here

like image 154
Didzis Elferts Avatar answered Sep 27 '22 18:09

Didzis Elferts