hrbrmstr / waffle

:maple_leaf: Make waffle (square pie) charts in R
770 stars 95 forks source link

colors are not continuous. #32

Open Sanrrone opened 7 years ago

Sanrrone commented 7 years ago

Hi, When the are several categories, the little squares loss their color continuity, hindering the analyze step, the code is:

library(RColorBrewer)
library(waffle)
cl <- colors(distinct = TRUE)
set.seed(15887) # to set random generator seed
kolor <- sample(cl, 25)

waffle(c("organophosphate catabolic process"=8,"transition metal ion transport"=7,"multi-organism cellular process"=6,"growth"=6,"cellular biogenic amine biosynthetic process"=6,"protein maturation"=6,"indole-containing compound metabolic process"=6,"reactive oxygen species metabolic process"=5,"pyrimidine nucleobase metabolic process"=5,"carbohydrate phosphorylation"=4,"negative regulation of hydrolase activity"=4,"carbohydrate derivative transport"=4,"glutamate metabolic process"=4,"indole-containing compound biosynthetic process"=3,"protein oligomerization"=3,"regulation of cellular component movement"=3,"organophosphate ester transport"=3,"(obsolete) ATP catabolic process"=3,"response to acid chemical"=2,"hydrogen peroxide metabolic process"=2,"lipid oxidation"=2,"glycosyl compound catabolic process"=2,"positive regulation of translation"=2,"protein autophosphorylation"=2,"dicarboxylic acid transport"=2), 
       title = "Biological Proccess",
       colors = kolor

is there an solution ?, I attach the pdf regards

biologicalP.pdf )

hrbrmstr commented 7 years ago

First, your code is not reproducible. It errors out on my system.

waffle charts are a pie chart alternative and are designed to visualize counts of a small number of discrete categories (just like pie charts should be).

having said that, if you specify the proper # of colors you get what you want:

c("organophosphate catabolic process"=8, "transition metal ion transport"=7,
         "multi-organism cellular process"=6,"growth"=6,
         "cellular biogenic amine biosynthetic process"=6,
         "protein maturation"=6,"indole-containing compound metabolic process"=6,
         "reactive oxygen species metabolic process"=5,
         "pyrimidine nucleobase metabolic process"=5,"carbohydrate phosphorylation"=4,
         "negative regulation of hydrolase activity"=4,
         "carbohydrate derivative transport"=4,"glutamate metabolic process"=4,
         "indole-containing compound biosynthetic process"=3,"protein oligomerization"=3,
         "regulation of cellular component movement"=3,"organophosphate ester transport"=3,
         "(obsolete) ATP catabolic process"=3,"response to acid chemical"=2,
         "hydrogen peroxide metabolic process"=2,"lipid oxidation"=2,
         "glycosyl compound catabolic process"=2,"positive regulation of translation"=2,
         "protein autophosphorylation"=2,"dicarboxylic acid transport"=2) -> processes

waffle(parts = processes, 
       title = "Biological Proccess", 
       colors = viridis::viridis_pal()(25))

image

With 25 colors, nobody is going to be able to keep track of the color-to-entity relationship. That's a big reason Color Brewer palettes top out at 12 (and only a few of them). This is visual jibberish:

waffle(parts = processes, 
       title = "Biological Proccess", 
       colors = {set.seed(1492); unname(randomcoloR::distinctColorPalette(25))})

image

as is:

waffle(parts = processes, 
       title = "Biological Proccess", 
       colors = c(brewer.pal(8, "Accent"), brewer.pal(8, "Dark2"), brewer.pal(9, "Set1")))

image

I'd consider re-thinking what you're trying to communicate.

Sanrrone commented 7 years ago

thanks for the quick support!, you are right the colors are 8 but I need 25 (edited in first comment), although the pdf was made with 25 distinct colors (gradients are nice but a little useless to explain gene onthology terms), to communicate that i want to communicate, I need the colors be continuous, in this example, "transition metal ion transport" (second category), is "splited" by "organophosphate catabolic process" (first category) and "multi-organism cellular process" (third category). sure this is true looking from top to bottom, is there a way to transpose the waffle and get the colors begin top to right? or top to bottom and not bottom to top?. regards