This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I use ggplot2 to indicate chromosomes on a continuous axis?

The plot below is what I want to plot: enter image description here

Basically, the plot contains the log(Pi1/Pi2) values for specific positions on each chromosome. (It looks like a Manhattan plot but with negative values)

I have the following data frame

Chromosome  Position  Log_Pi

1              102331    -0.552
2              220231    2.32
5              233433   -2.200
.
.
.
7             522631   -1.023
7             322512    1.2231
10            233356      -0.223
12            5666932     0.2235

I have tried:

ggplot(data = Pi_PLOT, aes(x = Chromosome, y = log_pi)) + geom_point(data = Pi_PLOT, aes(x = Position, y = log_pi, fill = Chromosome)) + labs(x = "Chromosome", y = "log_pi")
ggplot2

3 answers

I figured out by using the CMplot package in R.

Thanks

Gene names are missing from your dataframe. Add an extra column which has gene names to those of interest. After this, you can do something like:

p = ggplot(data = Pi_PLOT, aes(x = Chromosome, y = log_pi)) + 
      geom_point(data = Pi_PLOT, aes(x = Position, y = log_pi, fill = Chromosome)) + 
      labs(x = "Chromosome", y = "log_pi") +

p + geom_text(aes(label=gene_name))

Where gene_name is the name of the column I mentioned above.

I don't have the ready codes for this, but when we have that many values on xaxis precise values do not matter much.

So we can sort the data on chrom and position, then give x axis 1 to nrow values, then for each chrom find the middle. For example, if chr2 is from 2000 to 3000, then we put the label "chr2" at round(2000 + (3000 - 2000)/2), do this for each chrom. Then plot with label.

Log in to answer this question.