重置每个面GGR中的颜色
我有三个变量的频率计数,并希望在饼图中显示频率计数。我尝试了ggplot并使用了以下代码:重置每个面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
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')
行,这样绘图实际上看起来就像您绘制的一样。添加另一列。将因子级别指定给这些。将其用于填充
美学。