If I have a 2-column dataset like:

How do I make a BarChart in the obvious way (i.e., bars labeled by FileName, in this case)?


Several ways to do it:

dataset[BarChart[Labeled[#, Rotate[#2, 90 Degree], Axis]&@@@#]&,{"FileSize", "FileName"}]

dataset[BarChart[#[[All, 1]], ChartLabels -> (Rotate[#, 90 Degree]& /@ #[[All,2]])]&, 
  {"FileSize", "FileName"}]

dataset // Query[BarChart[#[[All, 1]], 
   ChartLabels -> (Rotate[#, 90 Degree]& /@ #[[All,2]])]&, {"FileSize", "FileName"}]

BarChart[#, ChartLabels -> Placed[#2, Axis, Rotate[#, 90 Degree]&]]& @@ 
  dataset[Transpose, {"FileSize", "FileName"}]
  • $\begingroup$ It turns out this causes collision in the BarChart due to outliers: here. Is there a way to account for this? Maybe only the top few files can be shown cleanly? $\endgroup$ – George Jul 19 '19 at 21:16
  • $\begingroup$ @George, does ScalingFunctions->"Log" (in BarChart) help? $\endgroup$ – kglr Jul 19 '19 at 21:22
  • $\begingroup$ A bit but there's still considerable collision in the labeling. $\endgroup$ – George Jul 19 '19 at 21:37
  • $\begingroup$ you can use dataset[BarChart[Labeled[#, Rotate[#2, 90 Degree], Axis]& @@@ #]&, {"FileSize","FileName"}] to have the labels rotated. $\endgroup$ – kglr Jul 19 '19 at 21:52
  • $\begingroup$ kglr: That worked! Is there a way to make the y-axis have units in Mb instead of bytes? $\endgroup$ – George Jul 19 '19 at 23:04

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.