gg_qq_plot | R Documentation |
This is a version of the quantile-quantile (Q-Q) plot using ggplot2
. In
addition to the Q-Q plot, marginal distributions are also provided.
gg_qq_plot(
samp,
theoretical_dist = "norm",
bins = 20,
probs = c(0.25, 0.75),
loess = FALSE,
span = 1,
title,
xlab = "Theoretical Quantiles",
ylab = "Sample Quantiles",
theme,
...
)
samp |
a numeric vector of the sample. |
theoretical_dist |
the distribution function to use to draw a theoretical
distribution. This can be any function that follows R's conventions for
distributions. That is, there needs to be a |
bins |
the number of bins to use for the histograms. |
probs |
numeric vector of length two, representing probabilities. Corresponding quantile pairs that define the line drawn. |
loess |
whether to include a Loess regression line. |
span |
if |
title |
plot title. |
xlab |
label for the x-axis. |
ylab |
label for the y-axis. |
theme |
a ggplot2 theme (optional). |
... |
other parameters passed to the |
a Q-Q plot.
pop_size <- 100000
samp_size <- 50
distributions <- data.frame(
unif_pop = runif(pop_size),
skew_pop = rchisq(pop_size, df = 5),
norm_pop = rnorm(pop_size, mean = 2, sd = 1)
)
# Draw random samples from each of our populations.
unif_samp <- sample(distributions$unif_pop, size = samp_size)
skew_pop <- sample(distributions$skew_pop, size = samp_size)
norm_pop <- sample(distributions$norm_pop, size = samp_size)
# Q-Q plots for our three samples
gg_qq_plot(unif_samp, title = 'Normal Quantile-Quantile Plot (Uniform Population)')
gg_qq_plot(skew_pop, title = 'Normal Quantile-Quantile Plot (Skewed Population)')
gg_qq_plot(norm_pop, title = 'Normal Quantile-Quantile Plot (Normal Population)')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.