下面的代码
library(magrittr)
library(gt)
library(dplyr)
TestColumn_one <- c("CA", "FL", "GA", "MA", "NM", "OH", "OK", "TN", "UT")
TestColumn_two <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
TestColumn_three <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
TestColumn_four <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
TestColumn_five <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
TestColumn_six <- c("Community 1",
"Community 2",
"Community 3",
"Community 4",
"Community 5",
"Community 6",
"Community 7",
"Community 8",
"Community 9")
TestColumn_seven <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
test.dashboard.data <- data.frame(TestColumn_one, TestColumn_two,TestColumn_three,
TestColumn_four, TestColumn_five, TestColumn_six,
TestColumn_seven,
stringsAsFactors = FALSE)
names(test.dashboard.data)[1] <- "State"
names(test.dashboard.data)[2] <- "NCIncidence"
names(test.dashboard.data)[3] <- "NCRiskLevel"
names(test.dashboard.data)[4] <- "TestIncidence"
names(test.dashboard.data)[5] <- "TestRiskLevel"
names(test.dashboard.data)[6] <- "LocalCommunity"
names(test.dashboard.data)[7] <- "LocalRisk"
testBoard <- test.dashboard.data %>% gt() %>%
tab_header(
title = md("**CDC Risk Levels**"),
subtitle = md("*Based on 14-day moving average of cases per 100,000*")
) %>%
cols_label(NCIncidence = "Incidence",
NCRiskLevel = "Risk Level",
TestIncidence = "Incidence",
TestRiskLevel = "Risk Level",
LocalCommunity = "Local Community",
LocalRisk = "Risk Level") %>%
#These two spanners get clobbered by the last two
tab_spanner(label="New Cases", columns=vars(NCIncidence, NCRiskLevel)) %>%
tab_spanner(label="Test Positivity", columns=vars(TestIncidence, TestRiskLevel)) %>%
tab_spanner(label="Statewide", columns=vars(NCIncidence, NCRiskLevel, TestIncidence, TestRiskLevel)) %>%
tab_spanner(label="Localities", columns=vars(LocalCommunity, LocalRisk))
print(testBoard)
生成这张表......数据显然是垃圾,无法在列中占据一席之地,但你明白了。
如您所见,两个扳手列标签
tab_spanner(label="New Cases", columns=vars(NCIncidence, NCRiskLevel)) %>%
tab_spanner(label="Test Positivity", columns=vars(TestIncidence, TestRiskLevel)) %>%
被覆盖。有没有办法实现两行扳手标签?或者那是不可能的?
Stackoverflow 说我的帖子主要是代码,我必须添加更多细节,所以我在这里输入更多字符,希望能扫清障碍……但希望问题很清楚。