SecretIndividual
SecretIndividual

Reputation: 2549

ggplot/qqplotr returns error on data format

I am trying to create a QQ and/or PP plot from the air_time data inside the flights data frame belonging to the nycflights13 package. I am using ggplot with qqplotr.

This is my code:

library(nycflights13)
library(qqplotr)

ggplot(data = flights$air_time, mapping = aes(sample = norm)) +
  stat_qq_band() +
  stat_qq_line() +
  stat_qq_point() +
  labs(x = "Theoretical Quantiles", y = "Sample Quantiles")

When I try to run this I get the error:

Error: `data` must be a data frame, or other object coercible by `fortify()`, not a numeric vector

What is causing this error and how do I fix it? I normally call ggplot as follows so I do not know if there could be issues there:

ggplot(flights, air_time, aes(sample = norm))

Upvotes: 1

Views: 321

Answers (1)

Edward
Edward

Reputation: 19514

Change the sample argument to reflect the variable inside the data.

Air_time <- flights[, "air_time"] # Or select a random sample to save time
ggplot(data = Air_time, mapping = aes(sample = air_time)) +
  stat_qq_band() +
  stat_qq_line() +
  stat_qq_point() 

Upvotes: 3

Related Questions