如何在 R 中将密度表示为百分比?

发布于 2024-12-28 21:21:54 字数 144 浏览 2 评论 0原文

当我在 R 中运行密度直方图时,纵轴将密度显示为分数。试试这个,例如: hist(rnorm(100), freq = FALSE)

看看纵轴如何显示“0.0”、“0.1”、“0.2”等,如何让它显示“0%”、“ 1%”、“2%”?

When I run a density histogram in R, the vertical axis shows densities as fractions. Try this, for example:
hist(rnorm(100), freq = FALSE)

See how the vertical axis shows "0.0", "0.1", "0.2", etc. How can I make it display "0%", "1%", "2%"?

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

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

发布评论

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

评论(2

情定在深秋 2025-01-04 21:21:54

像这样的东西吗?

x <- rnorm(100)
par(mfrow = c(1, 2))
hist(x, freq = FALSE, axes = FALSE)
axis(2, at = seq(0, 0.4, 0.1), labels = paste(0:4, "%", sep = ""))
hist(x, freq = FALSE)

在此处输入图像描述

Something like this?

x <- rnorm(100)
par(mfrow = c(1, 2))
hist(x, freq = FALSE, axes = FALSE)
axis(2, at = seq(0, 0.4, 0.1), labels = paste(0:4, "%", sep = ""))
hist(x, freq = FALSE)

enter image description here

橘寄 2025-01-04 21:21:54

不要在 hist 中绘制垂直轴。通过axis自行添加。

h <- hist(rnorm(100))
plot(h, freq=FALSE, yaxt="n")
axis(2, pretty(h$density), sprintf("%0.0f%%", pretty(h$density)*100))

然而,这确实具有误导性,因为密度与某物的百分比或比例不同。如果你要做类似的事情,

hist(rnorm(100, s=0.1))

你会得到相同的分布,但现在你所有的密度都大了 10 倍,因为分布的规模小了 10 倍。

在 y 轴上绘制带有百分比的累积频率多边形或直方图会更有意义。

Don't plot the vertical axis in hist. Add it yourself via axis.

h <- hist(rnorm(100))
plot(h, freq=FALSE, yaxt="n")
axis(2, pretty(h$density), sprintf("%0.0f%%", pretty(h$density)*100))

However, this is really misleading, because densities aren't the same as percentages or proportions of something. If you were to do something like

hist(rnorm(100, s=0.1))

You get the same distribution, but now all your densities are 10 times larger in magnitude because the scale of the distribution is 10 times smaller.

It would make more sense to plot the cumulative frequency polygon or histogram with percentages on the y-axis.

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