【问题标题】:Data bars with Data tables带有数据表的数据栏
【发布时间】:2021-02-22 12:37:51
【问题描述】:

我正在尝试按照以下步骤在表格的列中添加数据栏:

library(DT)
options(DT.options = list(pageLength = 5))
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
datatable(df) %>% formatStyle(names(df),
  background = styleColorBar(range(df), 'lightblue'),
  backgroundSize = '98% 88%',
  backgroundRepeat = 'no-repeat',
  backgroundPosition = 'center')

单元格中的条形图从右到左显示,我希望它们从左到右显示。在数据表中可以做些什么来修改这些数据条。

【问题讨论】:

    标签: r dt


    【解决方案1】:

    有一个参数 angle th styleColorBar 应该可以完成这项工作

    library(DT)
    options(DT.options = list(pageLength = 5))
    df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
    datatable(df) %>% formatStyle(names(df),
                                  background = styleColorBar(range(df), 'lightblue', angle = -90),
                                  backgroundSize = '98% 88%',
                                  backgroundRepeat = 'no-repeat',
                                  backgroundPosition = 'center')
    

    来自help("styleColorBar")

    角度 表示相对于水平线和渐变线填充渐变的方向的度数,逆时针方向。例如,90 从右到左填充,-90 从左到右填充

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      • 2018-06-15
      相关资源
      最近更新 更多