I have a long data frame like the following:
data = data.frame(
id = rep(c(1, 2, 3, 4, 5, 6, 7), each = 5),
pt = rep(c("A", "A", "A", "B", "B", "B", "B"), each = 5),
value = rnorm(35, 10, 1)
)
id
here is the sample ID, while pt
is the patient ID. Not required information, but may help to understand the purpose. One pt
has multiple id
s, as these are replicates.
I want to make a pairwise scatterplot of the replicate samples. This means for a single pt
, I want all of the combinations of scatterplots for id
.
The desired output would be a facet grid with scatterplots for A_1 vs A_2, A_2 vs A_3, A_1 vs A_3, B_4 vs B_5, B_4 vs B_6, B_4 vs B_7, B_5 vs B_6, B_5 vs B_7, B_6 vs B_7
, in the format pt_id
.
How could this be done? If I were to convert this from long to wide, and then run pairs, I would get all combinations, but I am only interested in combinations from the same pt
and would like a facet_wrap object.
Thanks, Jack