【问题标题】:How can I graph 2 normal distributions over one-another in the same plot? [closed]如何在同一个图中相互绘制 2 个正态分布? [关闭]
【发布时间】:2018-01-29 20:17:31
【问题描述】:

一条曲线必须使用 Gender 变量的值为 0(即男性)的数据。另一条曲线必须使用性别变量值为 1(即女性)的数据。

我使用了 2 个变量:意见(用于分布)和性别(用于创建两条曲线)。

希望这些信息足以帮助某人...

【问题讨论】:

  • 到目前为止您尝试过什么,您想要的输出是什么样的?

标签: r rstudio normal-distribution


【解决方案1】:

由于您没有说明有关图表类型的信息,也没有说明示例数据框,因此您有一些建议。

# This installs and loads pacman, to use the p_loas function
if (!require('pacman')) install.packages('pacman'); library('pacman')

# sample data
value <- rnorm(n=100, mean=50, sd=5)
gen <- rep(x = c(1,2), 50)

df <- data.frame(value = as.numeric(value), gender = as.factor(gen))

# Option 1
p_load(ggjoy)
ggplot(df, aes(x = value, y = gender)) +
  geom_joy(scale = 2, alpha = .7, color = "black") +
  scale_fill_hue(l=30)

# Option 2
p_load(ggpubr)
ggdensity(df, x = "value",
          add = "mean", rug = TRUE,
          color = "gender", palette = c("#00AFBB", "#E7B800"), fill = "gender")

# Option 3
p_load(yarrr)
pirateplot(value ~ gender, df)

【讨论】:

    猜你喜欢
    • 2018-03-16
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    相关资源
    最近更新 更多