I am attempting to draw words on horizontal bars in a bar plot so the top and bottom of the words just brush the top and bottom sides of the bar plot. This boils down to being able to calculate a tight bounding box for text including the descenders and ascenders. For example, consider
plot( 1:10, 1:10 )
text( 3, 7, "sample", adj=c(0,0), cex=3 )
sh = strheight( "sample" )
abline( h=c( 7, 7+3*sh ) )
Note the top line hits the "l" just right. The "p" descends through the bottom line.
How can I calculate a proper bottom line here?
Alternatively, how can I plot text so it fills a given height, such as the following:
plot( 1:10, 1:10 )
ht = 2
abline( h=c( 7, 7+ht ) )
sh = strheight( "sample" )
sh
text( 3, 7, "sample", adj=c(0,0), cex=2/sh )
This question is related to finding bounding boxes (see related stack overflow question). Due to the descender issue, it does not seem to be the same the the solutions there do not seem to fully work.