If x and y have the same length, do qqplot(x,y) and plot(sort(x),sort(y)) yield the same plot in R? - Stack Overflow

admin2025-04-17  3

This is a question about R. Let x and y be two numerical vectors with the same length. Am I right that the commands qqplot(x,y) and plot(sort(x),sort(y)) yield the same plot in R?

I tried two approaches to find the answer:

  1. I defined x = qqnorm(100) and y = qqnorm(100) and in this case the two plots looked equal to me.
  2. I tried to compare the plots with the code qqplot(x,y) == plot(sort(x),sort(y)) and I got the ouput logical(0) in addition to a plot. I am not sure how to interpret the result. In fact I was expecting to get an error message since the functions qqplot and plot yields objects with different classes, namely qqplot returns a list whereas plot returns NULL.

This is a question about R. Let x and y be two numerical vectors with the same length. Am I right that the commands qqplot(x,y) and plot(sort(x),sort(y)) yield the same plot in R?

I tried two approaches to find the answer:

  1. I defined x = qqnorm(100) and y = qqnorm(100) and in this case the two plots looked equal to me.
  2. I tried to compare the plots with the code qqplot(x,y) == plot(sort(x),sort(y)) and I got the ouput logical(0) in addition to a plot. I am not sure how to interpret the result. In fact I was expecting to get an error message since the functions qqplot and plot yields objects with different classes, namely qqplot returns a list whereas plot returns NULL.
Share Improve this question asked Jan 30 at 18:31 FilippoFilippo 1131 silver badge4 bronze badges 2
  • 1 It is a pity that the comments of the reviewers got lost, since the question got mostly answered in the comments. – Filippo Commented Jan 30 at 18:33
  • 1 Well, the reviewers should not answer the question in Staging Ground: meta.stackoverflow.com/questions/431282/… That said, they are not lost: stackoverflow.com/staging-ground/79399995 – M-- Commented Jan 30 at 19:50
Add a comment  | 

1 Answer 1

Reset to default 1

They are plotting the same thing.

Compare print(qqplot(x,y)) to print(plot(sort(x),sort(y))) and you'll see why the comparison is unequal. The plot function doesn't return a value; it just renders the plot. But the qqplot is returning something, the sorted arrays in a list.

Btw, you can rename the plot axis labels to make them look the identical: plot(sort(x),sort(y), xlab = "x", ylab = "y")

转载请注明原文地址:http://www.anycun.com/QandA/1744897977a89179.html