【问题标题】:Style sparklines in R using dataui package使用 dataui 包在 R 中设置迷你图样式
【发布时间】:2021-09-14 00:00:00
【问题描述】:

我正在使用 dataui 包来创建迷你图。我希望对角线填充的颜色与迷你图的颜色相匹配。

因此,A 公司将有一条绿线,下方有绿色对角线填充,而 B 公司将有一条红线,下方有红色对角线填充。

我似乎无法让对角线填充具有多个值。

这可能吗?

library("tidyverse")
library("dataui")
library("reactable")

df <- tibble(
  Company = c("A", "B"),
  Line = list(list(c(1, 2, 1)), list(c(2, 2, 1)))
)

colpal <- c("#00DA07", "#BB0337")

rt1 <- reactable(df,
        compact = TRUE,
        fullWidth = FALSE,
                 
        columns = list(
          Line = colDef(
            cell = function(value, index) {
              dui_sparkline(
                data = value[[1]], 
                height = 80,
                components = list(
                  dui_sparklineseries(
                    curve = "linear",
                    showArea = TRUE,
                    fill = "url(#area_pattern2)",
                    stroke = colpal[index]),
                  
                  # Diagonal fill lines
                  dui_sparkpatternlines(
                    id = "area_pattern2",
                    height = 4,
                    width = 4,
                    stroke =  colpal[index],
                    strokeWidth = 1,
                    orientation = "diagonal"
                  )
                  
                )
              )
            }
          )
        )
)
rt1

【问题讨论】:

    标签: r sparklines


    【解决方案1】:
    library("tidyverse")
    library("dataui")
    library("reactable")
    
    df <- tibble(
      Company = c("A", "B"),
      Line = list(list(c(1, 2, 1)), list(c(2, 2, 1)))
    )
    
    colpal_fill <- c("url(#area_pattern2)",  "url(#area_pattern3)")
    colpal_stroke <- c("#91a7ff", "#F1a0ff")
      
    rt1 <- reactable(df,
            compact = TRUE,
            fullWidth = FALSE,
                     
            columns = list(
              Line = colDef(
                cell = function(value, index) {
                  dui_sparkline(
                    data = value[[1]], 
                    height = 80,
                    margin = list(top = 20, right = 20, bottom = 20, left = 20),
                    
                    components = list(
                      dui_sparkpatternlines(
                        id = "area_pattern2",
                        height = 4,
                        width = 4,
                        stroke = "#91a7ff",
                        strokeWidth = 1,
                        orientation = "diagonal"
                      ),
                      
                      dui_sparkpatternlines(
                        id = "area_pattern3",
                        height = 4,
                        width = 4,
                        stroke = "#F1a0ff",
                        strokeWidth = 1,
                        orientation = "diagonal"
                      ),
                      
                      dui_sparklineseries(
                        curve = "linear",
                        showArea = TRUE,
                        fill = colpal_fill[index],
                        stroke = colpal_stroke[index]
                      )
                    )
                  )
                }
              )
            )
    )
    rt1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      相关资源
      最近更新 更多