2017-05-30 7 views
0

AkselAから供給される溶液を使用する。 in How to formatting numbers by column in a table (tableGrob) 私はテーブルのフォントサイズを増やそうとしました。表のサイズと色数によるテキストの書式設定方法(tableGrob)

g$grobs[ind][[1]][["gp"]] <- gpar(fontsize=15, fontface="bold"). 

をしかし、私は、コードを変更しようとすると、私はエラーを得続ける:このウェブサイトから

、私は解決策を使用して、「テーブル内の既存のgrobsへのアクセス」であると信じています。

+0

あなたはどのようなエラーを受けていますか?また、 'ind'はどのような価値を表していますか? –

+0

大変申し訳ございません。私はウェブサイトのリンクがアップロードされなかったことに気付かなかった。 'ind'はここの例です:https://github.com/baptiste/gridextra/wiki/tableGrob私はその例を統合してテキストサイズを調整しようとしていました。 – user2946746

+0

このコードは私のためのエラーを生成しません。あなたが受け取っているエラーについてより具体的に言えますか? –

答えて

0

私はこの質問に対する答えを見つけ出すことができました。私は'42 - 'で提供されたソリューションを使用することができましたText alignment and font size in gtable

コードフラグメントを変更して、参照されている質問の末尾に追加します。

g$grobs[] <- 
lapply(g$grobs[], 
function(x) modifyList(x, list(gp=list(fontsize=25, cex=1)))) 

完全なコードは次のようになります。

library(gtable) 
library(grid) 
library(gridExtra) 
library(zoo) 

data(iris) 
iris <- iris[1:4, 1:3] 
rownames(iris) <- as.character(as.yearmon(
    seq(as.Date("2000/1/1"), as.Date("2000/4/1"), by = "month"))) 
iris$RankColumn <- 1:nrow(iris) 

# a simple function to scale each row or column to the range [0, 1] 
# will convert characters to numerics if in a sensible format 
norm <- function(x, mar=2) { 
    rnames <- rownames(x) 
    x <- apply(x, 2, as.numeric) 
    x <- apply(x, mar, function(y){(y-min(y))/(max(y)-min(y))}) 
    rownames(x) <- rnames 
    x 
} 

# function to pad with zero 
# by default does not pad integers 
zeropad <- function(x, nz=1, exc.int=TRUE) { 
    if (is.integer(x) & exc.int) { 
     x 
    } else { 
     sprintf(paste0("%.", nz, "f"), x) 
    } 
} 

bluecol <- colorRamp(c("#3366EE", "#AABBFF", "#DDDDFF"))(norm(iris)) 
bluecol <- rgb(bluecol[, 1], bluecol[, 2], bluecol[, 3], max=255) 

tt <- ttheme_default(core=list(bg_params=list(fill=bluecol))) 

# convert floats to zero-padded characters 
iris[1:ncol(iris)] <- sapply(iris, zeropad, 2) 

g <- tableGrob(iris, theme=tt) 
g <- gtable_add_grob(g, 
        grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)), 
        t = 2, b = nrow(g), l = 1, r = ncol(g)) 
g <- gtable_add_grob(g, 
        grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)), 
        t = 1, l = 1, r = ncol(g)) 


g$grobs[] <- 
    lapply(g$grobs[], 
    function(x) modifyList(x, list(gp=list(fontsize=25, cex=1)))) 


plot.new() 
grid.draw(g) 
関連する問題