I thought this was a simple syntax, but my code would not stack bars.
data.frame(x = c('a', 'b', 'c'),
y = c(.549, .051, .4)) %>%
ggplot(aes(x = x, y = y)) +
geom_col(position = 'stack')
I also tried position = position_stack(), but it still shows position dodge.
What am I doing wrong?
Try this instead:
data.frame(x = c(1,1,1),
grp = c('a', 'b', 'c'),
y = c(.549, .051, .4)) %>%
ggplot(aes(x = x, y = y,fill = grp)) +
geom_col(position = 'stack')
Stacking requires a third variable beyond x & y.