# How can I make labels with units and then position the label to the right of a bar?

I want to add units to my numbers to display them as the labels of my chart. I tried this:

sizes = {10718, 881, 395, 387, 375, 309, 297};
sizesStr = ToString[sizes] <> " kB";
BarChart[sizes, BarOrigin -> Left, ChartLabels -> Placed[sizesStr, Right]]


So instead of each bar displaying "xxx kB" I get the "kB" after the whole list. Should I blame StringJoin for not being listable? How do I get the numbers in each of the bars?

Related: for the short bars the text will go beyond the vertical axis. Can I get the labels at the right of the bars, instead of inside them?

-
Yes it was the non Listable aspect of ToString that brought you undone. I've taken the liberty of modifying the title to make it more reflective of the question –  Mike Honeychurch Jul 14 at 8:41

This can be done in one of two ways. In both cases I am bypassing the creation of sizesStr:

sizes = {10718, 881, 395, 387, 375, 309, 297};
BarChart[sizes, BarOrigin -> Left, LabelingFunction -> (Placed[
Row[{#1, " kB"}], {{1, 0.5}, {0, 0.5}}] &)]


For that example I am using Row to "join" the value with the unit. I am using the Placed syntax to be found at the bottom of Details in the docs.

Note that {pos, epos} are scaled coordinates therefore {{1, 0.5}, {0, 0.5}} means that I am placing the middle of the left edge of the label {0,0.5} at the middle of the right edge of the bar {1,0.5}. Adding a Spacer might make it more aesthetically pleasing: Row[{Spacer[5], #1, " kB"}]

Alternatively:

BarChart[sizes, BarOrigin -> Left,
ChartLabels ->
Placed[sizes, {{1, 0.5}, {0, 0.5}}, ToString[#] <> " kB" &]]


In this example the third argument to Placed is used, i.e. a function that converts the value to a string and joins " kB" to it.

-