Estou realizando o gráfico de análise de resíduos half-normal plot. Vejam que utilizando a função default é possível fazer com que no gráfico apareça a informação associada a contagem de pontos fora do envelope.
library(gamlss)
library(hnp)
head(Orange)
mod1 = gamlss(circumference ~ age,
family=NO, data = Orange)
mod2 = gamlss(circumference ~ age,
family=GA, data = Orange)
old_par <- par(mfrow=c(1,2))
hnp(mod1$residuals,how.many.out = T,print.on = T,
xlab = "Quantis Teóricos N(0,1)", half = T,
ylab = "Resíduos quantílicos aleatorizados")
hnp(mod2$residuals,how.many.out = T,print.on = T,
xlab = "Quantis Teóricos N(0,1)", half = T,
ylab = "Resíduos quantílicos aleatorizados")
par(old_par)
No entanto, ao realizar o mesmo gráfico via ggplot2 tais informações não aparecem.
Ga = hnp(mod1$residuals,how.many.out = T,print.on = T,
xlab = "Quantis Teóricos N(0,1)", half = T,
ylab = "Resíduos quantílicos aleatorizados")
G1a <- with(Ga, data.frame(x, lower, upper, median, residuals))
p1=ggplot(data = G1a, aes(x)) +
geom_point(aes(y = residuals)) +
geom_ribbon(aes(ymin = lower, ymax = upper),
alpha = 0.5)+
coord_cartesian(ylim = c(0,4)) +
geom_line(aes(y = median), linetype = 2, col="black") +
ylab("Resíduos quantílicos aleatorizados") +
xlab("Quantis Teóricos N(0,1)") +
theme(legend.title = element_text(size = 25),
legend.text = element_text(size = 25),
axis.text.x = element_text(size = 25,color = "black"),
axis.text.y = element_text(size = 25,color = "black"),
axis.title.x = element_text(size = 15),
axis.title.y = element_text(size = 15),
axis.text = element_text(size = 25),
plot.title = element_text(size = 15, hjust = 0.5))
Gb = hnp(mod2$residuals,how.many.out = T,print.on = T,
xlab = "Quantis Teóricos N(0,1)", half = T,
ylab = "Resíduos quantílicos aleatorizados")
G1b <- with(Gb, data.frame(x, lower, upper, median, residuals))
p2=ggplot(data = G1b, aes(x)) +
geom_point(aes(y = residuals)) +
geom_ribbon(aes(ymin = lower, ymax = upper),
alpha = 0.5)+
coord_cartesian(ylim = c(0,4)) +
geom_line(aes(y = median), linetype = 2, col="black") +
ylab("Resíduos quantílicos aleatorizados") +
xlab("Quantis Teóricos N(0,1)") +
theme(legend.title = element_text(size = 25),
legend.text = element_text(size = 25),
axis.text.x = element_text(size = 25,color = "black"),
axis.text.y = element_text(size = 25,color = "black"),
axis.title.x = element_text(size = 15),
axis.title.y = element_text(size = 15),
axis.text = element_text(size = 25),
plot.title = element_text(size = 15, hjust = 0.5))
grid.arrange(p1,p2,ncol=2)