【发布时间】:2020-05-08 06:05:44
【问题描述】:
我正在尝试创建一个 color_bar,其中条形基于行值子集的百分比,即 a1=(a1+b1)/2。但是,我还希望将数字格式化为百分比。
我试过谷歌搜索,但找不到其他人有类似问题。我怀疑可能有更好的方法可以更容易地做到这一点,但我想不通。
tempDf = data.frame(a=c(0.8,0.5), b=c(0.2,0.5),c=c(500,500)) # dummy data
formattable(tempDf,unlist(list(
lapply(as.list(1:nrow(tempDf)), function(row) {
list(
area(row, 1:2) ~ color_bar('green', function(row) row/sum(row)), # creates the green bars which are based on the percentage a1=(a1+b1)/2
area(row, 1:1) ~ function(x) percent(x, digits = 1) # formats the a row as percent *this overwrites the color bars*
)
})
)))
预期的输出是绿色条在 A 列中可见并且以百分比表示。目前百分比代码会覆盖条形。
【问题讨论】:
-
同样的问题,但似乎不会影响编写本指南的人:displayr.com/formattable/…
标签: r formattable