微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 dataui 包在 R 中设置迷你图样式

如何解决使用 dataui 包在 R 中设置迷你图样式

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

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

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

enter image description here

这可能吗?

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

df <- tibble(
  Company = c("A","B"),Line = list(list(c(1,2,1)),list(c(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

解决方法

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

df <- tibble(
  Company = c("A","B"),Line = list(list(c(1,2,1)),list(c(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",stroke = "#F1a0ff",dui_sparklineseries(
                    curve = "linear",showArea = TRUE,fill = colpal_fill[index],stroke = colpal_stroke[index]
                  )
                )
              )
            }
          )
        )
)
rt1

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。