rdataframegraphstacked-area-chart

Stacked area chart only display dot (R)


I m trying to make a stacked area chart, but my chart is not 'fill', instead there is just dots.

My output:

enter image description here

My code:

library(ggplot2)

ggplot(df, aes(x=avg_time, y=value, fill=Attrition)) + 
    geom_area()

My dataframe :

             avg_time    Attrition    value
              <dbl>        <chr>       <dbl>
 1            7.4            No          1  
 2            7.7           Yes          1  
 3            7.0            No          1  
 4            7.2            No          1  
 5            8.0            No          1

Sample of my dataframe:

df <- data.frame(structure(list(avg = c(7.4, 7.7, 7, 7.2, 8, 11, 6.9, 6.7, 7.2, 
7.1, 8.4, 7.1, 9.3, 9.4, 6.1, 6.7, 6.6, 11, 7, 9.3, 7.6, 6, 8.4, 
6.8, 7.1), Attrition = c("No", "Yes", "No", "No", "No", "No", 
"Yes", "No", "No", "No", "No", "No", "No", "Yes", "No", "No", 
"No", "No", "No", "No", "No", "No", "No", "No", "No"), value = c(1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1)), row.names = c(NA, 25L), class = "data.frame"))

Solution

  • Thanks to the solution of @stefan:

    ggplot(df_graph, aes(x=avg, y=value, fill=Attrition)) + 
        stat_summary(fun = "sum", geom = "area", position = "stack")
    

    enter image description here