text: user15922: I am looking for a way to present some single-cell RNA sequencing data on expression of a certain gene. My dataset has 2 variables, cell type and condition. I'm looking to create a grouped aligned scatter plot bar graph of the expression of the gene, where the y-axis is expression levels, while X axis is the different cell types, with each cell type having 2 bars (1 for healthy, 1 for diseased). My dataset has 3 healthy and 3 diseased samples, but all of the data is integrated into a Seurat object. To first create an aligned scatter plot bar graph, what I did was generate a DotPlot for the expression of gene X in each sample, split by cell-type. Then I realized that DotPlot() prints out a data table with values including avg.exp, pct.exp and avg.scaled.exp. I used the avg.exp metric to plot the data, but I was posting this question to see if there are other ways I can access and present expression data from a Seurat object. Is the way I've presented accurate? I've posted a sample bar graph of what I'm looking for, and the main question is how I can gather the expression levels across cell types AND diseased or healthy condition.
  Thanks!
  
  
  user8550: In single-cell data a bargraph with error bar is not usually shown since the gene expression does not have a normal distribution due to drop-outs. A violin-plot is commonly used. In your case, first set the active.ident to cell types
  seuratObj <- SetIdent(seuratObj , value = "Cell.Types")
  
  Then call the violin plot
  VlnPlot(seuratObj , features = "geneX", split.by = "condition")
  
  If you still specifically need bargraph, you can get the output of the violin plot as a dataframe and then draw the barplot.
  
  user15952: Following the answer of @Ajay.
  You can add + geom_boxplot() after the command to turn the violin plot to a box plot.
  As for the barplot, you can do it with these:
  # the object is your seurat object
  data.df <- object@meta.data[, c("celltypes", "condition")]
  data.df["value"] <- object$RNA@data["geneX", ]
  data.df <- data.df %>% mutate(group = paste(celltypes, condition, sep=":"))
  
  # remove cells that do not express the gene
  data.df <- data.df %>% filter(value > 0)
  
  data.df.2 <- data.df %>% group_by(group) %>% summarise(sd=sd(value),value=mean(value))
  X <- str_split(data.df.2$'group', ":", 2, simplify=TRUE)
  data.df.2$'celltypes' <- X[, 1]
  data.df.2$'condition' <- X[, 2]
  
  ggplot(data.df.2, aes(fill=condition, y=value, x=celltypes)) + 
      geom_bar(color="black", position="dodge", stat="identity") +
      geom_errorbar(
          aes(ymin=value, ymax=value+sd), width=.2,
          position=position_dodge(.9)
      )
  
  Dropout is very usual in single-cell data. If you really want to show the expression with barplot, I would suggest removing the zero values or using denoised data for better visualisation.
  
original_text: 15922: <p>I am looking for a way to present some single-cell RNA sequencing data on expression of a certain gene. My dataset has 2 variables, cell type and condition. I'm looking to create a grouped aligned scatter plot bar graph of the expression of the gene, where the y-axis is expression levels, while X axis is the different cell types, with each cell type having 2 bars (1 for healthy, 1 for diseased). My dataset has 3 healthy and 3 diseased samples, but all of the data is integrated into a Seurat object. To first create an aligned scatter plot bar graph, what I did was generate a DotPlot for the expression of gene X in each sample, split by cell-type. Then I realized that DotPlot() prints out a data table with values including avg.exp, pct.exp and avg.scaled.exp. I used the avg.exp metric to plot the data, but I was posting this question to see if there are other ways I can access and present expression data from a Seurat object. Is the way I've presented accurate? I've posted a sample bar graph of what I'm looking for, and the main question is how I can gather the expression levels across cell types AND diseased or healthy condition.</p>
  <p>Thanks!
  <a href="https://i.stack.imgur.com/xqVRw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xqVRw.png" alt="Example Bar Graph" /></a></p>
   8550: <p>In single-cell data a bargraph with error bar is not usually shown since the gene expression does not have a normal distribution due to drop-outs. A violin-plot is commonly used. In your case, first set the active.ident to cell types</p>
  <pre><code>seuratObj &lt;- SetIdent(seuratObj , value = &quot;Cell.Types&quot;)
  </code></pre>
  <p>Then call the violin plot</p>
  <pre><code>VlnPlot(seuratObj , features = &quot;geneX&quot;, split.by = &quot;condition&quot;)
  </code></pre>
  <p>If you still specifically need bargraph, you can get the output of the violin plot as a dataframe and then draw the barplot.</p>
   15952: <p>Following the answer of @<em>Ajay</em>.</p>
  <p>You can add <code>+ geom_boxplot()</code> after the command to turn the violin plot to a box plot.</p>
  <p>As for the barplot, you can do it with these:</p>
  <pre><code># the object is your seurat object
  data.df &lt;- object@meta.data[, c(&quot;celltypes&quot;, &quot;condition&quot;)]
  data.df[&quot;value&quot;] &lt;- object$RNA@data[&quot;geneX&quot;, ]
  data.df &lt;- data.df %&gt;% mutate(group = paste(celltypes, condition, sep=&quot;:&quot;))
  
  # remove cells that do not express the gene
  data.df &lt;- data.df %&gt;% filter(value &gt; 0)
  
  data.df.2 &lt;- data.df %&gt;% group_by(group) %&gt;% summarise(sd=sd(value),value=mean(value))
  X &lt;- str_split(data.df.2<span class="math-container">$'group', ":", 2, simplify=TRUE)
  data.df.2$</span>'celltypes' &lt;- X[, 1]
  data.df.2$'condition' &lt;- X[, 2]
  
  ggplot(data.df.2, aes(fill=condition, y=value, x=celltypes)) + 
      geom_bar(color=&quot;black&quot;, position=&quot;dodge&quot;, stat=&quot;identity&quot;) +
      geom_errorbar(
          aes(ymin=value, ymax=value+sd), width=.2,
          position=position_dodge(.9)
      )
  </code></pre>
  <p>Dropout is very usual in single-cell data. If you really want to show the expression with barplot, I would suggest removing the zero values or using denoised data for better visualisation.</p>
  