Here is a little script that gives the top,middle and bottom, and US groupings
It does this separately for each year. If that is not what you want, then the script can easily be changed by taking out the year references.
Names Default To Here( 1 );
dt = Data Table( "All Items 2014-2021 Stacked" );
dtSum =
// → Data Table( "SummaryData" )
Data Table( "All Items 2014-2021 Stacked" ) << Summary(
Group( :State, :Year ),
Mean( :Data ),
Freq( "None" ),
Weight( "None" ),
Link to original data table( 0 ),
output table name( "SummaryData" )
);
dtSum << delete rows( dtSum << get rows where( :state == "United States" ) );
// Sort data table
dtSum = Data Table( "SummaryData" ) << Sort(
By( :Year, :"Mean(Data)"n ),
Replace Table,
Order( Ascending, Ascending )
);
DtSum << New Column( "Color Group",
character,
set each value(
If(
Col Cumulative Sum( 1, :Year ) <= 5, "Top",
Col Cumulative Sum( 1, :Year ) <= 20, "Middle",
"Bottom"
)
)
);
Data Table( "All Items 2014-2021 Stacked" ) << Update(
With( Data Table( "SummaryData" ) ),
Match Columns( :State = :State, :Year = :Year )
);
dt:Color Group[dt << get rows where( :Color Group == "" )] = "U.S.";
dt << delete column( :"Mean(Data)"n );
dt:color group << set property( "value colors", {"Bottom" = 20, "Middle" = 41, "Top" = 19, "U.S." = 0} );
dt << Graph Builder(
Size( 534, 464 ),
Show Control Panel( 0 ),
Variables( X( :State ), Y( :Data ), Color( :Color Group ) ),
Elements( Points( X, Y, Legend( 7 ) ) )
);
Jim