如何更改R中格式表中的字体系列?

时间:2017-02-22 12:26:59

标签: css r formattable

在我的大学的数据科学项目中,我们已经被要求制作一个决策树,以模拟哪些客户可能响应或不响应活动。该任务的一个要求是制作一个混淆矩阵,我将其转换为数据帧。这是我生成的数据框。

    confusionMatrixCARTDecisionTree <- data.frame("Number Predicted to Not Subscribe" = 
    c(36006, 542), "Number Predicted to Subscribe" = c(3554, 1086), 
    row.names = c("Number of Individuals that Subscribed", 
    "Number of Individuals that didn't Subscribe"));

然后我使用此代码将其转换为格式表。

    formattableConfusionMatrixCARTDecisionTree <- formattable(
    confusionMatrixCARTDecisionTree, align = "c", 
    list("Predicted Number not Subscribing" = color_tile("white", "yellow"),     
    "Predicted Number Subscribing" = color_tile("yellow", "white")));

然后我在这里找到一个函数https://github.com/renkun-ken/formattable/issues/26,将formattable放入pdf报告中。但是,我现在要做的是将字体系列更改为混淆矩阵的CMU Serif,以便与LaTeX文件保持一致。我已经研究了如何更改列的字体,如下所示:

    formattableConfusionMatrixCARTDecisionTree <- 
    formattable(confusionMatrixCARTDecisionTree, list("Predicted Number not Subscribing" = 
    formatter("span", style=style("font-family" = "CMU Serif"))));

但是,我已阅读此处的文档https://cran.r-project.org/web/packages/formattable/formattable.pdf并且我已在线搜索但我找不到更改标题字体或行名称的方法。如果有人有解决方案,我将永远感激不尽!如果有人知道某些代码会改变整个表的字体系列,我也会非常高兴。

注意:我确实理解在此处How to change appearance of table header row with R formattable package询问了有关更改标题外观的问题,但是,这是没有答案的,并且没有解决更改字体系列的问题。

感谢您的时间!我真的相信任何答案都会帮助其他人使用这个伟大的包。

1 个答案:

答案 0 :(得分:1)

@font-face {
   font-family: 'Name';
   src:url('../fonts/Name.eot?#') format('eot'),url('../fonts/Name.woff') format('woff'),url('../fonts/Name.ttf') format('truetype');
}
html {
   height:100%
}
body{
   font-family:Name,Tahoma,tahoma,Arial;
   background-color:#fafafa;
   height:100%
}