Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重置每个面GGR中的颜色_R_Ggplot2 - Fatal编程技术网

重置每个面GGR中的颜色

重置每个面GGR中的颜色,r,ggplot2,R,Ggplot2,我有三个变量的频率计数,并希望在饼图中显示频率计数。我尝试了ggplot并使用了以下代码: library(ggplot2) df = data.frame(var = rep(c('a','b','c'),each = 3), class = letters[1:9], count = rep(1:3, 3)) ggplot(df, aes(x = '', y = count, fill = class)) + geom_bar(widt

我有三个变量的频率计数,并希望在饼图中显示频率计数。我尝试了ggplot并使用了以下代码:

library(ggplot2)
df = data.frame(var = rep(c('a','b','c'),each = 3),
            class = letters[1:9],
            count = rep(1:3, 3))

ggplot(df, aes(x = '', y = count, fill = class)) + 
  geom_bar(width = 0.5, stat = 'identity') + 
  coord_polar('y', start = 10) + facet_wrap(~var) + 
  theme(legend.position = 'none')
我得到了以下图表:

但是,我想要这样的东西:


如何重置每个面板中的颜色?

您必须在每个方面引入一个相同的虚拟变量:

df = data.frame(var = rep(c('a','b','c'),each = 3),
                class = letters[1:9],
                dummy = rep(letters[1:3], 3),
                count = rep(1:3, 3))

ggplot(df, aes(x = '', y = count, fill = dummy)) + 
  geom_bar(width = 0.5, stat = 'identity') + 
  coord_polar('y', start = 10) + facet_wrap(~var)


我删除了
主题(legend.position='none')
行,这样绘图实际上看起来就像您绘制的一样。

添加另一列。将因子级别指定给这些。将其用于
填充
美学。