分组条形图中的堆叠条形图 [英] stacked bars within grouped bar chart

查看:50
本文介绍了分组条形图中的堆叠条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下图表

test <- expand.grid('cat' = LETTERS[1:5], 'cond'= c(F,T), 'year' = 2001:2005)
test$value <- floor((rnorm(nrow(test)))*100)
test$value[test$value < 0] <- 0

ggplot() +
  geom_bar(data=test, aes(y = value, x = year, fill = cat), stat="identity",position='dodge') +
  theme_bw()

我需要将每只猫"除以条件"(真或假).我该怎么做?

and I need to divide each 'cat' by 'cond'(true or false). How do I do that?

推荐答案

您可以将 cat 放在 x 轴上,并使用 facet_gridyear:

You can put cat on the x-axis and use facet_grid with year:

ggplot() +
  geom_bar(data=test, aes(y = value, x = cat, fill = cond), stat="identity",
           position='stack') +
  theme_bw() + 
  facet_grid( ~ year)

这篇关于分组条形图中的堆叠条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆