SydneyBioX / spicyR

https://sydneybiox.github.io/spicyR/
8 stars 4 forks source link

Update signifPlot #17

Closed ellispatrick closed 1 year ago

ellispatrick commented 2 years ago

We should update signifPlot to make a plot similar to Figure 5 in the head and neck paper https://www.biorxiv.org/content/10.1101/2022.04.19.488697v1.full . Here was the code...

size <- -log10(test$p.value[,2]) groupA <- test$coefficient[,1]sqrt(pi)2/sqrt(10)/100 groupB <- (test$coefficient[,1] + test$coefficient[,2])sqrt(pi)2/sqrt(10)/100 cellTypeA <- unlist(lapply(strsplit(rownames(test$statistic), ""), function(x)x[1])) cellTypeB <- unlist(lapply(strsplit(rownames(test$statistic), ""), function(x)x[2]))

df <- data.frame(cellTypeA, cellTypeB, groupA, groupB, size, stat = test$statistic[,2], pvalue = test$p.value[,2], sig = test$p.value[,2] < 0.05) rownames(df) <- rownames(test$statistic)

library(ggnewscale)

shape.legend = c(NP = "\U25D6", P = "\U25D7")

df.shape = data.frame(cellTypeA = c(NA,NA), cellTypeB = c(NA,NA), size = c(1,1), condition = c("NP", "P"))

ggplot(df, aes(x = cellTypeA, y = cellTypeB, size = size)) + scale_colour_gradient2(low ="#4575B4", mid = "white", high = "#D73027", midpoint = 0, breaks = c(-1.66, -1, 0, 1, 2, 3, 4), labels = c("avoidance", -1, 0, 1, 2, 3, "interaction")) + geom_point(aes(colour = pmin(groupA, 4)), shape="\u25D0") + geom_point(aes(colour = pmin(groupB, 2)), shape="\u25D1") + geom_point(data= df.shape, aes(shape = condition))+ scale_shape_manual(values = shape.legend) + guides(shape = guide_legend(override.aes = list(size=5))) + labs(colour = "Localisation", shape = "Condition") + new_scale_color() + geom_point(shape=1, aes(colour = factor(sig))) + scale_color_manual(values = c("TRUE" = "black", "FALSE" = "white"), labels = c("p-value < 0.05", "")) + theme_classic() + theme( axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0)) + labs(x = "Cell type i", y = "Cell type j", size = "-log10 p-value", colour = "") + guides(colour = guide_legend(override.aes = list(size=5)))