Advertisement
crdougla345

Violin Plot for TCGA Data

May 16th, 2023 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.59 KB | None | 0 0
  1. library(ggplot2)
  2. library(dplyr)
  3. library(forcats)
  4. library(hrbrthemes)
  5. library(viridis)
  6. library(tidyr)
  7. library(ggsignif)
  8.  
  9. setwd("C:/Users/Christopher/OneDrive/A_UC_LabAdmin_Projects/Research_Projects/R21_PRELIMINARY_GBM_PROJECT_COLLABORATION/Data_Materials/ExternalBioinformaticDatasets/timeDB/")
  10.  
  11. # Load Cell and Clinical Information
  12. lgg_cell <- read.csv(file="CD_TCGA_LGG_2_xCell_full.csv", header=TRUE)
  13. lgg_clinical <- read.csv(file="CD_TCGA_LGG_2_Clinical.csv", header=TRUE)
  14.  
  15. # Modify matrices
  16. rownames(lgg_cell) <- lgg_cell[,1]
  17. rownames(lgg_clinical) <- lgg_clinical[,1]
  18. lgg_cell <- lgg_cell[,-1]
  19. lgg_clinical <- lgg_clinical[,-1]
  20.  
  21. # Combine matrices by TCGA sample id
  22. lgg_cell[rownames(lgg_clinical),colnames(lgg_clinical)] <- lgg_clinical  
  23.  
  24.  
  25. # Create intervals for n_age and pfs
  26. lgg_cell$age_int <- cut_interval(lgg_cell$n_age, n = 2)
  27. lgg_cell$pfs_int <- cut_interval(lgg_cell$pfs, n = 2)
  28.  
  29.  
  30. jpeg(file=paste("race-sex.jpeg", sep=""), width = 2000, height = 2000)
  31. lgg_cell %>%
  32.   mutate(day = fct_reorder(c_race, c_gender)) %>%
  33.   mutate(day = factor(c_race, levels=c("Asian", "White", "Black"))) %>%
  34.   drop_na(c("age_int", "c_gender")) %>%
  35.   ggplot(aes(fill=c_gender, y=Monocytes, x=age_int)) +
  36.   geom_violin(position="dodge", alpha=0.5, outlier.colour="transparent") +
  37.   scale_fill_viridis(discrete=T, name="") +
  38.   theme_ipsum()  +
  39.   xlab("") +
  40.   ylab("Tip (%)") +
  41.   geom_signif(
  42.     comparisons = list(c("female, [14,50.5]", "male, [14,50.5]")), # Specify the pairs to compare
  43.     map_signif_level = TRUE, # Show the significance level as stars
  44.     y_position=0.1
  45.   )
  46. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement