Plot density with ggplot2 without x-axis line

I use ggplot2::ggplot2D graphics for all needs, including density graphs, but I find that when building the number of overlapping densities with extreme outliers in the same space (in different colors), the x-axis line becomes little distracting.

My question is, is it possible to remove the bottom of the density graph from the graph? If so, how?

You can use this example:

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

enter image description here

It should be like this:

enter image description here

+4
source share
2 answers

How about direct use stat_density

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

enter image description here

+10
source

You can simply draw a white line above it:

ggplot(movies, aes(x = rating)) +
    geom_density() +
    geom_hline(color = "white", yintercept = 0)

enter image description here

+1
source

Source: https://habr.com/ru/post/1599393/


All Articles