9
$\begingroup$

How to plot relative proportions on a line? IE PieChart as stacked BarChart that is normalised.

For example,

diversityCoearse = {"Firmicutes" -> 1000, 
  "Bacteroidetes" -> 200, "Verrucomicrobia" -> 20,
  "Proteobacteria" -> 40, "Actinobacteria" -> 32 };

PieChart[diversityCoearse[[All, 2]],
 SectorOrigin -> {Automatic, 1},
 ChartLabels -> Placed[{Style[#, 13] &/@ diversityCoearse[[All, 1]]}, {"RadialCallout"}],
 PlotRange -> All
]

PieChart example

And I would like to have:

enter image description here

$\endgroup$
11
$\begingroup$
diversityCoearse = 
  Association[
   "Firmicutes" -> 1000, "Bacteroidetes" -> 200, "Verrucomicrobia" -> 20, 
   "Proteobacteria" -> 40, "Actinobacteria" -> 32]

BarChart[diversityCoearse,
 ImageSize -> Large,
 AspectRatio -> 1/6,
 BarOrigin -> Left,
 ChartLayout -> "Stacked",
 ChartLabels -> 
   Placed[Keys @ diversityCoearse, {{.5, 1}, {0, 0}}, Rotate[#, 45 °] &]]

bar_chart

$\endgroup$
  • $\begingroup$ Works wonderfully, especially after adding @kglr trick: Normalize[diversityCoearse, Total] $\endgroup$ – Karolis May 30 '17 at 1:57
10
$\begingroup$
 RectangleChart[Callout[{#2, 1}, #]] & @@@ diversityCoearse, 
  ChartStyle -> 97,  AspectRatio -> 1/2, BarSpacing->{0,0}, Axes -> {True, False}]

Mathematica graphics

Update: using Normalized data:

diversityC = diversityCoearse;
diversityC[[All,2]]=Normalize[diversityC[[All,2]], Total];

RectangleChart[Callout[{#2, 1}, #] & @@@   diversityC, ChartStyle -> 97, 
 AspectRatio -> 1/2, Axes -> {True, False}, BarSpacing -> {0, 0}]

Mathematica graphics

$\endgroup$
5
$\begingroup$

To start you off:

Graphics[Riffle[ColorData[97] /@ Range[Length[dc]], 
                MapThread[Tooltip,
                          {Rectangle[{#1, 0}, {#2, 1/8}] & @@@ 
                           Partition[FoldList[Plus, 0, Normalize[Values[diversityCoearse],
                                                                 Total]], 2, 1],
                           Keys[diversityCoearse]}]],
         Frame -> True, FrameTicks -> {{False, False}, {True, False}}]

chart

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.