仅使用平均值和SD信息绘制R中的密度图

发布于 2025-02-01 05:05:07 字数 65 浏览 6 评论 0原文

我想知道,当我们只有平均值(IE 34)和标准偏差(IE 4.5)时,我们是否可以在R(GGPLOT)中表示密度图。

I wonder to know if we can represent in R (ggplot) a density plot when we only have mean (i.e. 34) and standard deviation (i.e. 4.5).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想念有你 2025-02-08 05:05:07

使用stat_functiondnorm

library(ggplot2)

ggplot() + 
  stat_function(fun = ~ dnorm(.x, 34, 4.5), geom = "area",
                fill = "deepskyblue4", alpha = 0.5, color = "black") +
  theme_bw(base_size = 16) +
  xlim(c(20, 48))

”在此处输入图像描述”

Using stat_function and dnorm

library(ggplot2)

ggplot() + 
  stat_function(fun = ~ dnorm(.x, 34, 4.5), geom = "area",
                fill = "deepskyblue4", alpha = 0.5, color = "black") +
  theme_bw(base_size = 16) +
  xlim(c(20, 48))

enter image description here

德意的啸 2025-02-08 05:05:07

您可以使用rnorm为给定的均值sd创建示例分布,然后ggplot:

library(tidyverse)

tibble(x = rnorm(10000, mean = 34, sd = 4.5)) |> 
  ggplot(aes(x)) +
  geom_density(fill = "lightgrey")

​(v2.0.1)

You can use rnorm to create a sample distribution for a given mean and sd, then ggplot:

library(tidyverse)

tibble(x = rnorm(10000, mean = 34, sd = 4.5)) |> 
  ggplot(aes(x)) +
  geom_density(fill = "lightgrey")

Created on 2022-05-25 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文