简体   繁体   English

更改标题样式格式表R

[英]change header style formattable R

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" 我已经尝试过formatter()函数,但是即使我使用"th"节点而不是"span" ,它也仅作用于值

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

In the mtcars, how may I change the names (mpg, cyl, disp,...) to italic? 在mtcar中,如何将名称(mpg,cyl,disp等)更改为斜体?

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. 我不知道formattable包,但make_italic您创建对象,增加了斜体字标签字符对象的功能。 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. 由于名称已更改,因此您不能再在formattable函数中使用它们来格式化列,但是您可以在以相同方式更改列名称之前在data.frame中格式化这些列。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM