如何更改使用R中的d3treeR和treemap构建的交互式树形图中的默认字体大小?

时间:2016-09-11 15:29:20

标签: r treemap

我正在制作交互式多层树图并将它们导出为HTML文件 - 这就是我的代码的样子:

library(googleVis)  #not really needed, only using the datset "Fruit" in example
library(treemap)
library(d3treeR)

fruitTree <- d3tree(
              treemap(Fruits,
                      index=c("Fruit", "Year"),
                      vSize="Profit",
                      vColor="Fruit"
                     )
                     ,rootname = "Fruit")

htmlwidgets::saveWidget(as.widget(fruitTree), "D:/temp/fruit.html")

我不喜欢默认的字体大小,我没有找到任何操作它们的选项(至少对于交互式的vizs。当使用'treemap'命令时)。

这是输出的样子:

第一层:enter image description here

第二层,当你点击其中一个块时: enter image description here

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

您可以使用htmltools::tags()

library(htmltools)

browsable(
  tagList(
    tags$head(
      tags$style('text.label{font-size: 20px !important}')
    ),
    d3tree(
      treemap(Fruits,
              index=c("Fruit", "Year"),
              vSize="Profit",
              vColor="Fruit"
      )
      ,rootname = "Fruit")
  )
)

给出了:

enter image description here