# Ordering the cells by the expression of specific genes

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

• 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 Jun 23 '18 at 14:29
• 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 :( – Exhausted Jun 23 '18 at 18:11
• could you further explain how this picture doesn't help you ?. I am still trying to figure out how I can help – llrs Jun 25 '18 at 8:46
• 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 – Exhausted Jun 25 '18 at 10:51
• So, your problem is how to convert an axis to log10? This is answered in Stack Overflow and other venues. In ggplot2 you can't have two axis by design: it is against the grammar of graphics. – llrs Jun 25 '18 at 11:11