I want to make a matrix of QQ plots like the one posted here
[Sample set QQ plot comparing different elements to each other] . Below is a condensed version of my data frame. For each scan (a-c), I want a QQ plot to compare the grain size (numerical values below the element names) for each chemical element (s, fe, cr, zr) to each other. Because I have many scans, I will need to make this matrix of QQ plots multiple times.
I am pretty new to R so specific code to help me make these plots would be appreciated.
Thank you
# Packages
library(tidyverse)
library(ggplot2)
library(dplyr)
library(GGally)
print(df, n = 27)
scan grain s fe cr zr
1 a 1 22 21 13 25
2 a 2 33 31 23 35
3 a 3 44 41 45 45
4 a 4 55 51 56 56
5 a 5 66 61 67 65
6 a 6 66 71 78 75
7 a 7 77 81 89 85
8 a 8 88 82 97 95
9 a 9 92 93 72 97
10 b 1 23 22 14 26
11 b 2 34 32 24 36
12 b 3 45 42 46 46
13 b 4 56 52 57 57
14 b 5 67 62 68 66
15 b 6 67 72 79 76
16 b 7 78 82 90 86
17 b 8 89 83 98 96
18 b 9 93 94 73 98
19 c 1 24 23 15 27
20 c 2 35 33 25 37
21 c 3 46 43 47 47
22 c 4 57 53 58 58
23 c 5 68 63 69 67
24 c 6 68 73 80 77
25 c 7 79 83 91 87
26 c 8 90 84 99 97
27 c 9 94 95 74 99
I have used
ggplot( aes(sample = diameter, color = element, shape = element, )) +
stat_qq() +
stat_qq_line() +
facet_wrap(~ scan, nrow = 3)
to compare each element to the theoretical quantile, but not to each other element.
I tried using GGally with ggpairs(df, columns = 3:6) (https://i.stack.imgur.com/wH1mt.png) This made a matrix, but I can’t figure out how to make each plot a QQ plot
.
Are you looking for something like this?
If yes, this type of problems generally has to do with reshaping the data. The format should be the long format and the data is in wide format. See this post on how to reshape the data from wide to long format.
With the data in long format, map
valueto thesampleaesthetic then plot byname(withfacet_wrap).Created on 2024-03-29 with reprex v2.1.0
Data