# Mapping a list of cells in seurat featureplot

I have 209 cells, I clustered them by Seurat to 4 clusters. By Featureplot I am able to track a gene in clusters:

Higher color shows higher expression.

Now, for some genes I want to highlight some cells in Featureplot so that apart from yellow or red colours I want to colour a subsets of cells with another color. I mean I want to map a list of cells in Featureplot or tSNE plot. Let's say I want to know the location of cells 1, 4, 80 and highlight them with another color. My Seurat object in this link.

Seurat itself beautifully maps the cells in Featureplot for defined genes with a gradient of colours showing the level of expression. Saying I have genes A and B, in excel.

I have coloured cells that express a gene > mean + se, < mean - se or between these values. For instance, for this gene, 36 cells express this gene > mean + se, I want to map these cells in Featureplot or tSNE plot in distinct colour so I can locate them in clusters easily. Something like binary (on off) expression to relative expression.

How I can change the colour of some cells based on my threshold for this gene please?

• Do you mean in this exact plot to put a separated color for the cells you want? I don't think this is possible. From what I know, you can put a color code based on gene expression (the situation in your plot) or a color code for a group of cells you want to highlight. But as far as I know both options are incompatible. One thing you can do its to color cells based on gene expression and then highlight the cells you want in a different way. For instance, changing its shape from a dot to a triangle. Do you think this could fit your needs?
– plat
Jun 13 '18 at 14:59
• Thanks a lot, I think yes. I don't know how to ask Seurat to change the max and min of expression of a certain gene based on my desire. That would be nice if I could color my 209 cells for gene A, if gene A is expression > mean + se, < mean + se, or whatever criteria. The problem is this, in current Featureplot I don't know if a red cell is expressing genes A and B equally, higher or lower. Jun 13 '18 at 15:16
• I will put an answer of how to do it because it is a little bit tricky
– plat
Jun 13 '18 at 15:17

To color the TSNEPlot, you can generate a new column in metadata with the expression levels (High, low, etc). Then use pt.shape to set a shape for each identity.

To show binary expression based on expression you first have to define the list of cells that are below or over your threshold. Once you have those lists you can use SetIdent() in Seurat to color those groups.

load(file= "~/seuset_16.RData")

high <- c("s1.1","s1.4", "s1.80")
low <- setdiff(colnames(seuset_h16@data), high)
seuset_h16 <- SetIdent(seuset_h16, cells.use = high, ident.use = "high")
seuset_h16 <- SetIdent(seuset_h16, cells.use = low, ident.use = "low")
seuset_h16 <- StashIdent(seuset_h16, save.name = "expr")
seuset_h16 <- SetAllIdent(seuset_h16, id="res.1")
t <- TSNEPlot(seuset_h16, pt.size = 2, do.return = T, pt.shape ="expr")
t


high <- c("s1.1","s1.4", "s1.80")
low <- setdiff(colnames(seuset_h16@data), high)
seuset_h16 <- SetIdent(seuset_h16, cells.use = high, ident.use = "high")
seuset_h16 <- SetIdent(seuset_h16, cells.use = low, ident.use = "low")
t <- TSNEPlot(seuset_h16, pt.size = 2, do.return = T, colors.use = c("red", "grey"), do.hover =T, data.hover =c("ident", "res.1))
t


• Excuse me, I have 4 clusters made by these 209 cells so I want to know the exact location of cells that are below or over the threshold. For example cell 183 itself places in cluster 0. My question is, by your code is the location of my cells will change in tSNE plot or 4 clusters be reserved???? For instance, this is a link of a picture of my original tSNE plot, I want to know the location of a cell in clusters as it has already been drive.google.com/file/d/1ipXg2Nb9lM_JgIH6WgVV-PoLhEtzLWif/… Jun 13 '18 at 18:14
• Sorry, by doing hover I noticed all of cells have been labelled by 1, and high or low ident. That means I can't differentiate the cluster identities anymore (clusters 0, 1, 2, 3). How can color the cells and knowing their cluster identities? Jun 13 '18 at 18:45
• The cluster identity doesn't change, you can add data.hover = c("ident", "res.1"). res.1 is the column name for your clustering at resolution 1 that can be found in object@meta.data. By including this in data.hover you will be able to see the cluster number. Jun 13 '18 at 18:58
• Just edited based on your questions. please upvote answer if this helped. I am new and starting to build reputation! best of luck with your data Jun 13 '18 at 21:15
• Yes and no. Using 3 color schemes won't work but you can leverage the ggplot shapes for this. shape 21-25 allow you to have both fill and color. do.return = T, returns a ggplot object and using geom_point() allows you to set a shape. You can then use different schemes. for example high threshold open and low threshold filled shapes. What is the scientific information/answer you want to display. There are probably much simpler ways to convey that information. Jun 14 '18 at 16:09

Since I don't think it is possible to have two color schemes in a single plot (one for expression and one for highlighting some cells) I will suggest other approach.

A possible option to do this could be to change the shape in the plot of the cells that you want to highlight and maintain the color code for expression.

I add a code that works for this purpose with the R object provided. Maybe there are easier ways to do that but this is working:

# Run PCA
seuset_h16 <- RunPCA(seuset_h16,
pc.genes = seuset_h16@var.genes)
# Run tSNE
seuset_h16 <- RunTSNE(object = seuset_h16,
dims.use = 1:10,
do.fast = TRUE)
# Find clusters of cells
seuset_h16 <- FindClusters(object = seuset_h16,
reduction.type = "pca",
dims.use = 1:10,
resolution = 0.6,
print.output = 0,
save.SNN = TRUE)
# Store output from FeaturePlot (do.return = T)
fp <- FeaturePlot(object = seuset_h16,
features.plot = c("DDB_G0273311"),
cols.use = c("grey", "orange"),
reduction.use = "tsne",
do.return = T)
# Add extra column in the data with the cells to be highligthed
fp$DDB_G0273311$data$cellToDisplay <- as.factor(ifelse(row.names(fp$DDB_G0273311$data) %in% c("s1.1", "s1.4", "s1.80"), "group2", "group1")) # Modify color and shape in the plot # lapply is needed since the object returned in fp is a list lapply(fp, +, geom_point(aes(shape=cellToDisplay, colour = gene, size = 0.4)))  This is the output, with three cells highlighted as triangles and the rest as dots. You can play a little bit with shapes and sizes if you want a clearer display: • First of all thanks a lot for your time, in last piece of code says so > lapply(fp, +, geom_point(aes(shape=cellToDisplay, colour = gene, size = 0.4))) Error in FUN(X[[i]], ...) : non-numeric argument to binary operator Jun 13 '18 at 15:51 • Is working for me, but try with this: lapply(fp, function(x) { x + geom_point(aes(shape=cellToDisplay, colour = gene, size = 0.4))}) – plat Jun 13 '18 at 15:54 • Says that > apply(fp, function(x) { x + geom_point(aes(shape=cellToDisplay, colour = gene, size = 0.4))}) Error in match.fun(FUN) : argument "FUN" is missing, with no default Jun 13 '18 at 15:57 • I think you miss to copy the l from lapply. We are using the lapply function not apply function. Could be that? – plat Jun 13 '18 at 16:11 This updates the answer provided by Mack123456 to Seurat 3 and works in 3.1.2. There are some minor difference with colouring, but it is otherwise similar. The HoverLocator plot throws a warning, all about the plot colours and title, but the plot is fine and labels appear as expected. load(file= "~/seuset_16.RData") seuset_h16 <- UpdateSeuratObject(seuset_h16) high <- c("s1.1","s1.4", "s1.80") low <- setdiff(rownames(seuset_h16@meta.data), high) Idents(seuset_h16, cells = high) <- "high" Idents(seuset_h16, cells = low) <- "low" seuset_h16$expr <- Idents(seuset_h16)
Idents(object = seuset_h16) <- "res.1"

t <- DimPlot(seuset_h16, pt.size = 2, shape.by = "expr")
t

t2 <- DimPlot(seuset_h16, pt.size = 2, cols = c("red", "orange","green","blue"))
t2 <- HoverLocator(plot = t2, information = FetchData(object = seuset_h16, vars = c("ident", "res.1")))
t2