get colors from seurat dimplot 获取ggplot对象的颜色

seurat color palette · Issue #257 · satijalab/seurat · GitHub 

How to pull the exact list of colors used in DimPlot? · Issue #2366 · satijalab/seurat · GitHub 

  p <- DimPlot(fibroblast,label = TRUE) # Generate the tSNE plot, but save it as an object
 
  
 pbuild <- ggplot2::ggplot_build(p) # Use ggplot_build to deconstruct the ggplot object
 pdata <- pbuild$data[[1]] # Pull the data used for the plot

 head(pdata )
 head(reducedDims(sds)$UMAP) 
 pdata=cbind(pdata,reducedDims(sds)$UMAP,[email protected]$cell.type,sds$cell.type)
  
 ucols <- pdata$colour # Get a vector of unique colors
  names(ucols) <- pdata$'sds$cell.type' # Add the groups to the vector of colors as names

  plot(reducedDims(sds)$UMAP,  pch = 16, cex = 0.5, col =ucols )
  lines(SlingshotDataSet(sds), lwd = 2, type = 'lineages', col = 'red')
  

get colors from seurat dimplot 获取ggplot对象的颜色_第1张图片

你可能感兴趣的:(算法)