How to plot this group bar plot?How to control the layering of graphics displayed with ShowBarChart with relative abundances as chart labelsBarChart: plotting bars at given positionsHow do I animate a bar chart?Color coded bar to represent numeric valuesFormatting bar charts: size and ticksBarChart3d not working as expectedHow to draw two error bars at one point in Mathematica?Is that possible to adjust the bar legend size in GraphicsGrid or DensityPlot automatically?Plotting ListStepPlot with error bar

Is there a logarithm base for which the logarithm becomes an identity function?

Sort array by month and year

How can I portion out frozen cookie dough?

Paper published similar to PhD thesis

Insult for someone who "doesn't know anything"

School performs periodic password audits. Is my password compromised?

What is the oldest European royal house?

Is it appropriate to ask a former professor to order a library book for me through ILL?

Rationale to prefer local variables over instance variables?

Professor forcing me to attend a conference, I can't afford even with 50% funding

Who has more? Ireland or Iceland?

Should we avoid writing fiction about historical events without extensive research?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

What exactly is the meaning of "fine wine"?

Create chunks from an array

Giving a talk in my old university, how prominently should I tell students my salary?

Mixed Feelings - What am I

Can I negotiate a patent idea for a raise, under French law?

Tabular environment - text vertically positions itself by bottom of tikz picture in adjacent cell

How to recover against Snake as a heavyweight character?

How can I have x-axis ticks that show ticks scaled in powers of ten?

An Undercover Army

How to distinguish easily different soldier of ww2?

How to install "rounded" brake pads



How to plot this group bar plot?


How to control the layering of graphics displayed with ShowBarChart with relative abundances as chart labelsBarChart: plotting bars at given positionsHow do I animate a bar chart?Color coded bar to represent numeric valuesFormatting bar charts: size and ticksBarChart3d not working as expectedHow to draw two error bars at one point in Mathematica?Is that possible to adjust the bar legend size in GraphicsGrid or DensityPlot automatically?Plotting ListStepPlot with error bar













2












$begingroup$


enter image description here



I want to generate a barplot with the following characteristics.



There are 5 users in the system. Each user has a demand.
There are 2 suppliers.
Each supplier tries to meet user demand as closely as possible.
One supplier may perform better than the other supplier.



I want a grouped barplot.



There will be two bars for each user (demand and supply)
The supply bar should combine the supplies from two supplies in such a way that the



For example,



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;


I just want to combine Supply1 and Supply2 in one bar. So, there will only five supply bars. The demand bars and the supply bars are then grouped as shown in the attached figure.



It is like putting one supply bar above another but both should be visible. The shorter one will always on top so that both are visible.



But the problem I have with this plot is that for the last group, I cannot see the red bar, which is somehow hidden below the purple bar.



This one I obtained with MATLAB. I hope Mathematica can help me with what I need.










share|improve this question











$endgroup$











  • $begingroup$
    What have you tried so far using BarChart?
    $endgroup$
    – MarcoB
    14 hours ago










  • $begingroup$
    @kglr, this is not what I want. I have revised my question...
    $endgroup$
    – dipak narayanan
    13 hours ago










  • $begingroup$
    try adding the option ChartBaseStyle -> Opacity[.5]?
    $endgroup$
    – kglr
    12 hours ago






  • 2




    $begingroup$
    I'm voting to close this question as off-topic because the OP is asking for the impossible, despite reasonable suggestions. Furthermore, any solution will be extremely localized to their problem only.
    $endgroup$
    – MarcoB
    12 hours ago






  • 1




    $begingroup$
    I'm voting to close this question as off-topic because overloading bar charts makes for unintelligible displays. If there are two objectives for displaying data, then (despite objections from publishers) maybe two separate displays are needed.
    $endgroup$
    – JimB
    8 hours ago















2












$begingroup$


enter image description here



I want to generate a barplot with the following characteristics.



There are 5 users in the system. Each user has a demand.
There are 2 suppliers.
Each supplier tries to meet user demand as closely as possible.
One supplier may perform better than the other supplier.



I want a grouped barplot.



There will be two bars for each user (demand and supply)
The supply bar should combine the supplies from two supplies in such a way that the



For example,



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;


I just want to combine Supply1 and Supply2 in one bar. So, there will only five supply bars. The demand bars and the supply bars are then grouped as shown in the attached figure.



It is like putting one supply bar above another but both should be visible. The shorter one will always on top so that both are visible.



But the problem I have with this plot is that for the last group, I cannot see the red bar, which is somehow hidden below the purple bar.



This one I obtained with MATLAB. I hope Mathematica can help me with what I need.










share|improve this question











$endgroup$











  • $begingroup$
    What have you tried so far using BarChart?
    $endgroup$
    – MarcoB
    14 hours ago










  • $begingroup$
    @kglr, this is not what I want. I have revised my question...
    $endgroup$
    – dipak narayanan
    13 hours ago










  • $begingroup$
    try adding the option ChartBaseStyle -> Opacity[.5]?
    $endgroup$
    – kglr
    12 hours ago






  • 2




    $begingroup$
    I'm voting to close this question as off-topic because the OP is asking for the impossible, despite reasonable suggestions. Furthermore, any solution will be extremely localized to their problem only.
    $endgroup$
    – MarcoB
    12 hours ago






  • 1




    $begingroup$
    I'm voting to close this question as off-topic because overloading bar charts makes for unintelligible displays. If there are two objectives for displaying data, then (despite objections from publishers) maybe two separate displays are needed.
    $endgroup$
    – JimB
    8 hours ago













2












2








2


1



$begingroup$


enter image description here



I want to generate a barplot with the following characteristics.



There are 5 users in the system. Each user has a demand.
There are 2 suppliers.
Each supplier tries to meet user demand as closely as possible.
One supplier may perform better than the other supplier.



I want a grouped barplot.



There will be two bars for each user (demand and supply)
The supply bar should combine the supplies from two supplies in such a way that the



For example,



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;


I just want to combine Supply1 and Supply2 in one bar. So, there will only five supply bars. The demand bars and the supply bars are then grouped as shown in the attached figure.



It is like putting one supply bar above another but both should be visible. The shorter one will always on top so that both are visible.



But the problem I have with this plot is that for the last group, I cannot see the red bar, which is somehow hidden below the purple bar.



This one I obtained with MATLAB. I hope Mathematica can help me with what I need.










share|improve this question











$endgroup$




enter image description here



I want to generate a barplot with the following characteristics.



There are 5 users in the system. Each user has a demand.
There are 2 suppliers.
Each supplier tries to meet user demand as closely as possible.
One supplier may perform better than the other supplier.



I want a grouped barplot.



There will be two bars for each user (demand and supply)
The supply bar should combine the supplies from two supplies in such a way that the



For example,



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;


I just want to combine Supply1 and Supply2 in one bar. So, there will only five supply bars. The demand bars and the supply bars are then grouped as shown in the attached figure.



It is like putting one supply bar above another but both should be visible. The shorter one will always on top so that both are visible.



But the problem I have with this plot is that for the last group, I cannot see the red bar, which is somehow hidden below the purple bar.



This one I obtained with MATLAB. I hope Mathematica can help me with what I need.







plotting graphics charts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 12 hours ago









MarcoB

37.2k556113




37.2k556113










asked 14 hours ago









dipak narayanandipak narayanan

1266




1266











  • $begingroup$
    What have you tried so far using BarChart?
    $endgroup$
    – MarcoB
    14 hours ago










  • $begingroup$
    @kglr, this is not what I want. I have revised my question...
    $endgroup$
    – dipak narayanan
    13 hours ago










  • $begingroup$
    try adding the option ChartBaseStyle -> Opacity[.5]?
    $endgroup$
    – kglr
    12 hours ago






  • 2




    $begingroup$
    I'm voting to close this question as off-topic because the OP is asking for the impossible, despite reasonable suggestions. Furthermore, any solution will be extremely localized to their problem only.
    $endgroup$
    – MarcoB
    12 hours ago






  • 1




    $begingroup$
    I'm voting to close this question as off-topic because overloading bar charts makes for unintelligible displays. If there are two objectives for displaying data, then (despite objections from publishers) maybe two separate displays are needed.
    $endgroup$
    – JimB
    8 hours ago
















  • $begingroup$
    What have you tried so far using BarChart?
    $endgroup$
    – MarcoB
    14 hours ago










  • $begingroup$
    @kglr, this is not what I want. I have revised my question...
    $endgroup$
    – dipak narayanan
    13 hours ago










  • $begingroup$
    try adding the option ChartBaseStyle -> Opacity[.5]?
    $endgroup$
    – kglr
    12 hours ago






  • 2




    $begingroup$
    I'm voting to close this question as off-topic because the OP is asking for the impossible, despite reasonable suggestions. Furthermore, any solution will be extremely localized to their problem only.
    $endgroup$
    – MarcoB
    12 hours ago






  • 1




    $begingroup$
    I'm voting to close this question as off-topic because overloading bar charts makes for unintelligible displays. If there are two objectives for displaying data, then (despite objections from publishers) maybe two separate displays are needed.
    $endgroup$
    – JimB
    8 hours ago















$begingroup$
What have you tried so far using BarChart?
$endgroup$
– MarcoB
14 hours ago




$begingroup$
What have you tried so far using BarChart?
$endgroup$
– MarcoB
14 hours ago












$begingroup$
@kglr, this is not what I want. I have revised my question...
$endgroup$
– dipak narayanan
13 hours ago




$begingroup$
@kglr, this is not what I want. I have revised my question...
$endgroup$
– dipak narayanan
13 hours ago












$begingroup$
try adding the option ChartBaseStyle -> Opacity[.5]?
$endgroup$
– kglr
12 hours ago




$begingroup$
try adding the option ChartBaseStyle -> Opacity[.5]?
$endgroup$
– kglr
12 hours ago




2




2




$begingroup$
I'm voting to close this question as off-topic because the OP is asking for the impossible, despite reasonable suggestions. Furthermore, any solution will be extremely localized to their problem only.
$endgroup$
– MarcoB
12 hours ago




$begingroup$
I'm voting to close this question as off-topic because the OP is asking for the impossible, despite reasonable suggestions. Furthermore, any solution will be extremely localized to their problem only.
$endgroup$
– MarcoB
12 hours ago




1




1




$begingroup$
I'm voting to close this question as off-topic because overloading bar charts makes for unintelligible displays. If there are two objectives for displaying data, then (despite objections from publishers) maybe two separate displays are needed.
$endgroup$
– JimB
8 hours ago




$begingroup$
I'm voting to close this question as off-topic because overloading bar charts makes for unintelligible displays. If there are two objectives for displaying data, then (despite objections from publishers) maybe two separate displays are needed.
$endgroup$
– JimB
8 hours ago










2 Answers
2






active

oldest

votes


















2












$begingroup$

Update 2: A better approach to pre-processing is to use two separate BarCharts` (as in m_goldberg's answer):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
sb = SortBy[#, -First[#] &] & /@ s;

b1 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,1]]],
ChartLabels -> Placed["Group " <> ToString[#] & /@ Range[5], Axis],
Placed["D", "S", Axis],
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"]];

b2 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,2]]]];

Show[b1, b2]


enter image description here



Update: An alternative, more convenient and better, approach is to pre-process data to reorder based on heights:



sb = SortBy[#, -First[#] &] & /@ s;
datab = Join @@ Thread[0, 0, 0, 0, 0, d, sb];

bcb = BarChart[datab, ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1]


enter image description here



With this approach we don't need to add PerformanceGoal -> "Speed", thus we retain all the tool-tips and and dynamic highlighting.



Original answer:



BarChart does not support mixed layouts (it does not allow combining Grouped and Overlapped layouts). So, we cheat by inserting fake data sets with 0 height betweeen groups to separate the five groups and, to make all rectangles visible, we post-process to re-order the yellow and blue rectangles based on their heights (I added PerformanceGoal -> "Speed" above to make this post-processing easier):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
d = Thread[Style[#, Red] & /@ demand, Style[0, Opacity[0]]];
data = Join @@ Thread[0, 0, 0, 0, 0, d, s];

bc = BarChart[data,
ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1, PerformanceGoal -> "Speed"];


enter image description here



bc /. pattern : _, Rectangle[_, _, _, h1_, ___], _, 
Rectangle[_, _, _, h2_, ___] :> If[h2 <= h1, pattern, Reverse[pattern]]


enter image description here



Fixing ticks and labels is an altogether different challenge.






share|improve this answer











$endgroup$












  • $begingroup$
    Yep, this is the kind of heroic effort that I was hinting at in my comments... Thank you for trying though. (+1)
    $endgroup$
    – MarcoB
    12 hours ago











  • $begingroup$
    thank you @MarcoB.
    $endgroup$
    – kglr
    12 hours ago


















4












$begingroup$

This will reproduce your matlab generated chart.



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;

b1 = BarChart[Transpose[Demand, Supply2],
ChartStyle -> Automatic, Automatic, Red];
b2 = BarChart[Transpose[Demand, Supply1]];

Show[b1, b2, Frame -> True]


chart



It has the same defect as the matlab chart — the longer blue bar at the right end of chart hides the shorter red bar behind it.






share|improve this answer











$endgroup$












  • $begingroup$
    I suppose that, if OP's purpose is simply to get the plot, one could add Supply1, Supply2 = Transpose[Sort /@ Transpose[Supply1, Supply2]] before the calls to BarChart to "swap" the offending last values from Supply1 and Supply2.
    $endgroup$
    – MarcoB
    5 hours ago











  • $begingroup$
    @MarcoB. Yes, something like that would work, but it would ruin the stark simplicity of this answer :-), which is mainly to point out that hoe easy it is to reproduce the defective matlab chart. I think kglr's answer is better than mine because it makes the chart that is really wanted in a simple way.
    $endgroup$
    – m_goldberg
    2 hours ago











Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192883%2fhow-to-plot-this-group-bar-plot%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2












$begingroup$

Update 2: A better approach to pre-processing is to use two separate BarCharts` (as in m_goldberg's answer):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
sb = SortBy[#, -First[#] &] & /@ s;

b1 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,1]]],
ChartLabels -> Placed["Group " <> ToString[#] & /@ Range[5], Axis],
Placed["D", "S", Axis],
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"]];

b2 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,2]]]];

Show[b1, b2]


enter image description here



Update: An alternative, more convenient and better, approach is to pre-process data to reorder based on heights:



sb = SortBy[#, -First[#] &] & /@ s;
datab = Join @@ Thread[0, 0, 0, 0, 0, d, sb];

bcb = BarChart[datab, ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1]


enter image description here



With this approach we don't need to add PerformanceGoal -> "Speed", thus we retain all the tool-tips and and dynamic highlighting.



Original answer:



BarChart does not support mixed layouts (it does not allow combining Grouped and Overlapped layouts). So, we cheat by inserting fake data sets with 0 height betweeen groups to separate the five groups and, to make all rectangles visible, we post-process to re-order the yellow and blue rectangles based on their heights (I added PerformanceGoal -> "Speed" above to make this post-processing easier):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
d = Thread[Style[#, Red] & /@ demand, Style[0, Opacity[0]]];
data = Join @@ Thread[0, 0, 0, 0, 0, d, s];

bc = BarChart[data,
ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1, PerformanceGoal -> "Speed"];


enter image description here



bc /. pattern : _, Rectangle[_, _, _, h1_, ___], _, 
Rectangle[_, _, _, h2_, ___] :> If[h2 <= h1, pattern, Reverse[pattern]]


enter image description here



Fixing ticks and labels is an altogether different challenge.






share|improve this answer











$endgroup$












  • $begingroup$
    Yep, this is the kind of heroic effort that I was hinting at in my comments... Thank you for trying though. (+1)
    $endgroup$
    – MarcoB
    12 hours ago











  • $begingroup$
    thank you @MarcoB.
    $endgroup$
    – kglr
    12 hours ago















2












$begingroup$

Update 2: A better approach to pre-processing is to use two separate BarCharts` (as in m_goldberg's answer):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
sb = SortBy[#, -First[#] &] & /@ s;

b1 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,1]]],
ChartLabels -> Placed["Group " <> ToString[#] & /@ Range[5], Axis],
Placed["D", "S", Axis],
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"]];

b2 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,2]]]];

Show[b1, b2]


enter image description here



Update: An alternative, more convenient and better, approach is to pre-process data to reorder based on heights:



sb = SortBy[#, -First[#] &] & /@ s;
datab = Join @@ Thread[0, 0, 0, 0, 0, d, sb];

bcb = BarChart[datab, ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1]


enter image description here



With this approach we don't need to add PerformanceGoal -> "Speed", thus we retain all the tool-tips and and dynamic highlighting.



Original answer:



BarChart does not support mixed layouts (it does not allow combining Grouped and Overlapped layouts). So, we cheat by inserting fake data sets with 0 height betweeen groups to separate the five groups and, to make all rectangles visible, we post-process to re-order the yellow and blue rectangles based on their heights (I added PerformanceGoal -> "Speed" above to make this post-processing easier):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
d = Thread[Style[#, Red] & /@ demand, Style[0, Opacity[0]]];
data = Join @@ Thread[0, 0, 0, 0, 0, d, s];

bc = BarChart[data,
ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1, PerformanceGoal -> "Speed"];


enter image description here



bc /. pattern : _, Rectangle[_, _, _, h1_, ___], _, 
Rectangle[_, _, _, h2_, ___] :> If[h2 <= h1, pattern, Reverse[pattern]]


enter image description here



Fixing ticks and labels is an altogether different challenge.






share|improve this answer











$endgroup$












  • $begingroup$
    Yep, this is the kind of heroic effort that I was hinting at in my comments... Thank you for trying though. (+1)
    $endgroup$
    – MarcoB
    12 hours ago











  • $begingroup$
    thank you @MarcoB.
    $endgroup$
    – kglr
    12 hours ago













2












2








2





$begingroup$

Update 2: A better approach to pre-processing is to use two separate BarCharts` (as in m_goldberg's answer):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
sb = SortBy[#, -First[#] &] & /@ s;

b1 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,1]]],
ChartLabels -> Placed["Group " <> ToString[#] & /@ Range[5], Axis],
Placed["D", "S", Axis],
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"]];

b2 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,2]]]];

Show[b1, b2]


enter image description here



Update: An alternative, more convenient and better, approach is to pre-process data to reorder based on heights:



sb = SortBy[#, -First[#] &] & /@ s;
datab = Join @@ Thread[0, 0, 0, 0, 0, d, sb];

bcb = BarChart[datab, ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1]


enter image description here



With this approach we don't need to add PerformanceGoal -> "Speed", thus we retain all the tool-tips and and dynamic highlighting.



Original answer:



BarChart does not support mixed layouts (it does not allow combining Grouped and Overlapped layouts). So, we cheat by inserting fake data sets with 0 height betweeen groups to separate the five groups and, to make all rectangles visible, we post-process to re-order the yellow and blue rectangles based on their heights (I added PerformanceGoal -> "Speed" above to make this post-processing easier):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
d = Thread[Style[#, Red] & /@ demand, Style[0, Opacity[0]]];
data = Join @@ Thread[0, 0, 0, 0, 0, d, s];

bc = BarChart[data,
ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1, PerformanceGoal -> "Speed"];


enter image description here



bc /. pattern : _, Rectangle[_, _, _, h1_, ___], _, 
Rectangle[_, _, _, h2_, ___] :> If[h2 <= h1, pattern, Reverse[pattern]]


enter image description here



Fixing ticks and labels is an altogether different challenge.






share|improve this answer











$endgroup$



Update 2: A better approach to pre-processing is to use two separate BarCharts` (as in m_goldberg's answer):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
sb = SortBy[#, -First[#] &] & /@ s;

b1 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,1]]],
ChartLabels -> Placed["Group " <> ToString[#] & /@ Range[5], Axis],
Placed["D", "S", Axis],
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"]];

b2 = BarChart[Transpose[Style[#, Red] & /@ demand, sb[[All,2]]]];

Show[b1, b2]


enter image description here



Update: An alternative, more convenient and better, approach is to pre-process data to reorder based on heights:



sb = SortBy[#, -First[#] &] & /@ s;
datab = Join @@ Thread[0, 0, 0, 0, 0, d, sb];

bcb = BarChart[datab, ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1]


enter image description here



With this approach we don't need to add PerformanceGoal -> "Speed", thus we retain all the tool-tips and and dynamic highlighting.



Original answer:



BarChart does not support mixed layouts (it does not allow combining Grouped and Overlapped layouts). So, we cheat by inserting fake data sets with 0 height betweeen groups to separate the five groups and, to make all rectangles visible, we post-process to re-order the yellow and blue rectangles based on their heights (I added PerformanceGoal -> "Speed" above to make this post-processing easier):



demand = 10, 15, 20, 17, 9;
supply1 = 8, 13, 18, 14, 11;
supply2 = 9, 14, 19, 16, 10;
s = Transpose[Style[#, Blue] & /@ supply1, Style[#, Yellow] & /@ supply2];
d = Thread[Style[#, Red] & /@ demand, Style[0, Opacity[0]]];
data = Join @@ Thread[0, 0, 0, 0, 0, d, s];

bc = BarChart[data,
ChartLayout -> "Overlapped",
ChartLegends -> SwatchLegend[Red, Blue, Yellow, "D", "S1", "S2"],
BarSpacing -> 0, .1, PerformanceGoal -> "Speed"];


enter image description here



bc /. pattern : _, Rectangle[_, _, _, h1_, ___], _, 
Rectangle[_, _, _, h2_, ___] :> If[h2 <= h1, pattern, Reverse[pattern]]


enter image description here



Fixing ticks and labels is an altogether different challenge.







share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 12 hours ago









kglrkglr

187k10203421




187k10203421











  • $begingroup$
    Yep, this is the kind of heroic effort that I was hinting at in my comments... Thank you for trying though. (+1)
    $endgroup$
    – MarcoB
    12 hours ago











  • $begingroup$
    thank you @MarcoB.
    $endgroup$
    – kglr
    12 hours ago
















  • $begingroup$
    Yep, this is the kind of heroic effort that I was hinting at in my comments... Thank you for trying though. (+1)
    $endgroup$
    – MarcoB
    12 hours ago











  • $begingroup$
    thank you @MarcoB.
    $endgroup$
    – kglr
    12 hours ago















$begingroup$
Yep, this is the kind of heroic effort that I was hinting at in my comments... Thank you for trying though. (+1)
$endgroup$
– MarcoB
12 hours ago





$begingroup$
Yep, this is the kind of heroic effort that I was hinting at in my comments... Thank you for trying though. (+1)
$endgroup$
– MarcoB
12 hours ago













$begingroup$
thank you @MarcoB.
$endgroup$
– kglr
12 hours ago




$begingroup$
thank you @MarcoB.
$endgroup$
– kglr
12 hours ago











4












$begingroup$

This will reproduce your matlab generated chart.



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;

b1 = BarChart[Transpose[Demand, Supply2],
ChartStyle -> Automatic, Automatic, Red];
b2 = BarChart[Transpose[Demand, Supply1]];

Show[b1, b2, Frame -> True]


chart



It has the same defect as the matlab chart — the longer blue bar at the right end of chart hides the shorter red bar behind it.






share|improve this answer











$endgroup$












  • $begingroup$
    I suppose that, if OP's purpose is simply to get the plot, one could add Supply1, Supply2 = Transpose[Sort /@ Transpose[Supply1, Supply2]] before the calls to BarChart to "swap" the offending last values from Supply1 and Supply2.
    $endgroup$
    – MarcoB
    5 hours ago











  • $begingroup$
    @MarcoB. Yes, something like that would work, but it would ruin the stark simplicity of this answer :-), which is mainly to point out that hoe easy it is to reproduce the defective matlab chart. I think kglr's answer is better than mine because it makes the chart that is really wanted in a simple way.
    $endgroup$
    – m_goldberg
    2 hours ago
















4












$begingroup$

This will reproduce your matlab generated chart.



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;

b1 = BarChart[Transpose[Demand, Supply2],
ChartStyle -> Automatic, Automatic, Red];
b2 = BarChart[Transpose[Demand, Supply1]];

Show[b1, b2, Frame -> True]


chart



It has the same defect as the matlab chart — the longer blue bar at the right end of chart hides the shorter red bar behind it.






share|improve this answer











$endgroup$












  • $begingroup$
    I suppose that, if OP's purpose is simply to get the plot, one could add Supply1, Supply2 = Transpose[Sort /@ Transpose[Supply1, Supply2]] before the calls to BarChart to "swap" the offending last values from Supply1 and Supply2.
    $endgroup$
    – MarcoB
    5 hours ago











  • $begingroup$
    @MarcoB. Yes, something like that would work, but it would ruin the stark simplicity of this answer :-), which is mainly to point out that hoe easy it is to reproduce the defective matlab chart. I think kglr's answer is better than mine because it makes the chart that is really wanted in a simple way.
    $endgroup$
    – m_goldberg
    2 hours ago














4












4








4





$begingroup$

This will reproduce your matlab generated chart.



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;

b1 = BarChart[Transpose[Demand, Supply2],
ChartStyle -> Automatic, Automatic, Red];
b2 = BarChart[Transpose[Demand, Supply1]];

Show[b1, b2, Frame -> True]


chart



It has the same defect as the matlab chart — the longer blue bar at the right end of chart hides the shorter red bar behind it.






share|improve this answer











$endgroup$



This will reproduce your matlab generated chart.



Demand = 10, 15, 20, 17, 9;
Supply1 = 8, 13, 18, 14, 11;
Supply2 = 9, 14, 19, 16, 10;

b1 = BarChart[Transpose[Demand, Supply2],
ChartStyle -> Automatic, Automatic, Red];
b2 = BarChart[Transpose[Demand, Supply1]];

Show[b1, b2, Frame -> True]


chart



It has the same defect as the matlab chart — the longer blue bar at the right end of chart hides the shorter red bar behind it.







share|improve this answer














share|improve this answer



share|improve this answer








edited 10 hours ago

























answered 11 hours ago









m_goldbergm_goldberg

87.4k872198




87.4k872198











  • $begingroup$
    I suppose that, if OP's purpose is simply to get the plot, one could add Supply1, Supply2 = Transpose[Sort /@ Transpose[Supply1, Supply2]] before the calls to BarChart to "swap" the offending last values from Supply1 and Supply2.
    $endgroup$
    – MarcoB
    5 hours ago











  • $begingroup$
    @MarcoB. Yes, something like that would work, but it would ruin the stark simplicity of this answer :-), which is mainly to point out that hoe easy it is to reproduce the defective matlab chart. I think kglr's answer is better than mine because it makes the chart that is really wanted in a simple way.
    $endgroup$
    – m_goldberg
    2 hours ago

















  • $begingroup$
    I suppose that, if OP's purpose is simply to get the plot, one could add Supply1, Supply2 = Transpose[Sort /@ Transpose[Supply1, Supply2]] before the calls to BarChart to "swap" the offending last values from Supply1 and Supply2.
    $endgroup$
    – MarcoB
    5 hours ago











  • $begingroup$
    @MarcoB. Yes, something like that would work, but it would ruin the stark simplicity of this answer :-), which is mainly to point out that hoe easy it is to reproduce the defective matlab chart. I think kglr's answer is better than mine because it makes the chart that is really wanted in a simple way.
    $endgroup$
    – m_goldberg
    2 hours ago
















$begingroup$
I suppose that, if OP's purpose is simply to get the plot, one could add Supply1, Supply2 = Transpose[Sort /@ Transpose[Supply1, Supply2]] before the calls to BarChart to "swap" the offending last values from Supply1 and Supply2.
$endgroup$
– MarcoB
5 hours ago





$begingroup$
I suppose that, if OP's purpose is simply to get the plot, one could add Supply1, Supply2 = Transpose[Sort /@ Transpose[Supply1, Supply2]] before the calls to BarChart to "swap" the offending last values from Supply1 and Supply2.
$endgroup$
– MarcoB
5 hours ago













$begingroup$
@MarcoB. Yes, something like that would work, but it would ruin the stark simplicity of this answer :-), which is mainly to point out that hoe easy it is to reproduce the defective matlab chart. I think kglr's answer is better than mine because it makes the chart that is really wanted in a simple way.
$endgroup$
– m_goldberg
2 hours ago





$begingroup$
@MarcoB. Yes, something like that would work, but it would ruin the stark simplicity of this answer :-), which is mainly to point out that hoe easy it is to reproduce the defective matlab chart. I think kglr's answer is better than mine because it makes the chart that is really wanted in a simple way.
$endgroup$
– m_goldberg
2 hours ago


















draft saved

draft discarded
















































Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192883%2fhow-to-plot-this-group-bar-plot%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Möglingen Índice Localización Historia Demografía Referencias Enlaces externos Menú de navegación48°53′18″N 9°07′45″E / 48.888333333333, 9.129166666666748°53′18″N 9°07′45″E / 48.888333333333, 9.1291666666667Sitio web oficial Mapa de Möglingen«Gemeinden in Deutschland nach Fläche, Bevölkerung und Postleitzahl am 30.09.2016»Möglingen

Virtualbox - Configuration error: Querying “UUID” failed (VERR_CFGM_VALUE_NOT_FOUND)“VERR_SUPLIB_WORLD_WRITABLE” error when trying to installing OS in virtualboxVirtual Box Kernel errorFailed to open a seesion for the virtual machineFailed to open a session for the virtual machineUbuntu 14.04 LTS Virtualbox errorcan't use VM VirtualBoxusing virtualboxI can't run Linux-64 Bit on VirtualBoxUnable to insert the virtual optical disk (VBoxguestaddition) in virtual machine for ubuntu server in win 10VirtuaBox in Ubuntu 18.04 Issues with Win10.ISO Installation

Torre de la Isleta Índice Véase también Referencias Bibliografía Enlaces externos Menú de navegación38°25′58″N 0°23′02″O / 38.43277778, -0.3838888938°25′58″N 0°23′02″O / 38.43277778, -0.38388889Torre de la Illeta de l’Horta o Torre Saleta. Base de datos de bienes inmuebles. Patrimonio Cultural. Secretaría de Estado de CulturaFicha BIC Torre de la Illeta de l’Horta. Dirección General de Patrimonio Cultural. Generalitat ValencianaLugares de interés. Ayuntamiento del CampelloTorre de la Isleta en CastillosNet.org