- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个关于gridExtra包中的tableGrob/grid.table的问题。使用常规参数设置,可以直接为备用行着色。但是,我希望对行的颜色进行更多控制可能是可行的。
例如,是否可以用不同的颜色为每三行着色?
我怀疑通过这个链接中的示例判断,grid.edit函数是解决此问题的一种方法:http://code.google.com/p/gridextra/wiki/tableGrob但我不知道如何将其应用于我的问题。
我相信发布这个问题的人也有同样的想法。 Table with rows of different colors with tableGrob
由于兼容性问题,我目前仍停留在R 2.13上,因此,如果有不涉及较新版本的建议,那将是理想的选择。
示例代码:
library(gridExtra)
grid.table(mtcars[1:10, ],
gpar.coretext = gpar(fontsize = 10),
gpar.corefill = gpar(fill = "lightblue", alpha=0.5, col = NA),
h.even.alpha = 0.5
)
最佳答案
从gridExtra的v> = 2.0.0开始,grid.table
现在基于gtable,并且可以自定义到比以前版本更深的级别。 vignette has more examples,但是为了完整起见,这里的示例说明了如何突出显示特定的单元格,
g <- tableGrob(iris[1:4, 1:3])
find_cell <- function(table, row, col, name="core-fg"){
l <- table$layout
which(l$t==row & l$l==col & l$name==name)
}
ind <- find_cell(g, 3, 2, "core-fg")
ind2 <- find_cell(g, 2, 3, "core-bg")
g$grobs[ind][[1]][["gp"]] <- gpar(fontsize=15, fontface="bold")
g$grobs[ind2][[1]][["gp"]] <- gpar(fill="darkolivegreen1", col = "darkolivegreen4", lwd=5)
grid.draw(g)
find_cells <- function(table, row, col, name="core-fg"){
l <- table$layout
unlist(Map(function(r, c) which(((l$t-1) == r) & ((l$l-1) == c) & (l$name == name)), row, col))
}
modify_cells <- function(g, ids, gp=gpar()){
for(id in ids) g$grobs[id][[1]][["gp"]] <- gp
return(g)
}
ids <- find_cells(g, 1:3, c(3,2, 1), "core-fg")
g <- modify_cells(g, ids, gpar(fontsize=15, fontface="bold"))
grid.newpage()
grid.draw(g)
faces <- sample(1:4, size = prod(dim(iris[1:4, 1:2])), replace = TRUE)
tt <- ttheme_default(core=list(fg_params=list(fontface=faces)))
grid.table(iris[1:4, 1:2], theme=tt)
关于r - gridExtra使用tableGrob为不同的行着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18414001/
我在绘制简单摘要时遇到问题。 library(gridExtra) SummaryTable 从 ?tableGrob 开始,它的第一个参数是矩阵或 data.frame。 t 将 summary
我正在使用 R 的 gridExtra 包。 我想将第二列的数字向左对齐,而不改变第一列名称的对齐方式。是否可以? 谢谢! library(gridExtra) library(grid) names
有一种绘制多个图形的非常方便的方法,那就是使用 gridExtra - grid.arrange: grid.arrange(plot1,plot2,plot3,plot4,plot5,plot6,p
我花了很多时间试图将 11 个图形放在一个图中并使用 gridExtra 排列它们,但我失败了,所以我求助于您,希望您能提供帮助。 我有 11 种钻石分类(称为 size1 )和其他 11 种分类(
问题: 我使用 gridExtra 创建了一个表包裹: require("gridExtra") # Prepare data frame col1 = c(rep("A", 3), rep("B",
我正在尝试排列由 ggplot2 生成的一些图使用 gridExtra包裹。 library(ggplot2) library(gridExtra) p1 = 2.0.0,main参数已重命名 top
我想完美地对齐这些图: 这是R代码: library(tidyverse) library(gridExtra) groupes % filter(type==1) %>% ggplot(aes(pr
我想用 ggplot 绘制一个表格,但是似乎无法丢失 row.names。 我试过了: row.names(cov_table_a)<-NULL # outside the plot row.name
这个问题在这里已经有了答案: Three ggplots in a 2x2 grid (1 个回答) 关闭 1 年前。 我想按以下方式布置三个地 block : [FirstPlot] [2nd]
我有以下数据框 df section_name #> 1 WWW #> 2 WWW:XXX:YYY #> 3 WWW:ZZZ #> 4 WWW:ZZZ:
我在我的 WPF 应用程序中使用 grid extra 来设计各个响应式组件。我有如下 View :
我有一系列调查问题,正在报告学校、学校家庭和整个董事会的答复。有些问题很长——我想做的是让文本在专栏结束时自动换行。现在我必须手动添加换行符。这可能吗?我使用的是 R 版本 3.2.1 和 gridE
我想安排我的ggpairs与 arrangeGrob 一起绘制: library(GGally) library(gridExtra) df ggplotGrob(qplot(1:100)) sta
我已经使用 gridExtra 创建了 2 个彼此相邻的图,我可以使用 ggsave 保存对象 但是,gridExtra 中的绘图未对齐,所以我使用了这种方法 #Method 2 - gtable
我使用 gridExtra::grid.arrange 将多个图放入一张图像中并且希望可以选择将组合图保存为一个对象,该对象可以作为返回对象列表的一部分从函数内返回。理想情况下,我想在不打印绘图对象的
我正在使用 R Shiny 想在 gridExtra 的帮助下并排放置几个 ggplotly 图。 一个 plotly (没有 gridExtra)工作得很好: library(shiny) libr
我知道 gridExtra 已更新。结果,我想知道如何更改标题大小。这不再有效 grid.arrange(a, b, c, d,ncol=2, nrow=2, main=textGr
我正在使用 xyplot (lattice) 生成四个图,并进一步将它们与 grid.arrange (gridExtra) 组合。 我想获得一个具有通用全局图例的图表。我所达到的最接近的是以下内容。
我正在使用 gridExtra 结合 Ggplot 的条形图制作摘要图。 问题是我想让摘要对 radioButtons 输入有反应。 我想要实现的目标: 我有什么: 我确定是因为使用了我在服务器中使用
在对齐网格图形对象时遇到了一些麻烦——我已经阅读了我能找到的所有文档,包括 Murrell 的书,但没有成功。我认为我正在尝试做的事情非常简单,所以希望我缺少简单的东西。 这是一个可重现的示例,它将按
我是一名优秀的程序员,十分优秀!