R 中的正态概率图

Sheeraz Gul 2022年5月26日
R 中的正态概率图

正态概率图是数据的图形表示。本教程演示如何在 R 中绘制正态概率。

R 中的正态概率图

正态概率图显示给定数据集的正态分布。它将数据集与正态分布进行比较。

如果数据是正态分布的,它应该显示一条直线。我们可以使用 ggplot2ggplotr 包来绘制正态概率图。

首先,安装这些包:

install.packages("ggplot2")

install.packages("qqplotr")

成功安装软件包后,我们将为正态分布创建一个数据集,我们将为其绘制正态概率图。我们将使用函数 stat_qq_point()stat_qq_line() 来绘制正态概率。

参见示例:

install.packages("ggplot2")
install.packages("qqplotr")

library(ggplot2)
library(qqplotr)

# random data for normal distribution
normal_distribution = rnorm(1000, mean = 110, sd = 60)

# plot the data without line and labels
ggplot(mapping = aes(sample = normal_distribution)) + stat_qq_point(size = 3)+ stat_qq_line(color="green")

上面的代码将用绿色直线绘制给定数据的正态概率图。见输出:

正态概率图

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

相关文章 - R Plot