Hi @Rajat
I think we can get pretty close to what you want with only a little bit of work:
I've attached the restructured data table with the saved script so you can look for yourself. Here's what I did:
1. Stack your original table:
Current Data Table() << Stack(
columns( :Maths, :Physics, :Badminton, :Football ),
Source Label Column( "Label" ), Stacked Data Column( "Data" )
);
This gives the following:
2. We need a variable that will let us split up the grouping of activity (maths/physics vs badminton/football), so I'll add a new column, Group, and iterate A-A-B-B-A-A-B-B, etc. You can do this any way you like, you just need a nominal variable. Here's another way with Sequence():
New Column("Group", Numeric, "Nominal", Formula(Sequence(1, 2, 1, 2)) );
3. Graph Builder:
I tweaked a number of settings to get the graph looking the way I did, but here are the basic steps and a short video:
Steps:
- Drag "Data" column to Y role
- Drag both of the "Total" columns, at the same time, to the top of the Y drop zone
- Toggle off the points, and toggle on the Bar element
- Change the bar style for the lower graph, "Data," to "Stacked"
- Drag "Label" to the overlay role
- Under the controls for the top bars, turn off the overlay role under "Variables"
- Drag "Group" to the X axis role
- Turn off "Group" variable for upper plot in the control panel
- Drag "Student" to the Group X role
- Change "Summary Statistic" for the lower graph to "% of Factor" (I neglected to show this in the video)
- Change label to "Label by Value" for each bar
This gives:
From here you can do a lot. For the final graph I showed at the beginning, I also made some additions like changing the bar widths (right click a graph > customize), removed the X axis labels (double click axis and uncheck labels), and also changed the Graph Spacing (Red Triangle> Graph Spacing). Here is a script for the final graph:
Graph Builder(
Size( 799, 566 ),
Show Control Panel( 0 ),
Graph Spacing( 2 ),
Variables(
X( :Group ),
Y( :Total_Math_Physics ),
Y( :Total_Badminton_Football, Position( 1 ) ),
Y( :Data ),
Group X( :Student ),
Overlay( :Label )
),
Elements(
Position( 1, 1 ),
Bar( Y( 1 ), Y( 2 ), Overlay( 0 ), Legend( 5 ), Label( "Label by Value" ) )
),
Elements(
Position( 1, 2 ),
Bar(
X,
Y,
Legend( 4 ),
Bar Style( "Stacked" ),
Summary Statistic( "% of Factor" ),
Label( "Label by Value" )
)
),
SendToReport(
Dispatch(
{},
"Group",
ScaleBox,
{Min( -1.167069008972 ), Max( 2.147362067225 ), Inc( 1 ),
Minor Ticks( 0 ), Label Row( Show Major Labels( 0 ) )}
),
Dispatch(
{},
"Total_Math_Physics",
ScaleBox,
{Min( 0.23109243697479 ), Max( 55 ), Inc( 10 ), Minor Ticks( 1 )}
),
Dispatch(
{},
"Data",
ScaleBox,
{Min( 0 ), Max( 1.1209749344709 ), Inc( 0.2 ), Minor Ticks( 0 )}
),
Dispatch( {}, "graph title", TextEditBox, {Set Text( "Example" )} ),
Dispatch( {}, "X title", TextEditBox, {Set Text( "" )} ),
Dispatch(
{},
"Graph Builder",
FrameBox,
{DispatchSeg( BarSeg( 1 ), Set Width Proportion( 0.6 ) )}
),
Dispatch(
{},
"Graph Builder",
FrameBox( 2 ),
{DispatchSeg( BarSeg( 1 ), Set Width Proportion( 1 ) )}
),
Dispatch(
{},
"Graph Builder",
FrameBox( 3 ),
{DispatchSeg( BarSeg( 1 ), Set Width Proportion( 0.6 ) )}
),
Dispatch(
{},
"Graph Builder",
FrameBox( 4 ),
{DispatchSeg( BarSeg( 1 ), Set Width Proportion( 1 ) )}
),
Dispatch(
{},
"Graph Builder",
FrameBox( 5 ),
{DispatchSeg( BarSeg( 1 ), Set Width Proportion( 0.6 ) )}
),
Dispatch(
{},
"Graph Builder",
FrameBox( 6 ),
{DispatchSeg( BarSeg( 1 ), Set Width Proportion( 1 ) )}
)
)
);
I hope this helps!
@julian