【问题标题】:geom_density: remove horizontal line at zerogeom_density:删除零处的水平线
【发布时间】:2019-09-05 10:58:00
【问题描述】:

有没有办法去除geom_density 的零水平线?当试图同时绘制两条重叠的密度线时,这条线看起来不太漂亮。

演示示例从这里检索:

http://www.sthda.com/english/wiki/ggplot2-density-plot-quick-start-guide-r-software-and-data-visualization

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

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    是的,您必须使用密度统计功能并将几何更改为线(可选位置为"identity"):

    ggplot(iris, aes(Sepal.Length, colour = Species)) +
      stat_density(geom = "line", position = "identity")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 2018-02-26
      相关资源
      最近更新 更多