Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20100818/5f203714/attachment.pl>
On 08/18/2010 08:40 PM, David Hajage wrote:> Hello, > > I am using mtext to write some text below a graph: > > plot(1) > mtext("foo", side = 1, line = 2, at = seq(0.6, 1.6, 0.2)) > > I would like to draw something near the "foo" texts, for example a segment. > For this, I need to know the coordinates of the text ploted by mtext > function. > > I spent a few hours to try different combination, using the option xpd > TRUE and trying to convert between graphics coordinate system using > grconvertX and grconvertY... But I can't make it. > > Is there a way to know the coordinates of the text produce by mtext, > particularly vertical coordinates? For example, how can you draw some > segments to underline each foo in my example? >Hi David, You can get the "X" coordinates of the beginning and end of the text by using the strwidth function: # this is inefficient, but easy to follow begintext<-at-strwidth("foo")*par("adj") endtext<-at+strwidth("foo")*(1-par("adj")) the strheight function can be used to get the "Y" coordinates: bottomtext<-par("usr")[1]-(line+0.5)*strheight("Ug") You will probably have to fiddle with the constant (0.5) to get the line in the correct place on a particular device, then: par(xpd=TRUE) segments(begintext,bottomtext,endtext,bottomtext) par(xpd=FALSE) Jim
On Aug 18, 2010, at 6:40 AM, David Hajage wrote:> Hello, > > I am using mtext to write some text below a graph: > > plot(1) > mtext("foo", side = 1, line = 2, at = seq(0.6, 1.6, 0.2)) > > I would like to draw something near the "foo" texts, for example a > segment. > For this, I need to know the coordinates of the text ploted by mtext > function. > > I spent a few hours to try different combination, using the option > xpd > TRUE and trying to convert between graphics coordinate system using > grconvertX and grconvertY... But I can't make it. > > Is there a way to know the coordinates of the text produce by mtext, > particularly vertical coordinates? For example, how can you draw some > segments to underline each foo in my example?> plot(1) > mtext(expression(underline(foo)), side = 1, line = 2, at = seq(0.6, 1.6, 0.2))> > Thank you very much for any help. > > david > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT