# A tibble: 735 × 5
aminoacid heptad position ppi final_position
<chr> <int> <chr> <dbl> <fct>
1 * 1 a 0.601 1a
2 P 1 a 0.952 1a
3 G 1 a 0.686 1a
4 C 1 a 1.02 1a
5 M 1 a 1.06 1a
6 R 1 a 0.432 1a
7 K 1 a 0.770 1a
8 E 1 a 1.02 1a
9 D 1 a 0.786 1a
10 N 1 a 0.720 1a
# ℹ 725 more rows
We start by generating a single heatmap of PPI values for each amino acid mutation at each position. We illustrate two ways of generating ‘hierarchical’ labels for the x-axis, indicating both the heptad number and the relative position within a heptad.
Next we generate a grid of many such heatmaps. The two plots below illustrate two different ways of displaying the faceting information in the plot.
Code
## Generate random data for nbr x nbr pairsnbr <-10set.seed(123)## ... random namesnms <-vapply(seq_len(nbr), function(i) paste(sample(LETTERS, 5, replace =TRUE), collapse =""), "")allpairs <-expand.grid(nms, nms)## ... generate dataalldat <-do.call(bind_rows, lapply(seq_len(nrow(allpairs)), function(i) { tmp <- ppis tmp$ppi <-runif(nrow(ppis), min =0.4, max =1.1) tmp$p1 <- allpairs[i, 1] tmp$p2 <- allpairs[i, 2] tmp}))ggplot(alldat,aes(x = final_position, y = aminoacid, fill = ppi)) +geom_tile() +scale_fill_gradientn(colours =c("#811c11", "white", "#aecccb"), values =rescale(c(0.4, 1, 1.1)),guide ="colorbar", limits =c(0.4, 1.1), na.value ="white", name ="PPI") +facet_grid(p1 ~ p2, scales ="free", switch ="y") +scale_x_discrete(expand =expansion(mult =c(0, 0))) +labs(x ="", y ="") +theme_bw() +theme(axis.text =element_blank(),axis.ticks =element_blank(),panel.border =element_blank(),panel.grid.major =element_blank(), panel.grid.minor =element_blank(),legend.position ="none",strip.background =element_blank())
Code
## Alternative display, without strip titles but adding the labels to each panelaxis_titles <- alldat %>% dplyr::select(p1, p2) %>% dplyr::distinct()ggplot(alldat) +geom_tile(aes(x = final_position, y = aminoacid, fill = ppi)) +scale_fill_gradientn(colours =c("#811c11", "white", "#aecccb"), values =rescale(c(0.4, 1, 1.1)),guide ="colorbar", limits =c(0.4, 1.1), na.value ="white", name ="PPI") +facet_grid(p1 ~ p2, scales ="free", switch ="y") +labs(x =NULL, y =NULL) +geom_text(data = axis_titles, aes(label = p2), hjust =0.5, x =35/2, y =-1, color ="grey10", size =2) +geom_text(data = axis_titles, aes(label = p1), angle =90, vjust =0.5, x =-1, y =21/2, color ="grey10", size =2) +coord_cartesian(clip ="off") +theme(plot.margin =margin(b =10, l =10, r =5, t =5)) +scale_x_discrete(expand =expansion(mult =c(0, 0))) +theme_bw() +theme(axis.text =element_blank(),axis.ticks =element_blank(),panel.border =element_blank(),panel.grid.major =element_blank(), panel.grid.minor =element_blank(),panel.spacing =unit(0.6, "line"), legend.position ="none",strip.background =element_blank(),strip.text =element_blank())
Remarks
The combined plot could also have been generated with cowplot, which would give a bit more flexibility in the display of each panel - however, with many panels, it is a lot more resource intensive.