5

I have a dataset as shown below

 ID       MinTemp     MaxTemp     Quartile1     Quartile2     Quartile3
 28       19          88          23            63            80
 43       18          78          25            57            77
 11       34          118         52            81            101

I am interested in learning how to create an inline boxplot for each row based on their corresponding, Min, Max, Quartile1, Quartile2, Quartile3 values using the sparkline package.

The final output should look like this below

enter image description here

Any help on accomplishing this is much appreciated.

zx8754
  • 52,746
  • 12
  • 114
  • 209
missy morrow
  • 337
  • 3
  • 16
  • Did you find a method @missy morrow? – mihow Jan 27 '22 at 06:11
  • I just posted the following similar question https://stackoverflow.com/questions/72100688/r-shiny-table-with-sparkline-boxplot but no luck so far – Angelo May 04 '22 at 16:33

1 Answers1

0

One of the options is to use sparkline::spk_chr which is a wrapper for a jquery.sparkline solution. The raw = TRUE has to be set so you will be expected to provide the low_outlier, low_whisker, q1, median, q3, high_whisker, high_outlier not the raw data points. When the showOutliers = FALSE is set then the outliers stats should not be provided.

Updated part of ?sparkline::spk_chr help page:

library(sparkline)
library(formattable)
set.seed(1234)
fw <- as.htmlwidget(
    formattable(
        data.frame(
            id = c("a", "b", "c"),
            sparkline = c(
                # low_outlier, low_whisker, q1, median, q3, high_whisker, high_outlier
                spk_chr(c(-3, -3, 1, 2, 3, 6, 6), type="box", raw = TRUE, width = 200),
                # low_whisker, q1, median, q3, high_whisker
                spk_chr(c(-3, 1, 2, 3, 6), type="box", raw = TRUE, width = 200, showOutliers = FALSE),
                # raw data
                spk_chr(rnorm(10), type="box", width = 200)
            ),
            stringsAsFactors = FALSE
        )
    )
)
spk_add_deps(fw)
polkas
  • 3,797
  • 1
  • 12
  • 25