我一直在与这个问题争斗一段时间了。我想使用grid.arrange减少ggplot和表格之间的空间。我看着各种各样的threads,在网上搜索,尝试了各种各样的东西,但如果它们在一列中,我不能缩小两个地块之间的空间。 (是的,它需要是饼图,尽管表格提供了更好的信息)减少grid.arrange中两个地块之间的空间
这是我的示例代码。
fruits <- data.frame(Type = c("Oranges", "Apples"), Quantity = c(200, 500))
g <- ggplot(fruits, aes(x = factor(1), y = Quantity, fill = Type)) + geom_bar(position = "fill", stat = "identity", width = 1) + coord_polar(theta = "y")
g <- g + labs(x = NULL, y = NULL) + theme(axis.ticks = element_blank(), axis.text = element_blank(), panel.background = element_rect(fill = "white", colour = "white"), legend.position = "none")
g <- g + theme(plot.margin = unit(c(0,0,0,0), "lines"))
gtablegrob <- tableGrob(fruits, show.rownames = FALSE, gpar.coretext = gpar(fontsize = 10), par.coltext = gpar(fontsize = 10), gpar.rowtext = gpar(fontsize = 10), gpar.corefill = gpar(fill = "white", col = "white"))
grid.arrange(g, gtablegrob, nrow = 2)
其他类似的线程提供宽度的解决方案,但我找不到高度的文档。
'heights = c(4,1)'; ggplot2中的饼图很奇怪,似乎很难完全删除空间 – baptiste 2014-10-01 17:27:30
@baptiste是的,饼图在ggplot中是完全不可思议的。我会检查高度选项。谢谢 – karlos 2014-10-01 21:02:22