Is there a way to make a clustered stacked bar chart in R?
Currently I have 2 stacked bar charts that look like this:
(sorry for the links, I'm not yet able to post images to a question)
Stacked bar chart 1
Stacked bar chart 2
And my data looks something like this:
|state|A1|B1|C1|D1|E1|A2|B2|C2|D2
|AL| | 3| 2| 4|12| 2| 2| 8| 1| 6|
|AK| | 2| 4|22| 6| 4| 4|12| 2| 3|
|AZ| | 2| 1| 5| 5|45| 6| 2| 4|95|
|CA| | 3| 9|11| 3|12| 7| 1| 5|25|
Using this data, is there a way to have a clustered stacked bar chart, so that the 2nd values are next to the 1st values for each state?
So far I've used plotly to make these graphs, and my code looks like this:
p1 <- plot_ly(data=df, x = ~state, y = ~E1, type = 'bar', name = 'E1') %>%
add_trace(y = ~D1, name = 'D1') %>%
add_trace(y = ~C1, name = 'C1') %>%
add_trace(y = ~B1, name = 'B1') %>%
add_trace(y = ~A1, name = 'A1') %>%
layout(yaxis = list(title = ''), barmode = 'stack')
p1
Edit:
I would want the final graph to look something like this: Chart Example
However for each state in the U.S