
Hello,

I can go through the Seurat all the code from here: https://satijalab.org/seurat/archive/v3.0/visualization_vignette.html.

My question is: Is that possible that I can get the frequency of one gene in one cluster?

Thank you in advance for your great help!

Best Regards,

Yue







<a href="https://ibb.co/PZZyQx3"><img src="https://i.ibb.co/rGGhskT/2021-10-05-10-21-14.png" alt="2021-10-05-10-21-14" border="0" /></a>
`DotPlot` computes the fraction of cells expressing a gene in each group (metadata column), so you can cheat a little and extract the results from it [[source](https://github.com/satijalab/seurat/issues/1888)].

    library("Seurat")

    features <- c("PECAM1", "CD14")
    group_column <- "clusters"
    
    perc_exp <- DotPlot(seu, features=features, group.by=group_column)$data[, c("features.plot", "id", "pct.exp")]

The returned data will look something like this:

    > perc_exp
      features.plot          id  pct.exp
    1        PECAM1 Endothelial 26.55087
    2          CD14 Endothelial 37.21239
    3        PECAM1     T Cells 57.28534
    4          CD14     T Cells 90.82078

 You can then plot this easily using ggplot.

    library("ggplot")

    ggplot(perc_exp, aes(x=id, y=pct.exp, fill=id)) +
      geom_col() +
      facet_wrap(~features.plot)

![enter image description here][1]


----------

Example data used.

    perc_exp <- structure(list(features.plot = c("PECAM1", "CD14", "PECAM1", 
    "CD14"), id = c("Endothelial", "Endothelial", "T Cells", "T Cells"
    ), pct.exp = c(26.55086631421, 37.212389963679, 57.2853363351896, 
    90.8207789994776)), class = "data.frame", row.names = c(NA, -4L
    ))

  [1]: /media/images/9474f865-212b-4bbf-beb4-00fa57a5