我将以下代码复制为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)
谢谢!
答案 0 :(得分: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线的截距和斜率,可以执行以下操作:
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