作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
与 styleColorBar
,如何使颜色条的大小与列的绝对值成正比?与此相反,在下面的示例中,查看 cyl
列,红色条越大,值越大。
代码:
data <- head(mtcars[,1:4])
data[,2] <- -data[,2]
data
out <- datatable(data, rownames = FALSE) %>%
formatStyle('mpg',
background = styleColorBar(data$mpg, 'lightblue'),
backgroundSize = '95% 50%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'right') %>%
formatStyle('cyl',
background = styleColorBar(data$cyl, 'red'),
backgroundSize = '95% 50%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'right')
out
最佳答案
这是一种骇人听闻的方式:styleColorBar
生成一些 JavaScript,您可以在其中替换 value
来自 Math.abs(value)
.为了正确设置限制,我还使用了 abs(data$cyl)
:
library(DT)
data <- head(mtcars[,1:4])
data[,2] <- -data[,2]
data
out <- datatable(data, rownames = FALSE) %>%
formatStyle('mpg',
background = styleColorBar(data$mpg, 'lightblue'),
backgroundSize = '95% 50%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'right') %>%
formatStyle('cyl',
background = gsub(
"value", "Math.abs(value)",
styleColorBar(abs(data$cyl), 'red'),
fixed=T),
backgroundSize = '95% 50%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'right')
out
关于r - styleColorBar : have the size of the color bar be proportional to absolute values of a column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44504024/
我是一名优秀的程序员,十分优秀!