# Grouped AND Stacked Barplot

**URL:** <https://community.plotly.com/t/grouped-and-stacked-barplot/6834>\
**Category:** Plotly R\
**Created:** [November 15, 2017, 4:28pm UTC](https://community.plotly.com/t/grouped-and-stacked-barplot/6834 "2017-11-15T16:28:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![flachboard](https://avatars.discourse-cdn.com/v4/letter/f/b5ac83/32.png) [@flachboard](https://community.plotly.com/u/flachboard)\
**Post date:** [November 15, 2017, 4:28pm UTC](https://community.plotly.com/t/grouped-and-stacked-barplot/6834/1 "2017-11-15T16:28:38Z")

</div>

Hello, I know this was asked in the past. Is plotly still not able to do a Grouped AND Stacked Barplot similar to the solution here: [https://stackoverflow.com/questions/45055661/combine-grouped-and-stacked-bar-graph-in-r](https://stackoverflow.com/questions/45055661/combine-grouped-and-stacked-bar-graph-in-r)?

---

<div class="post-metadata">

**Author:** ![gcmicah](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/gcmicah/32/2650_2.png) [@gcmicah](https://community.plotly.com/u/gcmicah)\
**Post date:** [February 26, 2018, 6:13am UTC](https://community.plotly.com/t/grouped-and-stacked-barplot/6834/2 "2018-02-26T06:13:19Z")

</div>

hello, you can. see my post here: [Stacked bar chart - specify color platte for a column](https://community.plotly.com/t/stacked-bar-chart-specify-color-platte-for-a-column/8601)  
my question is about how to change color platte. if you know, please help. thanks.

---

<div class="post-metadata">

**Author:** ![bcd](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bcd](https://community.plotly.com/u/bcd)\
**Post date:** [March 6, 2018, 12:27pm UTC](https://community.plotly.com/t/grouped-and-stacked-barplot/6834/3 "2018-03-06T12:27:22Z")

</div>

Hey @flachboard and @gcmicah

continuing from [Stacked bar chart - specify color platte for a column](https://community.plotly.com/t/stacked-bar-chart-specify-color-platte-for-a-column/8601) couldn’t you just use subplots with `sharedY = T`. Something like:

```
grp <- c("A","B","C","D")
xval <- as.factor(c("x","y","x","y"))
frame <- merge(grp, xval, all=T)
yval <- as.factor(c('low', 'low-medium', 'medim-high', 'high'))
df <- tbl_df(cbind(frame, yval))
colnames(df) <- c("category", "Type", "Range")

p <- df %>% 
  group_by(category) %>% 
  arrange(Type) %>%
  plot_ly(
    x = ~Type, 
    y = ~Range, 
    color= ~category,
    colors = 'Reds',
    type = 'bar',
    legendgroup = "A")

pp <- df %>% 
  group_by(category) %>% 
  arrange(Type) %>%
  plot_ly(
    x = ~Type, 
    y = ~Range, 
    color= ~category,
    colors = 'Reds',
    type = 'bar',
    legendgroup = "A",
    showlegend=F)

subplot(p,pp,shareY = T) %>% layout(barmode = 'stack')
```

---

<div class="post-metadata">

**Author:** ![paulovieira](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/paulovieira/32/4127_2.png) [@paulovieira](https://community.plotly.com/u/paulovieira)\
**Post date:** [September 12, 2018, 2:29pm UTC](https://community.plotly.com/t/grouped-and-stacked-barplot/6834/4 "2018-09-12T14:29:56Z")

</div>

Yes, it is possible to make a stacked+grouped bar plot. But the “grouped” has to be done via subplots. More details here:

> [@Combination of grouped and stacked bar chart](https://community.plotly.com/t/combination-of-grouped-and-stacked-bar-chart/2154/6):
>
> It is possible to create stacked+grouped charts using subplots, see [https://github.com/plotly/plotly.js/issues/1835](https://github.com/plotly/plotly.js/issues/1835) for an example
