Function Repository Resource:

ScaledRankChart

Source Notebook

Display a chart of scaled counts of elements in a list

Contributed by: Michael Sollami

ResourceFunction["ScaledRankChart"][list]

displays a chart of ranked counts of elements in a given list.

Details and Options

ResourceFunction["ScaledRankChart"] uses several methods to make it easier to understand commonly occuring elements by charting elements to occupy space in proportion to the log of their frequency. ResourceFunction["ScaledRankChart"] groups together remaining frequencies of elements after a certain threshold number has been passed.
ResourceFunction["ScaledRankChart"] relies on the resource functions Equisample and MapColumn
ResourceFunction["ScaledRankChart"] takes the the following options:
ImageSizeAutomatichow big the chart should be
LabelStyleNonestyle to apply to label texts
"Logarithmic"Truewhether chart area is a linear or logarithmic function of frequency
LogPower1/2power p to use in pie-chart area formula: Log[1+count]*countp
MaxItems40max number of items beyond which they are lumped in the category “other”
"MinCount"Noneminimum count, beyond which they are lumped in category “other”
"NumberExamples"10number of examples to use in 2-argument form
"OtherChart"Falsewhether to allow mousing-over the “other” category to see next section of distribution
"Rotation"Automatichow much to rotate the starting sector axis
"ShowCounts"Truewhether to show counts next to each chart element
"Tooltips"Nonerules mapping elements to tooltips
"Type"PieChartthe type of chart displayed (BarChart or PieChart)
"UseLegend"Falsewhether to show a separate legend box

Examples

Basic Examples (3) 

Show a chart of the distribution of random variables:

In[1]:=
data = RandomChoice[
   Reverse@PowerRange[1, 32, 2] -> {"A", "B", "C", "D", "E", "F"}, 1000];
In[2]:=
Shallow@data
Out[2]=
In[3]:=
ResourceFunction["ScaledRankChart"][data, MaxItems -> 10, ImageSize -> 240]
Out[3]=

Rapidly-dwindling distributions are still legible:

In[4]:=
data = RandomVariate[HypergeometricDistribution[200, 200, 500], 300];
Shallow@data
Out[5]=
In[6]:=
ResourceFunction["ScaledRankChart"][data, MaxItems -> 10, "UseLegend" -> True, LabelStyle -> Directive[FontColor -> GrayLevel[.2], FontWeight -> Normal, FontSize -> 16], ImageSize -> 300]
Out[6]=

Chart the ranked distribution of random variables:

In[7]:=
ResourceFunction["ScaledRankChart"][
 Round[Exp@RandomReal[10, 10^8], 3], MaxItems -> 10, "Type" -> BarChart]
Out[7]=

Applications (2) 

Tokenize the text of Alice in Wonderland:

In[8]:=
text = ExampleData[{"Text", "AliceInWonderland"}];
words = DeleteStopwords@
   ToLowerCase[
    StringSplit[text, Alternatives @@ Characters[" ,|.!?;\"-()"]]]~
  DeleteCases~""; Take[words, 5]
Out[9]=

Display the distribution of words in the text, grouping elements making up less than 1% under the category “other”:

In[10]:=
Manipulate[
 ResourceFunction["ScaledRankChart"][words, "MinCount" -> minCount, ImageSize -> 300], {{minCount, .006}, 0.004, 0.0086}, ControlPlacement -> Top]
Out[10]=

Publisher

Michael Sollami

Version History

  • 1.0.0 – 31 March 2020

Related Resources

License Information