Vincenzo
Vincenzo

Reputation: 365

How to use ggplot to make a qqplot to compare the distribution of two variables?

I'd like to know how is possible to make a qqplot with ggplot2 that compares two distributions and not a distribution to a theoretical distribution. I want something like this:

qqplot(iris$Petal.Length, iris$Petal.Width)

that compares the quartiles of Petal.Length and Petal.Width in iris dataset, but using ggplot2.

Upvotes: 0

Views: 349

Answers (1)

Maël
Maël

Reputation: 51994

One easy way to reproduce the plot is to convert the qqplot call to a dataframe and then plot it with ggplot2:

qq <- as.data.frame(qqplot(iris$Petal.Length, iris$Petal.Width, plot.it = FALSE))
ggplot(qq) + 
  geom_point(aes(x = x, y = y))

enter image description here

Upvotes: 1

Related Questions