简体   繁体   中英

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

在此输入图像描述

Should turn out like this:

在此输入图像描述

How about using stat_density directly

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

在此输入图像描述

You can just draw a white line over it:

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM