Closed sdhutchins closed 5 years ago
It could also be worthwhile to take a look at the ggsci package. It has some good palettes.
https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html This one is supposed to be really good for colorblindness too.
Here's my R code to create the color palette we looked at:
> x <- colorRampPalette(unique(c(rev(viridis::viridis(800)[300:800]), viridis::magma(800))))
> pal <- x(20)
> pie(rep(1, length(pal)), col=pal)
Awesome.
This is what I added in to utils.R
@grabear
Here's what I'm adding to the MicrobiomeR package:
#' @title Viridis Palette Function
#' @description A function that returns a color palette function based off of the veridis package.
#' @param viridis_number The total number of colors used to generate the viridis palette. Default: 800
#' @param viridis_range Tne range of colors in the viridis palette to use. Default: c(300, 800)
#' @param magma_number The total number of colors used to generate the magma palette. Default: 500
#' @param magma_range The range of colors in the magma palette to use. Default: c(0, 500)
#' @return The output of this function is another function, which takes a number to generate a color
#' palette as a character vector.
#' @details The primary purpose of this function is to return a palette-function for generating virdis style
#' color palettes. By taking the viridis::viridis() and the viridis::magma() colors, and manipulating
#' them, this function can help create a unique set of colors that you can distinguish on a busy plot.
#' The hopes of this function is to help improve plots that use more than 20 colors. Use the provided
#' example to view the color palette.
#' @examples
#' \dontrun{
#' if(interactive()){
#' # Use the default values
#' > pal_func <- viridis_palette_func()
#'
#' # Get a palette with 20 colors
#' > pal <- pal_func(20)
#'
#' # Make a pie plot of the colros.
#' > pie(rep(1, length(pal)), col=pal)
#' }
#' }
#' @export
#' @family Color Palettes
#' @rdname virdis_palette_func
#' @seealso
#' \code{\link[viridis]{reexports}}
#' \code{\link[MicrobiomeR]{get_color_palette}}
#' @importFrom viridis viridis magma
virdis_palette_func <- function(viridis_number=800, viridis_range=c(300,800), magma_number=500, magma_range=c(0, 500)) {
v_min = viridis_range[1]
v_max = viridis_range[2]
m_min = magma_range[1]
m_max = magma_range[2]
colorRampPalette(
unique(c(
rev(viridis::viridis(viridis_number)[v_min:v_max]), viridis::magma(magma_number)[m_min:m_max])
)
)
}
get_color_palette <- function(pal_func=virdis_palette_func, color_no=20, display=TRUE, ...) {
func_params <- list(...)
pal_func <- pal_func(func_params)
pal <- pal_func(color_no)
if (display){
pie(rep(1, length(pal)), col=pal)
}
return(pal)
}
Me likey @grabear
I'm excited to test it out. Haven't done so yet.
https://github.com/thomasp85/scico Is looking really good now too.
scico provides 17 different palettes, all of which are perceptually uniform and colourblind safe. An overview can be had with the scico_palette_show() function:
Here's a sample of the viridis function used on a stacked bar chart:
I like it. What do you think? @sdhutchins
@sdhutchins Did you do that with your new workflow?
For whatever reason, my GitHub notifications are being odd...
But yes! that's with the new workflow!!! Only those 12 phyla!!!
@sdhutchins Did you do that with your new workflow?
@grabear
I thought it would look slightly better lol In general, I love the colors, but something is throwing it off for me. I think stacked bar charts just make it harder to pick palettes.
Currently playing around
Just wrote this function in a newly created palettes.R
.
# Import Libraries
source("code/global.R")
suppressMessages(library(viridis))
suppressMessages(library(scico))
get_palettes <- function() {
viridis_palettes <- list(
eight = colorRampPalette(unique(c(rev(viridis::viridis(800)[300:800]), viridis::magma(800))))(8),
fifteen = colorRampPalette(unique(c(rev(viridis::viridis(800)[300:800]), viridis::magma(800))))(15),
twentyfive = colorRampPalette(unique(c(rev(viridis::viridis(800)[300:800]), viridis::magma(800))))(25)
)
scico_palettes <- list(eight = scico::scico(8, palette = 'batlow'),
fifteen = scico::scico(15, palette = 'batlow'),
twentyfive = scico::scico(25, palette = 'batlow'))
palettes <- list(viridis = viridis_palettes, scico = scico_palettes)
return(palettes)
}
# Get a list of a list of a list of palettes by package -----
palettes <- get_palettes()
It'll return the palettes list to the global environment for us to use.
> palettes$viridis$eight
[1] "#FDE725" "#8DD645" "#28AE7F" "#100B2E" "#5D177F" "#C63C73" "#FD9768" "#FCFDBF"
It makes it easier to just use this with scale_fill_manual(values = palettes$viridis$eight)
Kind of interesting..this is the scico palette "batlow"
I still like spectral from the RColorBrewer
package
Using the dichromat package
dichromat::colorschemes$Categorical.12
I kind of like this one...
It was generated via ggthemes
pal <- ggthemes::tableau_color_pal(palette = "Classic Cyclic", type = "regular")(12)
Did you decide on one?
Did you decide on one?
...No...
:cry:
Use paletter to generate palettes from a figure (particularly heat trees) to ensure that colors are similar across plots.
Install paletter
The file should be in jpeg format :exclamation:
:exclamation: Update
paletter
wouldn't run the above code on my machine. Everything froze.