Closed jzadra closed 1 year ago
Slightly smaller reprex:
library(tidyverse)
library(visdat)
dat <- tibble(
constant = 34,
regular = 1:5,
sub_regular = c(NA, NA, 1, 2, 34)
)
vis_value(dat)
vis_value(dat, na_colour = "red")
Created on 2022-10-21 with reprex v2.0.2
I think this is happening inside the transformation where it rescales the data. Taking a closer look now
Is a 1 value the best way to go? To me that is assigning a relative value to something that can't be relative. Perhaps an argument for constant, with a default like white or black?
Hi @jzadra - thanks for that! Good point, however it becomes a bit challenging to implement as the colour scale is 0-1, and so the data looks like so:
# A tibble: 15 × 4
rows variable valueType value
<int> <chr> <dbl> <dbl>
1 1 constant 1 34
2 1 regular 0 1
3 1 sub_regular NA NA
4 2 constant 1 34
5 2 regular 0.25 2
6 2 sub_regular NA NA
7 3 constant 1 34
8 3 regular 0.5 3
9 3 sub_regular 0 1
10 4 constant 1 34
11 4 regular 0.75 4
12 4 sub_regular 0.0303 2
13 5 constant 1 34
14 5 regular 1 5
15 5 sub_regular 1 34
Although I like the idea of adding an extra colour for a "constant" value, I don't think I can come up with a way to show both colour scales. The "NA" colour value is a special case for this, where ggplot2 treats this differently.
My thoughts for assigning the 1 value is that within that column, that value is the maximum value - in this case, 34/34 = 1.
It might not be the maximum value relative to other data, but it will definitely stand out, and in the process should help flag itself in the context of the plot.
library(tibble)
library(visdat)
dat <- tibble(
constant = 34,
regular = 1:5,
sub_regular = c(NA, NA, 1, 2, 34)
)
dat
#> # A tibble: 5 × 3
#> constant regular sub_regular
#> <dbl> <int> <dbl>
#> 1 34 1 NA
#> 2 34 2 NA
#> 3 34 3 1
#> 4 34 4 2
#> 5 34 5 34
vis_value(dat)
Created on 2022-12-13 with reprex v2.0.2
Looking further it looks like there is a way to add other colour scales (http://gradientdescending.com/how-to-use-multiple-color-scales-in-ggplot-with-ggnewscale/) but this involves adding another dependency, which I would prefer to avoid in this instance.
Let me know what you think! Thanks for your contributions, I really value these! :)
@njtierney I see your point about using the 1 value for a constant, and I think you're right that that's the way to go! Thanks for the great package!
No worries! Thanks for using it and providing useful feedback! 😄
When a table has a column with a single distinct constant value, that column gets colored using the NA color.
I'd like to suggest that an additional argument with a default different from the
na_colour
default (grey90) be added to color constant value columns.