Created
January 3, 2020 16:22
-
-
Save jebard/e81d7d0657ef415cb252dfb868314a23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wt.subset <- subset(immune.combined, subset = stim == c("CTRL")) | |
ko.subset <- subset(immune.combined, subset = stim == c("Trp63-")) | |
FeaturePlot(immune.combined,features = c("Foxi2","Foxc1"),split.by = "stim") | |
gg1 <- plot_split_by_feature(wt.subset,ko.subset,c("Foxi2")) | |
gg2 <- plot_split_by_feature(wt.subset,ko.subset,c("Foxc1")) | |
ggsave(file="Foxi2_Foxc1.png",plot_grid(gg1,gg2,ncol=1)) | |
plot_split_by_feature<- function(wildType, knockout, feature ) { | |
ptSize = .4 | |
tmp <- data.frame("UMAP_1"= wildType@reductions$umap@cell.embeddings[,1], | |
"UMAP_2"= wildType@reductions$umap@cell.embeddings[,2], | |
LogNorm = wildType@assays$RNA@data[rownames(wildType@assays$RNA@data) %in% c(feature),]) | |
tmp2 <- data.frame("UMAP_1"= knockout@reductions$umap@cell.embeddings[,1], | |
"UMAP_2"= knockout@reductions$umap@cell.embeddings[,2], | |
LogNorm = knockout@assays$RNA@data[rownames(knockout@assays$RNA@data) %in% c(feature),]) | |
min = min(tmp$LogNorm,tmp2$LogNorm) | |
max = max(tmp$LogNorm,tmp2$LogNorm) | |
g1 <- ggplot(tmp, aes(x=UMAP_1, y=UMAP_2,colour=LogNorm)) + geom_point(size=ptSize) + theme_cowplot() + | |
scale_color_gradientn(colors = c("gray","blue"), | |
limits = c(min,max)) + xlim(-13, 13) + | |
ylim(-13,13) +ggtitle("Wildtype") + | |
theme(plot.title = element_text(hjust = 0.6,vjust = .2)) | |
g2 <- ggplot(tmp2, aes(x=UMAP_1, y=UMAP_2,colour=LogNorm)) + geom_point(size=ptSize) + theme_cowplot() + | |
scale_color_gradientn(colors = c("gray","blue"), | |
limits = c(min,max)) + xlim(-13, 13) + | |
ylim(-13,13) + ggtitle("Knockout") + | |
theme(plot.title = element_text(hjust = 0.6,vjust = .2)) | |
plot_grid(g1,g2,labels = c(feature),label_x = .9) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment