9

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

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Karolis
  • 1,639
  • 1
  • 12
  • 25

3 Answers3

11
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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
10
 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

kglr
  • 394,356
  • 18
  • 477
  • 896
5

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

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574