Add Chromosome Breaks and Labels to Continuous x-axis in R
0
0
Entering edit mode
2.2 years ago
selplat21 ▴ 20

I have a paf file that have imported that has the following structure:

Classes ‘pafr’ and 'data.frame':    44304 obs. of  18 variables:
 $ qname : chr  "Chr1" "Chr1" "Chr1" "Chr1" ...
 $ qlen  : num  196345723 196345723 196345723 196345723 196345723 ...
 $ qstart: num  136822117 180636036 161249961 149012134 155428335 ...
 $ qend  : num  148529244 193071845 177994375 155397308 161194689 ...
 $ strand: chr  "-" "+" "-" "+" ...
 $ tname : chr  "OU015528.1" "OU015528.1" "OU015528.1" "OU015528.1" ...
 $ tlen  : num  82614289 82614289 82614289 82614289 82614289 ...
 $ tstart: num  45642910 65383687 14852200 5070550 59356880 ...
 $ tend  : num  57423515 78622207 32888725 11853840 65371656 ...
 $ nmatch: num  990974 973135 1187463 552523 440276 ...
 $ alen  : num  12799627 14232743 19469502 7228820 6536219 ...
 $ mapq  : num  60 60 60 60 60 60 60 60 60 60 ...
 $ tp    : chr  "P" "P" "P" "P" ...
 $ cm    : num  92453 90044 110220 53963 40657 ...
 $ s1    : num  636113 512050 508620 338152 227618 ...
 $ s2    : num  1135 369 441 147 370 ...
 $ dv    : num  0.0156 0.0169 0.0176 0.0144 0.018 0.0205 0.015 0.0271 0.023 0.0198 ...
 $ rl    : num  1192370 1192370 1192370 1192370 1192370 ...

I've plotted using the following command, but I would like to add another label on the x-axis that would label/delimit chromosomes in addition to the current bp position.:

ggplot(data=bth.paf, aes(x=qstart, xend=qend, y=tstart, yend=tend)) + 
  geom_segment(color="blue") + 
  labs(x="Reference coordinate", y="Query coordinate") + 
  ylim(100000,1000000) +
  geom_rect(aes(xmin=0, xmax=200000000, ymin=782541, ymax=782654), colour=alpha("orange", 0.5), fill.alpha=0.5) + theme_bw()

enter image description here

R • 734 views
ADD COMMENT
1
Entering edit mode

Use facet_grid on chromosome column - qname.

ADD REPLY
0
Entering edit mode

This is definitely what I want, but I have about a hundred scaffolds. So I am trying to have it all in one row such that the visible sections are the larger chromosomes.

ADD REPLY
0
Entering edit mode

Please read the manuals: https://ggplot2.tidyverse.org/reference/facet_grid.html

We will need something like:

... + facet_grid(qname ~ ., scales = "free_x")
ADD REPLY

Login before adding your answer.

Traffic: 2420 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