【发布时间】:2014-10-01 17:08:31
【问题描述】:
我一直在与这个问题作斗争一段时间。我想使用 grid.arrange 减少 ggplot 和表格之间的空间。我查看了各种threads,在网上搜索,尝试了各种方法,但如果它们在一列中,我无法减少两个图之间的空间。 (是的,它必须是饼图,但表格可以提供更好的信息)
这是我的示例代码。
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 是的,ggplot 中的饼图很奇怪。我将检查高度选项。谢谢