更改标题样式格式表R [英] change header style formattable R

查看:46
本文介绍了更改标题样式格式表R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将格式表与物种的某些值一起使用,因此,对于列名来说,斜体非常重要;我已经尝试过使用 formatter()函数,但是即使我使用"th" 节点而不是"span",它也仅对值起作用.

I'm trying to use formattable with some values for species, thus, it's very important for column names to be italic; I've tried with the formatter() function, but it only acts on the values, even if I use the "th" node instead of "span"

library(formattable)
make_italic <- formatter("span",
                      style =  "font-style:italic")
formattable(mtcars, list(mpg = make_italic, qsec = make_italic))

在mtcar中,如何将名称(mpg,cyl,disp等)更改为斜体?

In the mtcars, how may I change the names (mpg, cyl, disp,...) to italic?

推荐答案

我不知道 formattable 包,但是您创建的 make_italic 对象是一个函数向字符对象添加斜体标签.您可以直接在列名称上使用它.因为名称已更改,所以您不能再在 formattable 函数中使用它们来格式化列,但是您可以在以相同方式更改列名之前在data.frame中格式化这些列.有点黑,但可以.

I don't know the formattable package, but the make_italic object that you create is a function that adds italics tags to character objects. You can use that on the column names directly. Because the names get changed you can no longer use them in your formattable function to format the columns, however you can format those column in the data.frame before changing the column names the same way. A bit hackish, but works.

library(formattable)
data(mtcars)
mtcars_tab        <- mtcars 
make_italic       <- formatter("span", style =  "font-style:italic")
mtcars_tab$mpg    <- make_italic(mtcars_tab$mpg)
mtcars_tab$qsec   <- make_italic(mtcars_tab$qsec)
names(mtcars_tab) <- make_italic(names(mtcars_tab))
formattable(mtcars_tab)

这篇关于更改标题样式格式表R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆