既然没有人回答了这一点,你可以这样做两种方式:
方法1:使用表达式,但做expression(bold(underline(...)))
,如:
t = textGrob(expression(bold(underline("My Sample Header"))),gp=gpar(fontfamily="serif",fontsize=16, fontface="bold",lineheight=1),vjust=.3,hjust=1)
grid.draw(t)
方法2:写将textGrob
与一行(可能是更好的选项)相结合的包装功能:
underlineText <- function(text, gpar, vjust, hjust){
txt <- textGrob(text, gp=gpar, vjust = vjust, hjust = hjust)
undLine <- segmentsGrob(x0 = txt$x - grobWidth(txt), y0 = txt$y - unit(0.55, "grobheight", txt), x1 = txt$x, y1 = txt$y - unit(0.55, "grobheight", txt))
gt <- grobTree(txt, undLine)
}
grid.draw(underlineText("My Sample Header", gpar(fontfamily="serif",fontsize=16, fontface="bold",lineheight=1), vjust = 0.3, hjust = 1))
你需要'表达式(粗体(下划线( “我的样本头”)))' –