【问题标题】:How can i have more than three gauge sectors in flexdashboard?我怎样才能在 flexdashboard 中拥有三个以上的仪表扇区?
【发布时间】:2018-03-15 10:39:01
【问题描述】:

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)
))

【问题讨论】:

    标签: r flexdashboard


    【解决方案1】:

    如果打算在中间有最佳射程,上下两侧都有警告和危险,我试过这个:

    gauge(value = 95,  # For example
          min = 0,
          max = 100,
          sectors = gaugeSectors(
            success = c(20, 80),
            warning = c(10, 90),
            danger = c(0, 100)
            )
          )
    

    您可能希望确保扇区覆盖整个范围(最小-最大)。范围内但不属于任何扇区的任何值都将使用默认颜色(成功)。

    【讨论】:

      【解决方案2】:

      我不认为它可以开箱即用。深入研究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 函数(使用当前函数作为模板),该函数需要五个扇区。

      【讨论】:

      • 谢谢!在我使用 Gauge() 定义颜色并将它们作为变量传递给 gaugeSectors(colors= c(color1,color2,color3)-argument 之前,我还考虑过使用函数的解决方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-25
      • 2021-10-24
      • 1970-01-01
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      相关资源
      最近更新 更多