2017-08-27 113 views
1

我试图创建一个标题为我的文字是大胆的图形页面。我使用的代码如下,我设置fontface =大胆,但是这似乎并不奏效。 是否有别的地方我需要设置呢?TextGrob的R - fontface =大胆,但没有大胆

t = textGrob(expression(underline("My Sample Header")),gp=gpar(fontfamily="serif",fontsize=16, fontface="bold",lineheight=1),vjust=.3,hjust=2.15) 
+2

你需要'表达式(粗体(下划线( “我的样本头”)))' –

回答

1

既然没有人回答了这一点,你可以这样做两种方式:

方法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))