Ggplot2 / colorbrewer quality palette with 125 categories

I have the following data:

  • 10 states
  • Each state has two types
  • Each type has from 1 to 29 objects
  • Each type of state object has a counter

Full data is available as an entity .

I am trying to imagine what proportion of the calculations were made for each object. For this, I used the following code:

icc <- transform( icc, state=factor(state), entity=factor(entity), type=factor(type) ) p <- ggplot( icc, aes( x=state, y=count, fill=entity ) ) + geom_bar( stat="identity", position="stack" ) + facet_grid( type ~ . ) custom_theme <- theme_update(legend.position="none") p 

plot

Unfortunately, I am losing a lot of information because state types with a large number of objects do not display enough unique colors.

As mentioned above, I have 125 objects, but most of the objects in type state are 29. Is there a way to get ggplot2 and colorbrewer to assign a unique (and hopefully fairly clear) color to each entity type?

The only way I came across is to force the entity to an integer that works, but does not provide significant color differentiation between levels.

+6
source share
1 answer

Here is an approach that gives you a little more information. Take the color wheel created with rainbow , and for any other color, replace it with the opposite on the wheel.

 col <- rainbow(30) col.index <- ifelse(seq(col) %% 2, seq(col), (seq(ceiling(length(col)/2), length.out=length(col)) %% length(col)) + 1) mixed <- col[col.index] p <- ggplot(icc, aes(x=state, y=count, fill=entity)) + geom_bar(stat="identity", position="stack") + facet_grid( type ~ . ) + scale_fill_manual(values=rep(mixed, length.out=nrow(icc))) custom_theme <- theme_update(legend.position='none') p 

enter image description here

+6
source

All Articles