Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QQ plot: More than two data

Tags:

plot

r

I wanted to graph a QQ plot similar to this picture:

http://i.stack.imgur.com/OmyCu.png

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:

http://i.stack.imgur.com/6VkgA.png

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.

like image 523
JM88 Avatar asked Nov 30 '13 10:11

JM88


People also ask

How do you compare two Q-Q plots?

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.

When would you need to draw a Q-Q plot?

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.

What is the difference between scatter plot and Q-Q plot?

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.

What is the difference between Q-Q plot and quantile plot?

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.


1 Answers

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"))

enter image description here

like image 70
Sven Hohenstein Avatar answered Oct 19 '22 00:10

Sven Hohenstein