小编use*_*133的帖子

使用TableGrob更改单元格的文本颜色

有没有办法在使用tableGrob和ggplot2时单独更改单元格文本的颜色?

例如,在下面的代码中,如果带有1的单元格可能是蓝色而带有2的单元格可能是红色,而3:8的单元格全黑,则会很棒.

library(ggplot2)
library(grid)

mytable = as.table(matrix(c("1","2","3","4","5","6","7","8"),ncol=2,byrow=TRUE))
mytable = tableGrob(mytable,gpar.coretext = gpar(col = "black", cex = 1))
mydf = data.frame(x = 1:10,y = 1:10)

ggplot( mydf, aes(x, y)) + annotation_custom(mytable)
Run Code Online (Sandbox Code Playgroud)

r colors ggplot2 gridextra r-grid

9
推荐指数
3
解决办法
5744
查看次数

标签 统计

colors ×1

ggplot2 ×1

gridextra ×1

r ×1

r-grid ×1