示例数据(从formattablegithub docs 修改):
df <- data.frame(
id = 1:10,
name = c("Bob", "Ashley", "James", "David", "Jenny",
"Hans", "Leo", "John", "Emily", "Lee"),
age = c(48, 47, 40, 28, 29, 29, 27, 27, 31, 30),
test1_score = c(18.9, 19.5, 19.6, 12.9, 11.1, 7.3, 4.3, 3.9, 2.5, 1.6),
test2_score = c(9.1, 9.1, 9.2, 11.1, 13.9, 14.5, 19.2, 19.3, 19.1, 18.8),
stringsAsFactors = FALSE)
Run Code Online (Sandbox Code Playgroud)
您可以使用这样的额外颜色格式制作漂亮的表格:
library(formattable)
formattable(df, list(
age = color_tile("white", "orange"),
test1_score = color_bar("pink", 0.2),
test2_score = color_bar("pink", 0.2)
))
Run Code Online (Sandbox Code Playgroud)
看起来像这样: …