I want to put numbers above the chromosomes barplot.
The chromosome data is provided as integer, for example, y1.
> y1
[,1]
[1,] 33
[2,] 49
[3,] 18
[4,] 61
[5,] 124
[6,] 12
[7,] 89
[8,] 59
[9,] 31
[10,] 69
[11,] 20
[12,] 89
[13,] 118
[14,] 67
[15,] 45
[16,] 49
[17,] 80
[18,] 98
[19,] 66
[20,] 52
[21,] 79
[22,] 98
[23,] 188
Each number represent the number of data points in that chromosome, for ex, there are 33 datappint in chromosome one. This y1 is dynamically changing, so I use barplot, which generate a chromosome heatmap, the wider the heatmap of each chromosome, the more data/bigger number in that chromosome. Now I want to put the chromosome number from 1 to 23 above the chromosome to show which is which. I use the y1 value to represent the y coordinates, however, the plot just doesn’ look right. Can anyone help explain what is wriong with my code?
Here is my code
ycor <- c(0)
num <- length(y1)
for (i in 2:num){
a=sum(y1[1:i-1])
x = y1[i]*0.5
b = a
ycor <- append(ycor, b)
}
par(mar = c(3,3,0,0)) # bottom,left,top,right
barplot(y1, horiz = F,axes = FALSE, col = colors2, border = NA) # chromosome
text(1,ycor, labels = 23:1, pos = 3)
Here is the plot how it looks,
enter image description here
I want the number right above each bar representing the chromosome. Feels like the coordinate systeme just doesn’t the way I think.
By the way, i only want to plot with barplot() and it’s compatible functions. ggplot2 is not the same ecosystem.
Any hope would be greatly appreciated.
Best,
LC