ggplot2/colorbrewer定性托盘,共125个类别

ggplot2/colorbrewer定性托盘,共125个类别,r,ggplot2,colorbrewer,R,Ggplot2,Colorbrewer,我有以下资料: 10个州 每个州有两种类型 每种类型有1到29个实体 每个状态实体类型都有一个计数 完整的数据 我试图想象每个实体的计数比例。为此,我使用了以下代码: icc <- transform( icc, state=factor(state), entity=factor(entity), type=factor(type) ) p <- ggplot( icc, aes( x=state, y=count, fill=entity ) ) + geom_bar(

我有以下资料:

  • 10个州
  • 每个州有两种类型
  • 每种类型有1到29个实体
  • 每个状态实体类型都有一个计数
完整的数据

我试图想象每个实体的计数比例。为此,我使用了以下代码:

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

icc这里有一种方法可以为您提供更多的信息。将彩虹生成的色轮
,与色轮上的另一种颜色交换其他颜色

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

col@Arun用一个很好的发散方案制作这样一个托盘是不平凡的(可能是一个很好的答案,wink-wink)。需要在每种状态类型的实体上运行一个颜色冲泡器(本身就有问题,因为大多数托盘似乎阻塞了超过12个),然后按正确的顺序排列。很难想出29种不同的颜色。哈德利指出,为什么不直接用文本标记实体呢。文本会很好,但最终可能会变得一团糟。我想我的要求实际上要简单得多:颜色甚至不必在状态类型中是唯一的,只是交替。我可以尝试一些类似于
scale\u fill\u manual(值=c(rep(c('red','blue'),125/2),'red'))
,但不能保证它们在每个条内交替。您可能可以使用
alternate创建一个新变量