Home > Mobile >  Display rotated numbers at the bottom of a bar plot, sticked to the floor
Display rotated numbers at the bottom of a bar plot, sticked to the floor

Time:12-22

I want to write some numbers in a bar plot like in this image: enter image description here

I would like to have the numbers stickt to the floor, so that each number in each bar starts at the bottom. Right now. each number starts at a different y-value, depending on its length. I tried it with adj and pos, but it did not work. That mostly decentered my numbers in addition. Here is a reproducable example:

data <- data.frame(x = as.factor(c(1:12)), y = rep(30,12), z = c(100,20,30,40,50,60,70,80,100,100,1000,10000)) 
my_bar <- barplot(data$y,ylim = c(0,30))
text(my_bar, 3 , paste(data$z) ,cex=1, srt = 90, font = 2, adj = c(0.5, 0.5))

I would be very grateful if someone had an idea

CodePudding user response:

It is doing what you are telling it to do. Change to adj=c(0, 0.5) for left-justification, and 3 to 1 (or 0 or something close) for pushing closer to the bottom margin.

data <- data.frame(x = as.factor(c(1:12)), y = rep(30,12), z = c(100,20,30,40,50,60,70,80,100,100,1000,10000)) 
my_bar <- barplot(data$y,ylim = c(0,30))
text(my_bar, 1 , paste(data$z) ,cex=1, srt = 90, font = 2, adj = c(0, 0.5))
# changes:  ^^^                                                   ^^^

enter image description here

  • Related