I wanted to graph a QQ plot similar to this picture:
I managed to get a QQ plot using two samples, but I do not know how to add a third one to the plot. Here is my result:
Here is the code I used:
qqplot(table$Bedouin, table$Tunisia, xlim = c(-0.25,0.25), ylim = c(-025,0.25))
In my table data frame I have other populations I would like to add. But I can't.
Thank you in advance.
To compare two distributions use a quantile-quantile (Q-Q) plot. Divide the range (max value – min value) into equal-sized cells or bins. Count the number of data points that fall in each cell.
The purpose of Q Q plots is to find out if two sets of data come from the same distribution. A 45 degree angle is plotted on the Q Q plot; if the two data sets come from a common distribution, the points will fall on that reference line.
A Q-Q plot is a scatterplot created by plotting two sets of quantiles against one another. If both sets of quantiles came from the same distribution, we should see the points forming a line that's roughly straight.
The quantile-quantile plot is a graphical method for determining whether two samples of data came from the same population or not. A q-q plot is a plot of the quantiles of the first data set against the quantiles of the second data set.
I suppose you're looking for a scatterplot of sorted values since all variables are stored in the same data frame.
An example dataset:
set.seed(10)
dat <- data.frame(A = rnorm(20), B = rnorm(20), C = rnorm(20))
This is a way to create the plot with basic R functions:
# create a QQ-plot of B as a function of A
qqplot(dat$A, dat$B, xlim = range(dat), ylim = range(dat),
xlab = "A", ylab = "B/C")
# create a diagonal line
abline(a = 0, b = 1)
# add the points of C
points(sort(dat$A), sort(dat$C), col = "red")
# create a legend
legend("bottomright", legend = c("B", "C"), pch = 1, col = c("black", "red"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With