有没有办法在使用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)