I created this plot from the following data
> head(data.frame(ali))
qname qlen qstart qend strand tname tlen tstart tend nmatch alen mapq
1 1 2535400 16999 2505278 + chromosome_1 2608419 3145 2582047 2228136 2615956 60
2 1 2535400 2514043 2521414 + chromosome_23 557589 348928 356301 6955 7373 23
3 1 2535400 2514040 2521414 + chromosome_13 959323 306762 314131 6489 7374 0
4 1 2535400 350 6278 - chromosome_4 1629129 1048335 1054264 5373 5929 4
5 1 2535400 350 6278 + chromosome_11 1087446 1070616 1076544 5306 5928 0
6 1 2535400 350 6278 + chromosome_4 1629129 886366 892296 5150 5930 0
> str(data.frame(ali))
'data.frame': 1156 obs. of 12 variables:
$ qname : chr "1" "1" "1" "1" ...
$ qlen : num 2535400 2535400 2535400 2535400 2535400 ...
$ qstart: num 16999 2514043 2514040 350 350 ...
$ qend : num 2505278 2521414 2521414 6278 6278 ...
$ strand: chr "+" "+" "+" "-" ...
$ tname : chr "chromosome_1" "chromosome_23" "chromosome_13" "chromosome_4" ...
$ tlen : num 2608419 557589 959323 1629129 1087446 ...
$ tstart: num 3145 348928 306762 1048335 1070616 ...
$ tend : num 2582047 356301 314131 1054264 1076544 ...
$ nmatch: num 2228136 6955 6489 5373 5306 ...
$ alen : num 2615956 7373 7374 5929 5928 ...
$ mapq : num 60 23 0 4 0 0 22 0 15 0 ...
What I would like is to order the 25 chromosomes on the left numerically, starting with chromosome 1 on the top and chromosome 25 on the bottom
For the legend I wanted to order the first 33 numbers numerically, once again starting with 1 and descending to 33, and then all the stuff afterwards (ie. bd_##x## and chloroplast) doesn't matter how it is ordered. It can stay the same or get switched around as long as it starts after 33.
Does anyone have any idea how to do this in ggplot?
This is all the code I used to make the plot
# import libraries
library(pafr, quietly = TRUE)
library(RColorBrewer)
# import alignment
alignment = system.file("extdata", "oldToNewMap.paf", package="pafr")
ali <- read_paf(alignment)
# create color palette
nb.cols <- 89
mycolors <- colorRampPalette(brewer.pal(8, "Set2"))(nb.cols)
# plot
plot_coverage(ali, fill='qname') +
scale_fill_manual(values = mycolors)