首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >删除gridExtra::tableGrob中的行名

删除gridExtra::tableGrob中的行名
EN

Stack Overflow用户
提问于 2016-11-24 14:21:50
回答 1查看 7.4K关注 0票数 12

我想用ggplot绘制一个表,但是似乎无法成功地丢失row.names。

我试过:

代码语言:javascript
运行
复制
row.names(cov_table_a)<-NULL # outside the plot
row.names = FALSE            # inside the annotation_custom

这是我的数据:

代码语言:javascript
运行
复制
cov_table_a<-
structure(list(Year = structure(1:16, .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 \nof missing data` = structure(c(4L, 2L, 4L, 6L, 
1L, 12L, 5L, 21L, 21L, 11L, 10L, 13L, 9L, 17L, 18L, 14L), .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, -16L), class = "data.frame")

我就是这样画出来的:

代码语言:javascript
运行
复制
library(ggplot2)
library(gridExtra)

# First I create an empty graph with absolutely nothing :
qplot(1:10, 1:10, geom = "blank") + theme_bw() + theme(line = element_blank(), text = element_blank()) +
# Then I add my table :
annotation_custom(grob = tableGrob(cov_table_a), xmin=-5, xmax=10,ymin=1, ymax=10)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-24 14:26:41

注意:如果要在空画布上绘制表,则不需要使用ggplot作为容器:

代码语言:javascript
运行
复制
grid.table(cov_table_a, rows = NULL)

代码语言:javascript
运行
复制
grid.draw(tableGrob(cov_table_a, rows = NULL))

可以用来代替。

但也可以使用ggplot

代码语言:javascript
运行
复制
qplot(1:10, 1:10, geom = "blank") + 
  theme_void() +
  annotation_custom(
    grob = tableGrob(cov_table_a, rows = NULL), 
    xmin = -5, xmax = 10, ymin = 1, ymax = 10
  )

票数 22
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40788778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档