使用gridExtra中的tableGrob在表格中包装文本

Gre*_*ell 2 r gridextra

我有一系列调查问题,并且正在报告学校,学校家庭和整个董事会的回复.有些问题很长 - 我想要做的是在列结束时自动换行.现在我必须手动添加换行符.这甚至可能吗?我正在使用R版本3.2.1和gridExtra_2.0.0.

一些代码:

library(gridExtra)
library(grid)
library(ggplot2)

key <- c("I feel close to other parents with children the same age", "I am comfortable asking for advice about parenting", "I take time out to take care of my own health and well?being")
SCH <- c(20,30,40)
FOS <- c(25,35,56)
BOARD <- c(32,44,58)

d <- data.frame(key, SCH, FOS, BOARD)

row.names(d) <- d[,1]
d[,1] <- NULL

g <- tableGrob(d)

g$widths <- unit (c(0.4, 0.1,0.1,0.1),"npc")
grid.newpage()
grid.draw(g)
Run Code Online (Sandbox Code Playgroud)

Ren*_*rop 7

你可以用这个来实现 strwrap

key <- c("I feel close to other parents with children the same age", "I am comfortable asking for advice about parenting", "I take time out to take care of my own health and well?being")

key_wraped <- strwrap(key, width = 30, simplify = FALSE) # modify 30 to your needs
key_new <- sapply(key_wraped, paste, collapse = "\n")

d <- data.frame(key_new, SCH, FOS, BOARD)
Run Code Online (Sandbox Code Playgroud)

对我来说,这导致: 在此输入图像描述