Flexdashboard允许为其仪表指定三个扇区:“危险”,“警告”和“成功”。我想使用5个刻度扇区来显示我的观察值所在的区间。我用alpha 0.2(80%)和0.01(99%)计算置信区间,用它来定义5个扇区:
Sector 1 = c(min(value),lower_90_ci)
Sector 2 = c(lower_90_ci,lower_80_ci)
Sector 3 = c(lower_80_ci, upper_80_ci)
Sector 4 = c(upper_80_ci, upper_90_ci)
Sector 5 = c(upper_90_ci, max(value))
这是flexdashboard中的标准尺度:
library(flexdashboard)
gauge(42, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(80, 100), warning = c(40, 79), danger = c(0, 39)
))
答案 0 :(得分:1)
如果要在中间设置最佳范围,并在上下两侧都发出警告和危险,我尝试这样做:
gauge(value = 95, # For example
min = 0,
max = 100,
sectors = gaugeSectors(
success = c(20, 80),
warning = c(10, 90),
danger = c(0, 100)
)
)
您可能要确保扇区覆盖整个范围(最小-最大)。范围内但不属于任何扇区的任何值将使用默认颜色(成功)。
答案 1 :(得分:0)
我不认为它可以开箱即用。深入研究resolveSectors
函数表明它需要三个扇区并且非常不灵活:
function (sectors, min, max)
{
if (is.null(sectors)) {
sectors = sectors(success = c(min, max), warning = NULL,
danger = NULL, colors = c("success", "warning", "danger"))
}
if (is.null(sectors$success) && is.null(sectors$warning) &&
is.null(sectors$danger)) {
sectors$success <- c(min, max)
}
if (is.null(sectors$colors))
sectors$colors <- c("success", "warning", "danger")
customSectors <- list()
addSector <- function(sector, color) {
if (!is.null(sector)) {
if (!is.numeric(sector) || length(sector) != 2)
stop("sectors must be numeric vectors of length 2",
call. = FALSE)
customSectors[[length(customSectors) + 1]] <<- list(lo = sector[[1]],
hi = sector[[2]], color = color)
}
}
sectors$colors <- rep_len(sectors$colors, 3)
addSector(sectors$success, sectors$colors[[1]])
addSector(sectors$warning, sectors$colors[[2]])
addSector(sectors$danger, sectors$colors[[3]])
customSectors
}
<environment: namespace:flexdashboard>
尽管如此,您可以使用自定义构建的gauge
函数(使用当前函数作为模板)构建自己的resolveSectors
函数,该函数需要五个扇区。