R格标题字体大小 [英] R lattice title font size
问题描述
我需要图表上的标题如下所示
I need my title on the graph to look like the following
Main
Submain
其中main的字体大小与submain的字体大小不同,现在我将其作为main ="Main \ n submain",但是如何指定不同的大小.如果没有,我该如何添加另一个标题
where main is of a different font size than submain, right now I have it as main="Main \n submain" but how do I specify different sizes. If not, how do I add another title
推荐答案
这两个任务都不是非常容易的.但这并不意味着不可能.除了接受main=
参数的字符值外,它还可以接受任意的grid
对象(或grob
).莱迪思建立在grid
图形库上,因此您可以在绘制之前自定义许多内容.这是一种使用助手功能创建具有两行文本的grid
对象的解决方案.
Neither of those tasks are super easy with lattice; but that doesn't mean it's impossible. In addition to accepting character values for the main=
parameter, it can also accept an arbitrary grid
object (or grob
). Lattice is build on the grid
graphics library so you can customize many things before plotting. Here's one solution that uses a helper function to create grid
object with two rows of text.
library(lattice)
library(grid)
doubleTitle <- function(a,b) {
gTree(children=gList(
textGrob(a, gp=gpar(fontsize=15, fontface=2), y=0,
vp=viewport(layout.pos.row=1, layout.pos.col=1)),
textGrob(b, gp=gpar(fontsize=13, fontface=3), y=0,
vp=viewport(layout.pos.row=2, layout.pos.col=1))
), vp=viewport(layout=grid.layout(nrow=2, ncol=1)), cl="doubletitle")
}
heightDetails.doubletitle <- function(x, recording=T) {
Reduce(`+`, lapply(x$children, grid:::heightDetails.text)) * 2
}
我们可以将其与
xyplot(1:10~1:10, main=doubleTitle("Main","Submain"))
您可以清楚地看到fontsize=
选项.对于fontface=
,1为正常,2为粗体,3为斜体,4为粗体+斜体.要更改行之间的间距,请在heightDetails.doubletitle
函数中调整2
的值.
You can clearly see the fontsize=
options. For fontface=
, 1 is normal, 2 is bold, 3 is italic, and 4 is bold+italic. To change the spacing between rows, adjust the value of 2
in the heightDetails.doubletitle
function.
这篇关于R格标题字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!