Special Stacked Bar Chart R ggplot

Shehroz Malik

Can you help me make the following bar chart in R? I have some simplified dummy data that i am using to recreate, and then my plan is to manipulate the data in the same way. No need to do the abline. The most important parts are the waterfall aspect.

   ï..labels value
1      start   100
2   january    120
3    febuary   140
4      march   160
5      april   180
6        may   130
7       june   140
8       july   170
9     august   160
10 september   180
11   october   190
12  november   210
13  december   200
14       end   200

enter image description here

cardinal40

This gets you the waterfall effect:

library(tidyverse)

df <- 
  tibble::tribble(
    ~month, ~month_name, ~value,
     1,     "start", 100,
     2,   "january", 120,
     3,   "febuary", 140,
     4,     "march", 160,
     5,     "april", 180,
     6,       "may", 130,
     7,      "june", 140,
     8,      "july", 170,
     9,    "august", 160,
    10, "september", 180,
    11,   "october", 190,
    12,  "november", 210,
    13,  "december", 200,
    14,       "end", 200
  ) %>% 
  mutate(
    type = case_when(
      month == min(month) ~ "Initial",
      month == max(month) ~ "Final",
      value > lag(value) ~ "Increase",
      TRUE ~ "Decrease"
    ),
    finish = value,
    start = if_else(month == max(month), 0, replace_na(lag(value), 0))
  )

df %>% 
  ggplot(aes(xmin = month - 0.3, xmax = month + 0.3, ymin = start, ymax = finish, fill = type)) +
  geom_rect() +
  scale_x_continuous(
    breaks = 1:14,
    labels = df %>% select(month_name) %>% pull()
  ) +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    legend.position = "none"
  )

You should be able to take care of the formatting and colors from here ;)

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Creating a Stacked Percentage Bar Chart in R with ggplot

R ggplot labels on stacked bar chart

Create Stacked "Progress" Bar Chart in R with ggplot

R ggplot Sort Percent Stacked Bar Chart

How to create a stacked bar chart in r with ggplot

How to change the position of stacked stacked bar chart in ggplot in R?

Making a stacked bar chart with ggplot

R: ggplot stacked bar chart with counts on y axis but percentage as label

Python (matplotlib) equivalent of stacked bar chart in R (ggplot)

How to created a grouped and stacked bar chart in R with ggplot2

Stacked Bar Chart in R using ggplot2 (not possible in excel)

R, ggplot stacked bar-chart with position = "fill" and labels

Stacked bar chart with side-by-side in R ggplot

Creating a Stacked Percentage Bar Chart in R with ggplot with labels

creating stacked bar chart in r

Arranging Stacked Bar Chart in R

How to plot a Stacked and grouped bar chart in ggplot?

Grouping legend of ggplot for stacked bar chart

ggplot with stacked bar chart ordered by a separate variable

Advanced stacked bar chart ggplot2

Horizontal stacked bar chart with a separate element in ggplot

Stacked bar chart with varying widths in ggplot

Transform a ggplot stacked bar into pie chart or alternative

ggplot Stacked Bar Chart with Alpha Differences within Each Stacked Category

R studio - stacked bar chart in R

ggplot - dual line chart and stacked bar chart on one plot

R Create stacked bar chart from non-numerical data using ggplot2

How do I make stacked bar chart in specific order in ggplot/R while maintaining a specific color scheme?

How to change the x-axis ticks in a facet-wrapt stacked bar chart--ggplot R