Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading