在R中的卡方QQ图中绘制qqline

问题描述 投票:0回答:1

我复制以下代码r help。但是,qqline功能不起作用。是什么原因?

library(mgcViz)
y <- rchisq(500, df = 3)
## Q-Q plot for Chi^2 data against true theoretical distribution:
qqplot(qchisq(ppoints(500), df = 3), y, main = expression("Q-Q plot for" ~~ {chi^2}[nu == 3]))
qqline(y, distribution = function(p) qchisq(p, df = 3), prob = c(0.1, 0.6), col = 2)

谢谢!

r plot quantile
1个回答
1
投票

要使用mgcViz添加qqline,您需要使用ggplot:

library(mgcViz)
y <- rchisq(500, df = 3)
## Q-Q plot for Chi^2 data against true theoretical distribution:
qqplot(qchisq(ppoints(500), df = 3), y, main = expression("Q-Q plot for" ~~ {chi^2}[nu == 3]))

# Add qq line
library(ggplot2)
ggplot2::last_plot() + qqline(y, distribution = function(p) qchisq(p, df = 3), prob = c(0.1, 0.6), col = 2)

qq plot

要查看qqline的截距和斜率,可以执行以下操作:

my.qqline = qqline(y, distribution = function(p) qchisq(p, df = 3), prob = c(0.1, 0.6), col = 2)
> my.qqline$data
   intercept     slope
1 0.08606285 0.9290453
© www.soinside.com 2019 - 2024. All rights reserved.