| geom_qqrplot | R Documentation |
geom_* and stat_* for Producing Quantile Residual Q-Q Plots with 'ggplot2'Various geom_* and stat_* used within
autoplot for producing quantile residual Q-Q plots.
geom_qqrplot(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
stat_qqrplot_simint(
mapping = NULL,
data = NULL,
geom = "qqrplot_simint",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
geom_qqrplot_simint(
mapping = NULL,
data = NULL,
stat = "qqrplot_simint",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
stat_qqrplot_ref(
mapping = NULL,
data = NULL,
geom = "qqrplot_ref",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
detrend = FALSE,
identity = TRUE,
probs = c(0.25, 0.75),
scale = c("normal", "uniform"),
...
)
geom_qqrplot_ref(
mapping = NULL,
data = NULL,
stat = "qqrplot_ref",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
detrend = FALSE,
identity = TRUE,
probs = c(0.25, 0.75),
scale = c("normal", "uniform"),
...
)
geom_qqrplot_confint(
mapping = NULL,
data = NULL,
stat = "qqrplot_confint",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
xlim = NULL,
n = 101,
detrend = FALSE,
type = c("pointwise", "simultaneous", "tail-sensitive"),
level = 0.95,
identity = TRUE,
probs = c(0.25, 0.75),
scale = c("normal", "uniform"),
style = c("polygon", "line"),
...
)
GeomQqrplotConfint
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
geom |
The geometric object to use display the data |
detrend |
logical, default |
identity |
logical. Should the identity line be plotted or a theoretical line
which passes through |
probs |
numeric vector of length two, representing probabilities of reference line used. |
scale |
character. Scale on which the quantile residuals will
be shown: |
xlim |
|
n |
positive numeric. Number of points used to compute the confidence intervals, the more the smoother. |
type |
character. Should |
level |
numeric. The confidence level required, defaults to |
style |
character. Style for plotting confidence intervals. Either |
An object of class GeomQqrplotConfint (inherits from Geom, ggproto, gg) of length 6.
if (require("ggplot2")) {
## Fit model
data("CrabSatellites", package = "countreg")
m1_pois <- glm(satellites ~ width + color, data = CrabSatellites, family = poisson)
m2_pois <- glm(satellites ~ color, data = CrabSatellites, family = poisson)
## Compute qqrplot
q1 <- qqrplot(m1_pois, plot = FALSE)
q2 <- qqrplot(m2_pois, plot = FALSE)
d <- c(q1, q2)
## Get label names
xlab <- unique(attr(d, "xlab"))
ylab <- unique(attr(d, "ylab"))
main <- attr(d, "main")
main <- make.names(main, unique = TRUE)
d$group <- factor(d$group, labels = main)
## Polygon CI around identity line used as reference
gg1 <- ggplot(data = d, aes(x = expected, y = observed, na.rm = TRUE)) +
geom_qqrplot_ref() +
geom_qqrplot_confint(fill = "red") +
geom_qqrplot() +
geom_qqrplot_simint(
aes(
x = simint_expected,
ymin = simint_observed_lwr,
ymax = simint_observed_upr,
group = group
)
) +
xlab(xlab) + ylab(ylab)
gg1
gg1 + facet_wrap(~group)
## Polygon CI around robust reference line
gg2 <- ggplot(data = d, aes(x = expected, y = observed, na.rm = TRUE)) +
geom_qqrplot_ref(identity = FALSE, scale = attr(d, "scale")) +
geom_qqrplot_confint(identity = FALSE, scale = attr(d, "scale"), style = "line") +
geom_qqrplot() +
geom_qqrplot_simint(
aes(
x = simint_expected,
ymin = simint_observed_lwr,
ymax = simint_observed_upr,
group = group
)
) +
xlab(xlab) + ylab(ylab)
gg2
gg2 + facet_wrap(~group)
## Use different `scale`s with confidence intervals
q1 <- qqrplot(m1_pois, scale = "uniform", plot = FALSE)
q2 <- qqrplot(m2_pois, plot = FALSE)
gg3 <- ggplot(data = q1, aes(x = expected, y = observed, na.rm = TRUE)) +
geom_qqrplot_ref() +
geom_qqrplot_confint(fill = "red", scale = "uniform") +
geom_qqrplot()
gg3
gg4 <- ggplot(data = q2, aes(x = expected, y = observed, na.rm = TRUE)) +
geom_qqrplot_ref() +
geom_qqrplot_confint(fill = "red", scale = "uniform") +
geom_qqrplot()
gg4
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.