Luca Monno
Luca Monno

Reputation: 880

combining geom_area with factor x axis

I have a plot with factorial x axis (not convertible in value ) and I'd like to plot a stacked area chart

set.seed(1)
df <- data.frame(x = rep(paste0(letters,formatC(1:26, width=2, flag="0")),2),
                 y = rep(runif(26)+1:26,2),
                 z = c(rep("a",26),rep("b",26)))

df %>% ggplot(aes(x= x, y=y)) + 
  geom_area(aes(colour = z, fill = z))

what I get is a bar chart: enter image description here

All the solution I have found to this problem involve a conversion of the x axis value (for example here)

Is there any other way to obtain a stacked chart area with factorial axis? How can I hide the first area ("b")?

Thank you very much

Upvotes: 4

Views: 1666

Answers (1)

cirofdo
cirofdo

Reputation: 1074

Do it like this:

df %>% ggplot(aes(x= x, y=y)) + 
  geom_area(aes(colour = z, group=z, fill = z))

Upvotes: 3

Related Questions