Modify boxplot using sparkline package

风格不统一 提交于 2021-01-29 15:50:31

问题


I am using the sparkline package to insert the boxplot into the DT table rows. I trying to modify the boxplot and add additional information on it.

Now boxplots look like this:

But I want to display more information on them, for example:
for A add values: (4,8,22)
for B add values: (5,15,22)

The desired output should look something like this:

I was trying to use help from here and here but can't figure it out.

Code:

library(dplyr)
library(sparkline)
library(DT)

df <- data.frame("Type" = c(rep("A",10), rep("B",10)),
             "Value_1"= c(1,12,10,15,5,30,7,25,9,10,-10,20,30,11,5,3,6,3,2,1))


df %>% 
 group_by(Type) %>% 
  summarize(boxplot = spk_chr(Value_1,
                     lineColor = 'black', 
                     fillColor = '#ccc',
                     chartRangeMin = range(df$Value_1)[1],
                     chartRangeMax = range(df$Value_1)[2],
                     width = 200,
                     height = 60,
                     type = "box",
                     #target = 8,
                     highlightLineColor = 'orange', 
                     highlightSpotColor = 'orange')) %>% 
  datatable(escape = F,
        rownames = F,
        options = list(fnDrawCallback = htmlwidgets::JS('function(){
                                                          HTMLWidgets.staticRender();
                                                          }'))
  ) %>% 
  spk_add_deps()


# for A (4,8,22)
# for B (5,15,22)

来源:https://stackoverflow.com/questions/61868853/modify-boxplot-using-sparkline-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!