Увеличение размера таблицы и добавление строк между строками и столбцами (аналогично Excel) - PullRequest
1 голос
/ 20 октября 2019

В приведенном ниже выводе мы можем увеличить размер таблицы и добавить строки между

library(RGraphics)
library(grid)
library(gridExtra) 
Performance1 <- structure(list(Mills = c("Mill-A", "Mill-B", "Mill-C", "Mill-D", 
"Mill-E"), Performance = c(0.5, 0.4, 0.2, 0.9, 0.4)), row.names = c(NA, 
-5L), class = "data.frame")
dt <- mtcars[1:5, 1:6]
t1 <- tableGrob(dt,theme=ttheme_minimal(base_size = 15))
g1 <- ggplot(data = Performance1,aes(x=Mills,y=Performance))+geom_bar(stat = "identity")+geom_bar(stat = "identity",width=0.4)+theme(plot.margin = unit(c(2,2,4,4),"cm"))
grid.arrange(t1,g1, ncol=2, top="The iris data",heights=c(1.2,1.5))

1 Ответ

0 голосов
/ 20 октября 2019

Вы можете сделать что-то вроде этого. Возможно, вам придется использовать gtable.

library(RGraphics)
library(grid)
library(gridExtra) 
library(gtable)
Performance1 <- structure(list(Mills = c("Mill-A", "Mill-B", "Mill-C", "Mill-D", 
                                         "Mill-E"), Performance = c(0.5, 0.4, 0.2, 0.9, 0.4)), row.names = c(NA, 
                                                                                                             -5L), class = "data.frame")
dt <- mtcars[1:5, 1:6]
# -------------------------------------------------------------------------
# Everything above is your script except the addition of gtable
# -------------------------------------------------------------------------
# modify t1 to add padding between cells 
t1 <- tableGrob(dt,theme=ttheme_minimal(base_size = 15, padding = unit(c(6, 6), "mm")), rows = NULL)
# -------------------------------------------------------------------------
# Experiment with different values 
# -------------------------------------------------------------------------
g1 <- ggplot(data = Performance1,aes(x=Mills,y=Performance))+geom_bar(stat = "identity")+geom_bar(stat = "identity",width=0.4)+theme(plot.margin = unit(c(2,2,4,4),"cm"))
# -------------------------------------------------------------------------
# g1 is your script
# -------------------------------------------------------------------------
p <- gtable_add_grob(t1, 
                     grobs = rectGrob(gp=gpar(fill =NA, lwd=2)), t = 1, b = nrow(t1), l = 1, r = ncol(t1))
# do grid.draw(p) followed by dev.off() and tweak the table to your liking  

p1 <- gtable_add_grob(p,
                     grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)),
                     t = 1, l = 1, r = ncol(p))
# do grid.draw(p1) followed by dev.off() and tweak the table to your liking  

grid.arrange(p1,g1, ncol=2, top="The iris data",heights=c(5,5))

Вывод

test_out

Если не это, посмотрите на Отображение таблиц в виде графиков сетки вероятно, поможет вам получить то, что вы хотите.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...