utextChildren <- function(label, x, y, just, name) { t <- textGrob(label, x, y, just=just, name=paste0(name, ".label")) corners <- textCorners(t) s <- segmentsGrob(corners$xl, corners$yb - unit(.2, "lines"), corners$xr, corners$yb - unit(.2, "lines"), name=paste0(name, ".underline")) gList(t, s) } utextStatic <- function(label, x=.5, y=.5, default.units="npc", just="centre", name="utext") { if (!is.unit(x)) x <- unit(x, default.units) if (!is.unit(y)) y <- unit(y, default.units) kids <- utextChildren(label, x, y, just, name) gTree(label=label, x=x, y=y, just=just, children=kids, cl="utextStatic", name=name) } ug <- utextStatic("underlined text") grid.draw(ug) grid.newpage() grid.rect(gp=gpar(col="grey")) ug <- utextStatic("underlined text") grid.draw(ug)