change header style formattable R

前端 未结 1 936
鱼传尺愫
鱼传尺愫 2021-01-21 07:19

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, bu

相关标签:
1条回答
  • 2021-01-21 07:46

    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)
    
    0 讨论(0)
提交回复
热议问题