https://cran.r-project.org/web/packages/formattable/formattable.pdf
我一直在使用 Formattable 包在 R 中制作一些漂亮的表格。我正在尝试将表格保存为图像(或实际上是任何文件格式),但找不到有效的命令。使用 jpeg/png 函数或 dev.copy 创建空白文档。理想情况下,我希望能够将这些表保存在一个循环中。有谁知道如何做到这一点?
数据:
library(formattable)
DF <- data.frame(Ticker=c("", "", "", "IBM", "AAPL", "MSFT"),
Name=c("Dow Jones", "S&P 500", "Technology",
"IBM", "Apple", "Microsoft"),
Value=accounting(c(15988.08, 1880.33, NA,
130.00, 97.05, 50.99)),
Change=percent(c(-0.0239, -0.0216, 0.021,
-0.0219, -0.0248, -0.0399)))
formattable(DF, list(
Name=formatter(
"span",
style = x ~ ifelse(x == "Technology",
style(font.weight = "bold"), NA)),
Value = color_tile("white", "orange"),
Change = formatter(
"span",
style = x ~ style(color = ifelse(x < 0 , "red", "green")),
x ~ icontext(ifelse(x < 0, "arrow-down", "arrow-up"), x)))
)