Comments (10)
Vibrant is best for me. Which colour would you use as the default for facets and ungrouped plots?
from incidence2.
Awesome. Maybe the first of the palette as default color for single plots / no groups? This said, feel free to reorder the colors of the palette if you fancy.
from incidence2.
I'm colourblind (red/green) so hopefully help out with the testing of palettes.
With the release of R 4.0 (see https://developer.r-project.org/Blog/public/2019/11/21/a-new-palette-for-r/index.html). Sometimes I find the most colourblind-friendly palettes are not necessarily the nicest looking (this is subjective of course). One additional thing to think about is palette ordering. Sometimes you can get away with a less friendly palette if you are only using a small subset of them.
from incidence2.
Not that I'm nessarily advocating for it, but here's one, derived from 'paired' in RColorBrewer, which natively allows up to 12 levels; not color-blind friendly I fear:
## trying colors
### paired tweaked
incidence_pal <- function(n) {
col <- c("#1F78B4", "#33A02C", "#E31A1C", "#FF7F00", "#6A3D9A", "#B15928",
"#A6CEE3", "#B2DF8A", "#FB9A99", "#FDBF6F", "#CAB2D6", "#FFFF99"
)
if (n < length(col)) {
return(col[seq_len(n)])
}
colorRampPalette(col)(n)
}
barplot(1:12, col = incidence_pal(12), main = "palette: sorted `paired`")
## 3 colors
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60),
col = incidence_pal(3), border = "transparent")
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of rows [3]
## 8 colors
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 8, ncol = 60),
col = incidence_pal(8), border = "transparent")
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 8, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of columns [60]
## 12 colors
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 12, ncol = 60),
col = incidence_pal(12), border = "transparent")
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 12, ncol = 60):
#> data length [1000] is not a sub-multiple or multiple of the number of rows [12]
Created on 2020-07-03 by the reprex package (v0.3.0)
from incidence2.
From left to right, drop colours 1, 2, 3 and 7 and it works for me
incidence_pal <- function(n) {
col <- c("#FF7F00", "#6A3D9A", "#B15928", "#B2DF8A", "#FB9A99", "#FDBF6F", "#CAB2D6", "#FFFF99"
)
if (n < length(col)) {
return(col[seq_len(n)])
}
colorRampPalette(col)(n)
}
barplot(1:8, col = incidence_pal(8), main = "palette: reduced sorted `paired`")
Created on 2020-07-03 by the reprex package (v0.3.0)
from incidence2.
This one is derived from the colorbling-friendly categorical variable palettes at: https://personal.sron.nl/~pault/#sec:qualitative
Two versions:
vibrant
: my favourite, less categoriesmuted
: nice too, more categories
I think I also like the colors better, but how does it work for you?
## my preferred, uses https://personal.sron.nl/~pault/#sec:qualitative
col_vibrant <- c(
"#0077BB",
"#33BBEE",
"#009988",
"#EE7733",
"#CC3311",
"#EE3377",
"#BBBBBB"
)
col_muted <- c(
"#332288",
"#88CCEE",
"#44AA99",
"#117733",
"#999933",
"#DDCC77",
"#CC6677",
"#882255",
"#AA4499",
"#BBBBBB"
)
make_palette <- function(x) {
function(n) {
if (length(x) > n) {
x[seq_len(n)]
} else {
colorRampPalette(x)(n)
}
}
}
#### vibrant palette
pal_vibrant <- make_palette(col_vibrant)
barplot(1:7, col = pal_vibrant(7), main = "palette: vibrant")
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60),
col = pal_vibrant(3))
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of rows [3]
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 8, ncol = 60),
col = pal_vibrant(8))
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 8, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of columns [60]
#### muted palette
pal_muted <- make_palette(col_muted)
barplot(1:7, col = pal_muted(7), main = "palette: muted")
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60),
col = pal_muted(3))
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of rows [3]
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 10, ncol = 60),
col = pal_muted(10))
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 10, ncol = 60):
#> data length [1000] is not a sub-multiple or multiple of the number of columns
#> [60]
Created on 2020-07-03 by the reprex package (v0.3.0)
from incidence2.
Now implemented. What do you think about the default for the column borders (white or NA)
from incidence2.
Morning! I was trying to test both to compare and found this issue. I think it may come from the borders (bars are so thin we see only the border)? If that is the case, that could be an element to consider in the default. My thinking would be:
- transparent border: safer for thin bars (if that's the issue)
- grey / black border: may be better contrast between colors (not even sure if that's true)
from incidence2.
On an unerlated point: maybe it would make sense to plot the missing (NA
) group as grey?
from incidence2.
Are we happy to close this now?
from incidence2.
Related Issues (20)
- Should we only provide getters for the variable names (not values)?
- Should a `find_peaks()` like function be in incidence HOT 1
- Restore some of the header information for incidence2 objects HOT 1
- Add minimal `new_incidence()` constructor
- Should `complete_dates()` use a different default `by` argument for POSIXct dates? HOT 7
- Consider warning when incidence objects are created with POSIXct dates HOT 1
- Error: object 'date_onset' not found HOT 1
- Error: show_cases dont work HOT 9
- reinstate `day` interval HOT 1
- Document `day` interval in vignettes.
- `plot.incidence2()` fails with `grates_period` dates HOT 3
- Make makefile more usable by others
- Ensure data.table uses 2 threads max in docs and examples
- NA values in observations cause a value of NA to be returned HOT 10
- Document how to handle grouped line list columns HOT 4
- Allow user to suppress NA warning in count variables
- vignette documentation on building upon incidence2 HOT 2
- Fix formatting of old news entries HOT 1
- Rework the devel news entry HOT 1
- 2.3.0 release TODO
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from incidence2.