Black Lives Matter. Please consider donating to Black Girls Code today.

geom_qq in ggplot2

How to make a quantile-quantile plot in ggplot2 using geom\_qq and geom\_qq\_line.


New to Plotly?

Plotly is a free and open-source graphing library for R. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

Basic geom_qq graph

A quantile-quantile graph is used to determine whether a range of numbers follows a certain distribution: the closer the data points are to being a straight line, the closer the data is to the distribution. (The default distribution is normal.) This dataset gives the daily change in the S&P 500, as well as Apple, Microsoft, IBM, and Starbucks stocks between January 2007 and February 2016.

library(plotly)
stocks <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/stockdata2.csv",
                   stringsAsFactors = FALSE)

p <- ggplot(stocks, aes(sample=change)) +
  geom_qq()

ggplotly(p)