有没有办法删除geom_密度
零处的水平线?当尝试同时绘制两条重叠的密度线时,这条线看起来不太漂亮。
演示示例可从此处检索:
set.seed(1234)
df <- data.frame(
sex=factor(rep(c("F", "M"), each=200)),
weight=round(c(rnorm(200, mean=55, sd=5),
rnorm(200, mean=65, sd=5)))
)
library(ggplot2)
# Basic density
p <- ggplot(df, aes(x=weight)) + geom_density()
最佳答案
是的,您必须使用密度统计函数并将几何图形更改为线(可以选择将位置更改为“identity”
):
ggplot(iris, aes(Sepal.Length, colour = Species)) +
stat_density(geom = "line", position = "identity")
关于r - 几何密度 : remove horizontal line at zero,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57803969/