0

I want to add multiple geom_texts to my diagram using a for loop. But the code I am using only displays the output for the last iteration.

Considering user input to the tool, there can be different number of rows in the forPlot.h tibble and the same goes for hl.hold tibble. Therefore, I suppose a for loop is best application here.

I also tried a while loop with the same outcome. My for loop is outlined below:

for (p in 1:(nrow(forPlot.h)-1)) {
  pinch <- pinch +
    geom_text(
      aes(
        x = (forPlot.h[[p,'q_cum']]+forPlot.h[[p+1,'q_cum']])/2,
        y = forPlot.h[[p,'ts_f']],
        label = paste0(hl.hold[[p,'s.nam']])
      ),
      vjust = -1.5
    )
}
Mark
  • 7,785
  • 2
  • 14
  • 34
  • 1
    Hi Ovais! Please provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Mark Jun 29 '23 at 03:58

0 Answers0