Search code examples
rggplot2density-plot

Plot density with ggplot2 without line on x-axis


I use ggplot2::ggplot for all 2D plotting needs, including density plots, but I find that when plotting a number of overlapping densities with extreme outliers on a single space (in different colors) the line on the x-axis becomes a little distracting.

My question is then, can you remove the bottom section of the density plot from being plotted? If so, how?

You can use this example:

library(ggplot2)
ggplot(movies, aes(x = rating)) + geom_density()

enter image description here

Should turn out like this:

enter image description here


Solution

  • How about using stat_density directly

     ggplot(movies, aes(x = rating)) + stat_density(geom="line")
    

    enter image description here