gotData<-function(seurat.obj,features,groups){ mat<-GetAssayData(data,assay = "RNA",slot = "data")[features,] plotData<-mat%>% as.data.frame()%>% tibble::rownames_to_column(var="gene")%>% as_tibble()%>% tidyr::pivot_longer(names_to = "cell",values_to="exp",cols=2:(ncol(mat)+1)) cellmeta<-data@meta.data%>% tibble::rownames_to_column(var="cell")%>% as_tibble()%>% select(cell,sym(groups)) plotData<-plotData%>% left_join(cellmeta,by="cell")%>% setNames(c("gene","cell","value","cellID")) plotData }
plot_stacked_violin<-function(plotData,xlab,ylab,cols){ ggplot(plotData,aes(y=cellID,x=value,fill=cellID))+ geom_violin()+ facet_wrap(.~gene)+ theme_test()+ xlab(xlab)+ ylab(ylab)+ scale_fill_manual(values = cols)+ theme(panel.spacing=unit(0,"cm"), strip.background = element_rect(fill="transparent",color = "white"), axis.text.x = element_blank(), axis.ticks.x = element_blank(), panel.border = element_rect(size=0.7,colour = "black"), strip.text = element_text(size=10,face = "italic"), axis.text.y = element_text(size = 11.5,face="bold"), axis.title.y = element_text(size = 13))+ NoLegend() }
|