Subscribe Bookmark RSS Feed

Clustered Stacked Bar

jeffjy

Staff

Joined:

Aug 29, 2011

http://peltiertech.com/Utility/pix/clusterstackcolumns.png

Hi friends,

I am currently trying to use JMP to generate a clustered stacked bar similar to the chart above. I tried to modify the JSL but did not succeed. May I know is it achievable using JMP?

Anyone has done or tried something similar before?

Thank you so much!

Regards,

Jun Yao

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

It is possible to make such a graph using the Chart or Graph Builder platforms. However, each platform generate somewhat different results, and neither is an exact copy of your chart.

It seems not to be possible to have have "nested" or multiple overlay varaibles. The data table must therefore be constructed with this in mind and the two platforms appear to require a different table layout to get it right. Below is a script example based on your graph (using random data). The legend and colors can be further tweaked by hand or by script.

//Example tables

dt = New Table( "Test",

          Add Rows( 24 ),

  New Column( "City",

                    Character,

                    Nominal,

                    Set Values(

                              {"Atlanta", "Boston", "Chicago", "Detroit", "Atlanta",

  "Boston", "Chicago", "Detroit", "Atlanta", "Boston",

  "Chicago", "Detroit", "Atlanta", "Boston", "Chicago",

  "Detroit", "Atlanta", "Boston", "Chicago", "Detroit",

  "Atlanta", "Boston", "Chicago", "Detroit"}

                    )

          ),

  New Column( "ABC",

                    Character,

                    Nominal,

                    Set Values(

                              {"A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C",

  "C", "A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C",

                              "C"}

                    )

          ),

  New Column( "Mode",

                    Character,

                    Nominal,

                    Set Values(

                              {"Actual", "Actual", "Actual", "Actual", "Actual",

  "Actual", "Actual", "Actual", "Actual", "Actual", "Actual",

  "Actual", "Forecast", "Forecast", "Forecast", "Forecast",

  "Forecast", "Forecast", "Forecast", "Forecast", "Forecast",

  "Forecast", "Forecast", "Forecast"}

                    )

          ),

  New Column( "Data",

                    Numeric,

                    Continuous,

                    Format( "Best", 12 ),

                    Formula( Random Integer( 24 ) )

          )

);

dt1 = dt << Split(

          Split By( :Mode ),

          Split( :Data ),

          Group( :City, :ABC ),

          Remaining Columns( Drop All )

);

dt2 = dt << Split(

          Split By( :ABC ),

          Split( :Data ),

          Group( :City, :Mode ),

          Remaining Columns( Drop All )

);

//Chart platform

dt1 << Chart(

          X( :City, :ABC ),

          Y( Mean( :Actual ), Mean( :Forecast ) ),

          Show Level Legend( 1 ),

          Stack Bars( 1 ),

          Bar Chart( 1 ),

          SendToReport(

                    Dispatch(

                              {},

  "Chart Graph",

                              FrameBox,

                              {Frame Size( 207, 207 )}

                    )

          )

);

//Graph builder

dt2 << Graph Builder(

          Variables(

                    X( :City ),

                    Y( :A ),

                    Y( :B, Position( 1 ) ),

                    Y( :C, Position( 1 ) ),

                    Overlay( :Mode )

          ),

          Elements(

                    Bar(

                              X,

                              Y( 3 ),

                              Y( 2 ),

                              Y( 1 ),

                              Legend( 2 ),

                              Bar Style( "Stacked" ),

                              Summary Statistic( "Mean" )

                    )

          )

);

2 REPLIES
Solution

It is possible to make such a graph using the Chart or Graph Builder platforms. However, each platform generate somewhat different results, and neither is an exact copy of your chart.

It seems not to be possible to have have "nested" or multiple overlay varaibles. The data table must therefore be constructed with this in mind and the two platforms appear to require a different table layout to get it right. Below is a script example based on your graph (using random data). The legend and colors can be further tweaked by hand or by script.

//Example tables

dt = New Table( "Test",

          Add Rows( 24 ),

  New Column( "City",

                    Character,

                    Nominal,

                    Set Values(

                              {"Atlanta", "Boston", "Chicago", "Detroit", "Atlanta",

  "Boston", "Chicago", "Detroit", "Atlanta", "Boston",

  "Chicago", "Detroit", "Atlanta", "Boston", "Chicago",

  "Detroit", "Atlanta", "Boston", "Chicago", "Detroit",

  "Atlanta", "Boston", "Chicago", "Detroit"}

                    )

          ),

  New Column( "ABC",

                    Character,

                    Nominal,

                    Set Values(

                              {"A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C",

  "C", "A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C",

                              "C"}

                    )

          ),

  New Column( "Mode",

                    Character,

                    Nominal,

                    Set Values(

                              {"Actual", "Actual", "Actual", "Actual", "Actual",

  "Actual", "Actual", "Actual", "Actual", "Actual", "Actual",

  "Actual", "Forecast", "Forecast", "Forecast", "Forecast",

  "Forecast", "Forecast", "Forecast", "Forecast", "Forecast",

  "Forecast", "Forecast", "Forecast"}

                    )

          ),

  New Column( "Data",

                    Numeric,

                    Continuous,

                    Format( "Best", 12 ),

                    Formula( Random Integer( 24 ) )

          )

);

dt1 = dt << Split(

          Split By( :Mode ),

          Split( :Data ),

          Group( :City, :ABC ),

          Remaining Columns( Drop All )

);

dt2 = dt << Split(

          Split By( :ABC ),

          Split( :Data ),

          Group( :City, :Mode ),

          Remaining Columns( Drop All )

);

//Chart platform

dt1 << Chart(

          X( :City, :ABC ),

          Y( Mean( :Actual ), Mean( :Forecast ) ),

          Show Level Legend( 1 ),

          Stack Bars( 1 ),

          Bar Chart( 1 ),

          SendToReport(

                    Dispatch(

                              {},

  "Chart Graph",

                              FrameBox,

                              {Frame Size( 207, 207 )}

                    )

          )

);

//Graph builder

dt2 << Graph Builder(

          Variables(

                    X( :City ),

                    Y( :A ),

                    Y( :B, Position( 1 ) ),

                    Y( :C, Position( 1 ) ),

                    Overlay( :Mode )

          ),

          Elements(

                    Bar(

                              X,

                              Y( 3 ),

                              Y( 2 ),

                              Y( 1 ),

                              Legend( 2 ),

                              Bar Style( "Stacked" ),

                              Summary Statistic( "Mean" )

                    )

          )

);

jeffjy

Staff

Joined:

Aug 29, 2011

Thank you very much for your help! This script is exactly what I am looking for!