1

Q-Q plot is a useful graphical device used to check for example normality of residuals. Q-Q plot is constructed by putting theoretical quantiles on x-axis and observed quantiles on the y-axis. In ggplot, this can be easily done using geom_qq and stat_qq. I would like to produce a wormplot, which is like a Q-Q plot, but on the y-axis, it has a difference between theoretical and observed quantiles (see the figure).

Is there a way to do this in ggplot? For example, is there a simple way to change the y-axis of the geom_qq to show the difference between theoretical and observed quantiles? I know it should be possible to calculate observed quantiles manually, but this would not work well if I would like to create plots of multiple groups or using facets, since then I would also need to calculate the observed quantiles manually for each group separately.

enter image description here

user2173836
  • 1,461
  • 2
  • 15
  • 19
  • Have you checked this tutorial ? Maybe it can help you : https://www.r-bloggers.com/2020/08/q-q-plots-and-worm-plots-from-scratch/ – Basti Apr 14 '21 at 11:47
  • no, thanks! It seems like my answer is there, although I was hoping there is a solution that would not require calculating these quantities manually or learning how to make my own stat function. – user2173836 Apr 14 '21 at 11:56
  • Good news is that once you make your own stat function, you can reuse it everywhere :) – chemdork123 Apr 15 '21 at 01:35
  • Hi, could any of you help me on this topic? https://stackoverflow.com/questions/67862074/worm-plot-residuals-graph-in-ggplot2 – user55546 Jun 12 '21 at 16:29
  • @user55546 see my answer bellow – user2173836 Jun 13 '21 at 20:42

1 Answers1

0

blogpost mentioned in comments contains a guide to code your own statfunctions to create such plots yourself

Otherwise, library qqplotr https://aloy.github.io/qqplotr/index.html contains an option detrend=True which basically produce wormplots with accompanying confidence bands.

If you want lines, and not a band, just do fill=NA, color='black', size=0.5

user2173836
  • 1,461
  • 2
  • 15
  • 19