Ответ 1
Вы можете поместить cat
по оси x и использовать facet_grid
с помощью year
:
ggplot() +
geom_bar(data=test, aes(y = value, x = cat, fill = cond), stat="identity",
position='stack') +
theme_bw() +
facet_grid( ~ year)
У меня есть следующий график
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()
и мне нужно разделить каждый "кот" на "cond" (true или false). Как это сделать?
Вы можете поместить cat
по оси x и использовать facet_grid
с помощью year
:
ggplot() +
geom_bar(data=test, aes(y = value, x = cat, fill = cond), stat="identity",
position='stack') +
theme_bw() +
facet_grid( ~ year)