Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. library(Seurat)
  2. library(ggplot2)
  3. library(ggthemes)
  4. library(ggpubr)
  5.  
  6. make_expression_plots <- function(seuset, feature, reduction = NULL) {
  7. stopifnot(length(feature) == 1)
  8.  
  9. if (!feature %in% rownames(seuset)) {
  10. warning(paste("Feature", feature, "not found"), call. = FALSE)
  11. return(NULL)
  12. }
  13.  
  14. # define base theme
  15. base_theme <- theme(
  16. aspect.ratio = 1,
  17. plot.margin = unit(c(5, 5, 5, 5), "mm"),
  18. plot.title = element_blank()
  19. )
  20.  
  21. dr_idents <- DimPlot(seuset, group.by = "ident", reduction = reduction) +
  22. scale_color_tableau(palette = "Tableau 20") +
  23. theme_void() +
  24. base_theme
  25.  
  26. dr_feature <- FeaturePlot(seuset, features = feature, reduction = reduction, min.cutoff = "q10") +
  27. scale_color_viridis_c(option = "inferno") +
  28. theme_void() +
  29. base_theme
  30.  
  31. vln <- VlnPlot(seuset, features = feature, pt.size = 0.3, sort = TRUE) +
  32. scale_fill_viridis_d(direction = -1) +
  33. base_theme +
  34. theme(
  35. legend.position = "none",
  36. axis.title.x = element_blank(),
  37. panel.grid.major.y = element_line(colour = "grey75")
  38. )
  39.  
  40. ridge <- RidgePlot(seuset, features = feature, sort = TRUE) +
  41. scale_fill_viridis_d(direction = -1) +
  42. base_theme +
  43. theme(
  44. legend.position = "none",
  45. axis.title.y = element_blank(),
  46. axis.title.x = element_text(hjust = 0.5),
  47. panel.grid.major.y = element_line(colour = "grey75")
  48. )
  49.  
  50. # combine plots and add global title
  51. CombinePlots(
  52. list(dr_idents, dr_feature, vln, ridge),
  53. ncol = 2, axis = "tb"
  54. ) %>%
  55. ggpubr::annotate_figure(
  56. top = text_grob(feature, face = "bold", size = 18)
  57. )
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement