<p>I have 209 cells. I want to show the expression of two genes by ordering my cells. Imagine something like a plot on which y axis shows the read counts range from 0 to 10000 and x axis shows the number of cells (there is a link of an example picture that I wish to produce the same). So that two colours bars each colour for a gene.</p>

<p>I have used this code but result is not as I want at all</p>

<pre><code># Library
 library(tidyverse)

 # Create data
 value1=abs(rnorm(26))*2
 data=data.frame(x=LETTERS[1:26], value1=value1, value2=value1+1+rnorm(26, sd=1) )

 # Reorder data using average?
 data = data %&gt;% rowwise() %&gt;% mutate( mymean = mean(c(value1,value2) )) %&gt;% arrange(mymean) %&gt;% mutate(x=factor(x, x))

 # plot
 ggplot(data) +
   geom_segment( aes(x=x, xend=x, y=value1, yend=value2), color="grey") +
   geom_point( aes(x=x, y=value1), color=rgb(0.2,0.7,0.1,0.5), size=3 ) +
   geom_point( aes(x=x, y=value2), color=rgb(0.7,0.2,0.1,0.5), size=3 ) +
   coord_flip() 
</code></pre>

<p>This is link of my data and my result picture</p>

<p><a href="https://i.sstatic.net/BIcaY.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BIcaY.jpg" alt="enter image description here"></a></p>

<p>And to some <a href="https://drive.google.com/file/d/1PPFjULGV4CfJvRbubtn6kb5f5qYlpJ5W/view?usp=sharing" rel="nofollow noreferrer">data</a></p>

CC BY-SA 4.0
2018-06-23T14:29:12.850Z
Could you add an example of what a lollipop is? (a link or something like that?) And what have you tried to make that plot (To avoid suggesting to do the same and help you more specifically)
llrs
CC BY-SA 4.0
2018-06-23T18:11:33.090Z
Thank you, I edited my post. Actually lollipop plot itself dose not matter that can be replaced by any other plots. The problem is that I could not figure out how to plot the same as picture and what I have tried up to now did not answer my question :(
Zizogolu
CC BY-SA 4.0
2018-06-25T08:46:33.903Z
could you further explain how this picture doesn't help you ?. I am still trying to figure out how I can help
llrs
CC BY-SA 4.0
2018-06-25T10:51:10.217Z
Thank you, because on gene seems to be compressed at the end  and does not allow to another gene to be cleared. I don't know how to have another gene on another axis or showing y axis in log10
Zizogolu
CC BY-SA 4.0
2018-06-25T11:11:43.837Z
So, your problem is how to convert an axis to log10? This is answered in [Stack Overflow](https://stackoverflow.com/questions/4699493/transform-only-one-axis-to-log10-scale-with-ggplot2) and other venues. In ggplot2 you can't have two axis by design: it is against the grammar of graphics.
llrs
<r><scrnaseq><ggplot2>
Ordering the cells by the expression of specific genes
# Ordering the cells by the expression of specific genes

(Asked by: username_0 on 2018-06-23)

I have 209 cells. I want to show the expression of two genes by ordering my cells. Imagine something like a plot on which y axis shows the read counts range from 0 to 10000 and x axis shows the number of cells (there is a link of an example picture that I wish to produce the same). So that two colours bars each colour for a gene.
I have used this code but result is not as I want at all
# Library
 library(tidyverse)

 # Create data
 value1=abs(rnorm(26))*2
 data=data.frame(x=LETTERS[1:26], value1=value1, value2=value1+1+rnorm(26, sd=1) )

 # Reorder data using average?
 data = data %>% rowwise() %>% mutate( mymean = mean(c(value1,value2) )) %>% arrange(mymean) %>% mutate(x=factor(x, x))

 # plot
 ggplot(data) +
   geom_segment( aes(x=x, xend=x, y=value1, yend=value2), color="grey") +
   geom_point( aes(x=x, y=value1), color=rgb(0.2,0.7,0.1,0.5), size=3 ) +
   geom_point( aes(x=x, y=value2), color=rgb(0.7,0.2,0.1,0.5), size=3 ) +
   coord_flip() 

This is link of my data and my result picture

And to some data

**Tags:** r, scrnaseq, ggplot2
> **Comments:**
> **username_1**: Could you add an example of what a lollipop is? (a link or something like that?) And what have you tried to make that plot (To avoid suggesting to do the same and help you more specifically)  
> **username_0**: Thank you, I edited my post. Actually lollipop plot itself dose not matter that can be replaced by any other plots. The problem is that I could not figure out how to plot the same as picture and what I have tried up to now did not answer my question :(  
> **username_1**: could you further explain how this picture doesn't help you ?. I am still trying to figure out how I can help  
> **username_0**: Thank you, because on gene seems to be compressed at the end  and does not allow to another gene to be cleared. I don't know how to have another gene on another axis or showing y axis in log10  
> **username_1**: So, your problem is how to convert an axis to log10? This is answered in [Stack Overflow](https://stackoverflow.com/questions/4699493/transform-only-one-axis-to-log10-scale-with-ggplot2) and other venues. In ggplot2 you can't have two axis by design: it is against the grammar of graphics.  

---

## 0 answers

