r - 如何更改 R 中 geom_table() 中列标题的颜色?
问题描述
我正在使用包中的geom_table()
函数ggpmisc
将表格图例添加到我的图中。我想从带有列标题的第一行中删除灰色。
library(ggpmisc)
library(tidyverse)
mtcars %>%
group_by(cyl) %>%
summarize(wt = mean(wt), mpg = mean(mpg)) %>%
ungroup() %>%
mutate(wt = sprintf("%.2f", wt),
mpg = sprintf("%.1f", mpg)) -> tb
df <- tibble(x = 5.45, y = 34, tb = list(tb))
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
geom_point() +
geom_table(data = df, aes(x = x, y = y, label = tb),
table.theme = ttheme_gtbw)
解决方案
您可以使用从(一些可能选项的描述ggpmisc
) 传递给相应ttheme
函数的参数来设置主题。如果我正确理解您的问题,您希望表格中第一行的背景为白色。您可以使用以下代码来构建您的绘图来实现此目的:gridExtra
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
geom_point() +
geom_table(data = df, aes(x = x, y = y, label = tb),
table.theme = ttheme_gtbw(colhead = list(bg_params = list(fill = "white"))))
推荐阅读
- heroku - Heroku Review App 找不到数据库
- android - Gradle 错误:任务 ':app:processDebugGoogleServices' 执行失败并确保首先调用 FirebaseApp.initializeApp(Context)
- amazon-web-services - 在 AWS 上使用 Kubernetes 部署 HTTP/2 Web 服务器
- elixir - 定义名为“in”的函数的语法错误
- ansible - 尝试-m ping all时Ansible“无法通过ssh连接到主机:权限被拒绝”
- android - 如何使用 Kotlin 将 SF 从 Activity 传递给 Presenter?
- angular - Angular项目编译失败-找不到模块
- java - 在适用于 Windows 10 Home 64bit 的 Android Studio 3.1.3 中运行构建失败
- c++ - 结构/方法不起作用
- java - 创建通用对象的缓存