我试图将一张表与一些图表一起绘制为 par(mfrow = c(2,3)) 的一部分。我有5个ggplot图表,我希望这些多个图表的第6部分用表格填充。然而,该表超出了它的界限。见下图:
这是3个表格中的一个的数据:
cov_table_1<-
structure(list(Year = structure(1:11, .Label = c("1970", "1971",
"1972", "1973", "1974", "1975", "1977", "1979", "1980", "1981",
"1982", "1983", "1984", "1985", "1986", "1987", "1988", "1990",
"1991", "1992", "2000", "2001", "2003", "2004", "2007", "2008",
"2009", "2010", "2011", "2012", "2013", "2014"), class = "factor"),
`Percentage
of missing data` = structure(c(4L, 2L, 4L, 6L,
1L, 12L, 5L, 21L, 21L, 11L, 10L), .Label = c("0%", "1%",
"100%", "17%", "24%", "31%", "35%", "5%", "58%", "59%", "60%",
"70%", "71%", "72%", "8%", "86%", "90%", "92%", "95%", "98%",
"99%"), class = "factor")), .Names = c("Year", "Percentage \nof missing data"
), row.names = c(NA, 11L), class = "data.frame")
这是我尝试绘制5个图表和1个表格的方式:
par(mfrow=c(2,3))
require(gridExtra)
library(RGraphics)
require(caroline)
require(ggplot2)
enter code here
h1<-ggplot() # graph 1
h2<-ggplot() # graph 2
h3<-ggplot() # graph 3
h4<-ggplot() # graph 4
h5<-ggplot() # graph 5
h6<-
# First I create an empty graph with absolutely nothing :
qplot(1:10, 1:10, geom = "blank",ylim=c(1,10), main=("\n")) +
theme_void() +
# Then I add my table :
annotation_custom(grob = tableGrob(cov_table_1, rows=NULL), xmin=0, xmax=4,ymin=1, ymax=10)+
annotation_custom(grob = tableGrob(cov_table_2, rows=NULL), xmin=4, xmax=6,ymin=1, ymax=10)+
annotation_custom(grob = tableGrob(cov_table_3, rows=NULL), xmin=6, xmax=10,ymin=1)+
theme(plot.margin = unit(c(1,1,1,1), "cm"))
正如您所看到的,我尝试通过添加标题来移动表格: main(&#34; \ n&#34;) 并使用 情节余量 或 ymin / ymax 也没有&#39;做的伎俩。 有没有人知道如何处理这个?