文本对齐方式和gtable字体大小

文本对齐方式和gtable字体大小

本文介绍了文本对齐方式和gtable字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题涉及到的答案被巴蒂斯,你可以在这里找到:http://stackoverflow.com/a/18667413/2072440.

My question relates to the answer by Baptiste that you can find here: http://stackoverflow.com/a/18667413/2072440.

这code的确pretty的就是我想要做的事。我想提出两个修改。首先,我想对准在第一列到左边的文本。其次,我想改变文本的字体。

That code does pretty what I want it to do. I would like to make two modifications. First, I would like to align the text in the first column to the left. Second, I would like to change the font of the text.

我试图编辑描述填充的细胞的背景就行,但这似乎并没有影响到字体和箱子本身,而不是他们的文字,只影响的位置。

I have tried to edit the line that describes the fill for the cells' background but that does not seem to impact the font and it only impacts the position of the boxes itself rather than the text in them.

感谢你。

推荐答案

这将是有益的检讨如何网格系统在?grid.text 的作品,尤其是外观。网格系统保存其情节对象grobs(图形对象)。我发现了一个有点出乎我的意料了理由是倒退到什么,我希望(和它被引用到中心线,而不是一个单元的边缘)。如果你运行本code中的G -object从你列举你可能期待的文本向右移动,而它实际上移动到页面左

It would be useful to review how the grid system works, in particular look at ?grid.text. The grid system saves its plot object in 'grobs' (graphical-objects). I discovered a bit to my surprise that the "justification" is backwards to what I expected (and it is referenced to the centerline rather than the edges of a cell). If you run this code on the "g"-object from the page you cited you might be expecting the text to move to the right, while it actually moves to the left.

g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)] <-
      lapply(g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)],
             function(x) modifyList( x, list(just="right") ) )
grid.draw(g)

为了改变,你需要设置的X的说法GP节点到成为一个列表具有不同结构(不只是一个空表不同)的字体。见`gpar它接受这些参数:?

In order to change the font you would need to set gp node of the "x" argument to a be a list with a different structure (different than just an empty list). See `?gpar' for the arguments it accepts:

str(g$grobs[[6]])
List of 11
 $ label        : chr "5.1"
 $ x            :Class 'unit'  atomic [1:1] 0.5
  .. ..- attr(*, "unit")= chr "npc"
  .. ..- attr(*, "valid.unit")= int 0
 $ y            :Class 'unit'  atomic [1:1] 0.5
  .. ..- attr(*, "unit")= chr "npc"
  .. ..- attr(*, "valid.unit")= int 0
 $ just         : chr "centre"
 $ hjust        : chr "left"
 $ vjust        : NULL
 $ rot          : num 0
 $ check.overlap: logi FALSE
 $ name         : chr "GRID.text.1032"
 $ gp           : list()
  ..- attr(*, "class")= chr "gpar"
 $ vp           : NULL


g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)] <-
           lapply(g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)],
                function(x) modifyList( x, list(gp=list(cex=0.8) ) ) )
grid.newpage()
grid.draw(g)

或者使用字号的说法:

Or use the fontsize argument:

g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)] <-
      lapply(g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)],
          function(x) modifyList( x, list(gp=list(fontsize=14, cex=1) ) ) )
grid.newpage()
grid.draw(g)

要更改的理由的gtable对象可以调整的 $ X 的格罗内的元素:

To change the justification for the gtable object one can "adjust" the $x element within the grob:

g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)] <-
   lapply(g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)],
     function(z) modifyList( z, list(x=unit(0.1,"npc"), just="left") ) )
g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)] <-
   lapply(g$grobs[c(6:8, 10:12, 14:16, 18:20, 22:24)],
     function(x) modifyList( x, list(gp=list(fontsize=16, cex=1) ) ) )
grid.draw(g)

这篇关于文本对齐方式和gtable字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 03:48