This is some notes on using the facet_grid function in ggplot2.
My data looks like this:
chr | window | function id | name | genes | p-val | start | end | chrlen | source | label |
---|---|---|---|---|---|---|---|---|---|---|
chr1 | 206 | 164a8da3b80 | Dynein | 7 | 0 | 77424754 | 81043029 | 88881357 | gfam | |
chr1 | 206 | PF01221 | Dynein_light | 14 | 0 | 77424754 | 81056868 | 88881357 | pfam | yes |
chr2 | 5 | PF05019 | Coq4 | 3 | 0 | 2611802 | 3155461 | 48130368 | pfam | |
chr2 | 5 | f40b1ae1da7e4 | CMTR1 | 8 | 0 | 2687527 | 4607079 | 48130368 | gfam | yes |
Basically it’s a collection of enriched functional clusters (gene family and pfam) on each chromosome. I would like to plot those gene numbers as bar (at least 4 genes) and label those marked “yes” with the function names. From ggplot2 facet_grid() function seems suitable in categorising the data into each chromosome. And I used geom_bar and geom_label to plot and label clusters. For the chromosome I used geom_rect to draw a rectangle (not ideal though).
Here is the script with notes to myself:
|
|
There is still one problem with the plot: some labels are overlapped with bars. Not sure which function to avoid this?