Placing data labels in bar graphs

If you think you’re a data visualisation junkie, it’s likely that you’ve read Edward Tufte’s Visual Display Of Quantitative Information. If you are only a casual observer of the topic, you are likely to have come across these gifs that show you how to clean up a bar graph and a data table.

And if you are a real geek when it comes to visualisation, and you are the sort of person who likes long-form articles about the information technology industry, I’m sure you’ve come across Eugene Wei’s massive essay on “remove the legend to become one“.

The idea in the last one is that when you have something like a line graph, a legend telling you which line represents what can be distracting, especially if you have too many lines. You need to constantly move your head back and forth between the chart and the table as you try to interpret it. So, Wei says, in order to “become a legend” (by presenting information that is easily consumable), you need to remove the legend.

My equivalent of that for bar graphs is to put data labels directly on the bar, rather than having the reader keep looking at a scale (the above gif with bar graphs also does this). It makes for easier reading, and by definition, the bar graph conveys the information on the relative sizes of the different data points as well.

There is one problem, though, especially when you’re drawing what my daughter calls “sleeping bar graphs” (horizontal) – where do you really put the text so that it is easily visible? This becomes especially important if you’re using a package like R ggplot where you have control over where to place the text, what size to use and so on.

The basic question is – do you place the label inside or outside the bar? I was grappling with this question yesterday while making some client chart. When I placed the labels inside the bar, I found that some of the labels couldn’t be displayed in full when the bars were too short. And since these were bars that were being generated programmatically, I had no clue beforehand how long the bars would be.

So I decided to put all the labels outside. This presented a different problem – with the long bars. The graph would automatically get cut off a little after the longest bar ended, so if you placed the text outside, then the labels on the longest bar couldn’t be seen! Again the graphs have to come out programmatically so when you’re making them you don’t know what the length of the longest bar will be.

I finally settled on this middle ground – if the bar is at least half as long as the longest bar in the chart set, then you put the label inside the bar. If the bar is shorter than half the longest bar, then you put the label outside the bar. And then, the text inside the bar is right-justified (so it ends just inside the end of the bar), and the text outside the bar is left-justified (so it starts exactly where the bar ends). And ggplot gives you enough flexibility to decide the justification (‘hjust’) and colour of the text (I keep it white if it is inside the bar, black if outside), that the whole thing can be done programmatically, while producing nice and easy-to-understand bar graphs with nice labels.

Obviously I can’t share my client charts here, but here is one I made for the doubling days for covid-19 cases by district in India. I mean it’s not exactly what I said here, but comes close (the manual element here is a bit more).

 

 

Segmenting leisure hotels

The original idea for this pertinent observation comes from the wife. However, since she’s on an extended vacation and hence unlikely to blog this soon, I’m blogging it.

Hotels are traditionally classified into “business” and “leisure” hotels. As the names suggest, the former mostly cater to business travellers and the latter to vacationers. The lines can be a little blur, though, since business and leisure travels have complementary seasonality, thanks to which hotels practice “revenue management” by using their capacity for both business and leisure.

However, as we discovered during our vacation last week, leisure hotels can be further segmented into “couple hotels” and “family hotels”. Let me explain using the example of Vythiri Village Spa Resort where we spent most of last week. Based on our reading of the hotel, it was initially built to be a “couple hotel” but perhaps based on the kind of clientele they were getting, they turned it into a “family hotel”.

Now, the difference between couple hotels and family hotels essentially has to do with how child-friendly the place is. Vythiri, for example, had a “kids play area”, the balconies had been shuttered up with windows (creating greenhouses inside the balconies which made them horrible to hang out it, but making them safer for kids), ┬áhad a pantry area (the balcony had been converted into a pantry – so people wiht babies could bring their electric cookers and cook!) and activities such as “guided nature walks” and “artificial waterfalls”. Even at its deepest the swimming pool was not more than three feet deep (no I didn’t test it).

The reason I say that the hotel was built for couples is to do with the large bathroom which also included the walk-in closet. Given that you might want to multiplex between one person showering and another dressing at the same time, this design made it obvious that it only works for couples, but not for people with kids – most parents are shy about letting their kids see them in various stages of undress.

Then this resort advertised itself as a “spa resort”, and a massage was included in our package. This is again a “couple thing” for people with kids are unlikely to be able to take time off from their kids to visit the spa! So everything about this resort told you that it had been designed for couples, but then changed its positioning to become a “family resort”!

I guess you get the drift. And so whenever the manager would accost us and ask if things were good, the wife would quickly nod him a “yes”, and then privately tell me that we were the wrong target segment for the hotel, and so our feedback didn’t really matter to him!

And so we stayed there, for three nights and a bit, looking at screaming kids every time we hit the restaurant (the buffet spreads were nice, so we didn’t order room service); looking in bemusement at people “going on nature walks”, ignoring the “entertainment” at the “gala Christmas dinner” and so forth.

We had a good time, though, eating, sleeping, talking, hanging about – mostly within the confines of the room. The service was great, the staff extremely friendly and pleasant. Only that we were the wrong target segment for the hotel, and we didn’t realise that while booking!

PS: I tried looking for a “marketing” category to put this post under but realised that none such exists. Goes to show what I’ve not been blogging about!