r - 如何在 R 表的标题中写上标?
问题描述
我正在尝试将上标添加到表格的标题中。该表稍后将用作条形图的标签。因此,我想缩写一些表格标题,并在稍后的图表图例中解释这些缩写。
# libraries
library(gridExtra) # for cool table
library(grid) # for cool table
# create example
df <- data.frame( a = 1:6, b = rep( letters[1:3], each = 2 ) )
# Create plotmath superscript strings
df[1,1] = paste0(df[1,1],"^",1) # i unsuccessfully tried to change the example
colnames(df)[1] <- expression('Title'^2) # here another unsuccessful try
# Define theme to parse plotmath expressions
tt = ttheme_default(core=list(fg_params=list(parse=TRUE)))
tg_df <- tableGrob(d = df, theme=tt)
grid.newpage()
grid.draw(tg_df)
谢谢你的帮助。
解决方案
在tableGrob vignette中有一个例子。只需确保也解析列标题
tt <- ttheme_default(
core = list(fg_params = list(parse=TRUE)),
colhead = list(fg_params = list(parse=TRUE))
)
tg_df <- tableGrob(d = df, theme=tt)
grid.newpage()
grid.draw(tg_df)
推荐阅读
- php - 调用带有参数的控制器?
- xcode - 如何在 Xcode 12 的新更新中显示视图控件?
- linux - 带有 ssh 的 Git 克隆适用于 Linux,但不适用于 Windows PowerShell
- javascript - Tinymce 编辑器只添加文本
- microsoft-teams - 是否可以深层链接到频道内“文件”选项卡中的文件夹?
- android - 导航到另一个片段时如何保留 ActionBar 的 SearchView?
- javascript - 我想在 c# 中使用 javascript 和通用处理程序将图像上传到文件夹
- botframework - 为团队频道集成语音到文本机器人框架?
- javascript - 如何根据数组中的“现有字段”百分比添加“新字段”颜色
- python - 如何在 json 中获取本地机器的 ansible 事实?