Hello,
I have the following data which is just the diamond dataset with an additional Qualify
column. I need custom formatting to happen on the pivot table based on the Qualify
column.
library(tidyverse)
library(radiant.data)
#> Loading required package: magrittr
#>
#> Attaching package: 'magrittr'
#> The following object is masked from 'package:purrr':
#>
#> set_names
#> The following object is masked from 'package:tidyr':
#>
#> extract
#> Loading required package: lubridate
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
#>
#> Attaching package: 'radiant.data'
#> The following objects are masked from 'package:lubridate':
#>
#> month, wday
#> The following object is masked from 'package:forcats':
#>
#> as_factor
#> The following objects are masked from 'package:purrr':
#>
#> is_double, is_empty, is_numeric
#> The following object is masked from 'package:ggplot2':
#>
#> diamonds
#> The following object is masked from 'package:base':
#>
#> date
library(DT)
df_diamonds <- diamonds %>%
mutate(Qualify = sample(c(0:1), replace = TRUE, size = nrow(diamonds)))
df_diamonds
#> # A tibble: 3,000 x 12
#> price carat clarity cut color depth table x y z date
#> <int> <dbl> <fct> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <date>
#> 1 580 0.32 VS1 Ideal H 61 56 4.43 4.45 2.71 2012-02-26
#> 2 650 0.34 SI1 Very~ G 63.4 57 4.45 4.42 2.81 2012-02-26
#> 3 630 0.3 VS2 Very~ G 63.1 58 4.27 4.23 2.68 2012-02-26
#> 4 706 0.35 VVS2 Ideal H 59.2 56 4.6 4.65 2.74 2012-02-26
#> 5 1080 0.4 VS2 Prem~ F 62.6 58 4.72 4.68 2.94 2012-02-26
#> 6 3082 0.6 VVS1 Ideal E 62.5 53.7 5.35 5.43 3.38 2012-02-26
#> 7 3328 0.88 SI1 Ideal I 61.7 56 6.14 6.18 3.8 2012-02-26
#> 8 4229 0.93 SI1 Prem~ E 61.4 57 6.34 6.23 3.86 2012-02-26
#> 9 1895 0.51 VVS2 Very~ G 63.4 57 5.09 5.06 3.22 2012-02-26
#> 10 3546 1.01 SI2 Good E 63.9 58 6.31 6.37 4.05 2012-02-26
#> # ... with 2,990 more rows, and 1 more variable: Qualify <int>
tab <- pivotr(df_diamonds, cvars = c("cut","color","carat"), nvar = "price", fun = "n_obs") %>%
dtab(format="color_bar")
#tab
Created on 2020-09-27 by the reprex package (v0.3.0)
Currently the table looks like this:
What I want to happen is that say 1 of 5 values in very good x d x 0.3 has 0 in Qualify it needs to grey out that number in the pivot. If at least one of the values in the aggregate for the pivot contain 0 then it needs to grey it out (not delete it as I still need the number for reference).
Can anyone assist?