Colouring cells by ggplot2
1
1
Entering edit mode
6.2 years ago
Za ▴ 140

In this graph 81 cells have being ordered by pseudo time. For example cell s0.76 has been placed at the start of pseudo time and cell s0.11 placed at the end of pseudo time.

enter image description here

This is the expression profile of this gene on this pseudo time

> Data

s0.76     s0.52     s0.72     s0.36     s0.18     s0.60     s0.54     s0.65     s0.56      s0.4     s0.14     s0.67      s0.1     s0.22     s0.28     s0.80     s0.16     s0.32 
 6354.316  2376.278  8037.063  4879.946  4989.872  5382.370 13239.227 12085.752  5510.481  9311.501  5303.664 13480.634  9085.402  9585.708 12678.642  8595.338 13901.138  9809.339 
     s0.8     s0.55     s0.71     s0.41     s0.40     s0.48     s0.68     s0.81     s0.29     s0.78     s0.34     s0.42     s0.13      s0.9      s0.7     s0.24     s0.62     s0.35 
12554.518 11001.622  6676.949  9266.956  5303.998 13405.392  8327.440  6903.236  9319.111  4427.627 11029.422  5370.687  4854.454 13199.522  5125.644 11687.103  7546.622  8656.206 
    s0.23     s0.21     s0.37     s0.25     s0.79     s0.64     s0.44     s0.15     s0.43     s0.63     s0.10      s0.6     s0.19     s0.31     s0.38     s0.39     s0.73     s0.59 
 4578.953 15771.795  3217.201  6362.859 11523.728  5977.613  4805.703  5373.737  2393.996  9104.929  3532.215  7974.742  4949.271  3285.566 10896.503  3746.348  4296.337  6510.001 
     s0.2     s0.12     s0.61     s0.66     s0.51     s0.58     s0.50     s0.27     s0.77     s0.69     s0.33     s0.17     s0.74     s0.26     s0.57     s0.49     s0.70     s0.53 
 3728.896  8761.615  3896.014  2618.151  4106.299 11898.634  2978.410  3129.880  5571.995  4314.655  3867.158  2209.066  1723.784  2741.320  4570.466  5506.473  3120.334  7284.682 
    s0.30     s0.45      s0.5     s0.47     s0.46     s0.75     s0.20      s0.3     s0.11 
 9454.997  7446.095  4765.971  7861.282 10393.357  4809.735 12421.501 12615.785 22238.399

Now, my question is, how I could color the plot by knowing a set of cells are in G2 and another set are in S/M phase of cell cycle like this picture?

enter image description here

These cells are at G2

[1] "s0.1"  "s0.2"  "s0.3"  "s0.6"  "s0.7"  "s0.8"  "s0.9"  "s0.10" "s0.12" "s0.13" "s0.14" "s0.15" "s0.16" "s0.19" "s0.21" "s0.22" "s0.23" "s0.24" "s0.25" "s0.28" "s0.29" "s0.31"
[23] "s0.32" "s0.34" "s0.35" "s0.37" "s0.38" "s0.39" "s0.42" "s0.43" "s0.44" "s0.48" "s0.50" "s0.51" "s0.54" "s0.55" "s0.56" "s0.59" "s0.60" "s0.61" "s0.62" "s0.63" "s0.64" "s0.65"
[45] "s0.66" "s0.67" "s0.68" "s0.70" "s0.71" "s0.73" "s0.78" "s0.79" "s0.80" "s0.81"

these cells are in M/S

 [1] "s0.4"  "s0.5"  "s0.11" "s0.17" "s0.18" "s0.20" "s0.26" "s0.27" "s0.30" "s0.33" "s0.36" "s0.40" "s0.41" "s0.45" "s0.46" "s0.47" "s0.49" "s0.52" "s0.53" "s0.57" "s0.58" "s0.69"
[23] "s0.72" "s0.74" "s0.75" "s0.76" "s0.77"

I tried to do that by this codes but the order of cells is not based on the pseudo time

> head(data)
         value  cell capture
1  30.59486 s0.76      G2
2  78.12876 s0.52      G2
3  63.36236 s0.72      G2
4  54.48303 s0.36     m/s
5 196.49463 s0.18     m/s
6  59.76789 s0.60      G2
>

enter image description here

> p=ggplot(data, aes(x=cell, y=value, color=capture))
> p+geom_point(alpha=.3)
ggplot2 r • 1.3k views
ADD COMMENT
3
Entering edit mode
6.2 years ago
Za ▴ 140
p+geom_point(alpha=.3)+scale_x_discrete(limits=as.factor(data$cell))
ADD COMMENT
1
Entering edit mode

Just a few observations that I wish to share with you:

  • Your question was extremely specific and generic at the same time. You could have searched Stack Overflow for color scatter plot by attribute and you'd have gotten the answer with a tiny bit of digging. All of the context you provided in the post is of little value to users here, as the context is singular to your use case. You should work on providing a simple, reproducible example with dummy data, not the details of your actual context.

  • This leads to the second point. When your question and answer are within an hour of each other, you're using us as a shortcut and not really contributing to the knowledge content of the site. And this behavior was also seen in your previous account. I strongly recommend you try harder before you post here, and when you do create a post, have the post be reproducible and valuable as a knowledge item.

Thank you!

ADD REPLY
0
Entering edit mode

You definitely you alright. Honestly, biostars is always my bests way of documentation for solutions for similar questions in future because I would always refer to my posts in near future. But believe me I am posting my question firstly here as I don't have any hope that I would find the solution myself and most of time I have to find the solution in a defined short time frame. So I post my question here and I am going to find the solution myself. In 90% of my posts I can not find the solution myself and here biostars solve the problem. Only one point, I am not mis using this website at all, at least not intentionally.

ADD REPLY
0
Entering edit mode

You are off course welcome to ask your questions here. But as Ram said, this one wasn't too hard and could have been solved easily. It is no use to be stuck on a problem for days, but spending a few hours is not wrong. Quite the contrary: every next question you'll have to solve will be easier because you learned how to figure things out.

Can you edit your question and answer to make them a bit more generic, as Ram suggested? As such more users in the future will be helped by stumbling upon this question in their own journey.

ADD REPLY

Login before adding your answer.

Traffic: 1794 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6