既然沒有人回答了這一點,你可以這樣做兩種方式:
方法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))
你需要'表達式(粗體(下劃線( 「我的樣本頭」)))' –