plot.mat <- mat.receptor[node.data$Gene[which(node.data$Type == "Receptor") ], ]
plot.mat <- t(scale(t(plot.mat)))
plot.cell <- c("TB-CD4T_naive","TB-CD4T_Tem","TB-CD4T_Treg","TB-CD8T_naive","TB-CD8T_Tm",
"TB-CD8T_Tem","TB-NKcell","TB-B_cell","TB-pDC","TB-Monocyte_CD14")
plot.total.edge <- NULL
plot.total.node <- NULL
for (i in 1:length(plot.cell)) {
sub.1 <- edge.data
sub.1$Group <- plot.cell[i]
sub.2 <- node.data
sub.2$Group <- plot.cell[i]
sub.2$ReceptorExp <- plot.mat[match(sub.2$Gene, rownames(plot.mat)), plot.cell[i]]
sub.2 <- sub.2[order(sub.2$ReceptorExp), ]
plot.total.edge <- rbind(plot.total.edge, sub.1)
plot.total.node <- rbind(plot.total.node, sub.2)
}
plot.total.node$ReceptorExpMod <- plot.total.node$ReceptorExp
plot.total.node$ReceptorExpMod[which(plot.total.node$ReceptorExp > 2)] = 2
plot.total.node$ReceptorExpMod[which(plot.total.node$ReceptorExp < -2)] = -2
plot.total.node$Group <- factor(as.character(plot.total.node$Group), levels = plot.cell)
plot.total.edge$Group <- factor(as.character(plot.total.edge$Group), levels = plot.cell)
gg <- ggplot()
gg <- gg + geom_segment(mapping = aes(x = from.x, y = from.y, xend = to.x, yend = to.y), color = "#CCCCCC", size = 0.05, data = plot.total.edge)
gg <- gg + geom_point(mapping = aes(x = pos.x, y = pos.y), color = "#CCCCCC", size = 0.2, shape = 16,
data = plot.total.node[which(plot.total.node$Type == "Ligand"), ])
gg <- gg + geom_point(mapping = aes(x = pos.x, y = pos.y, color = ReceptorExpMod), size = 2, shape = 18,
data = plot.total.node[which(plot.total.node$Type == "Receptor"), ])
gg <- gg + theme_void() + facet_wrap(~ Group, ncol = 5)
gg <- gg + labs(x = "", y = "", title = paste0("PPI"))
gg <- gg +scale_colour_gradientn(colors = c("#00408e",
"#007ed8","#62aee5","#a8dcff",
"#fffef3",
"#ffca79","#e5524c","#c52f4e",
"#D01910"))
gg