6

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

2 Answers 2

12

How about using stat_density directly

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

2

You can just draw a white line over it:

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

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.