# Displaying nominal data with a line graph

Recently I stumbled across a line graph displaying a contingency table which I found was a very powerfull visualization. In my opinion it is very seldom that nominal data is displayed this way; usually plots like a bar plot, mosaic plot etc. are used (see here or here for example).

To illustrate I provide a) a bar plot, b) a mosaic plot and c) a line plot for the same data. The Titanic data shows the frequencies for the variables Survived (yes vs. no), Sex (males vs. females) and class (1st, 2nd, 3rd and crew). I only included adults in the plots.

a) Bar plot b) Mosaic plot c) Line plot The line graph seems to clearly display what is going on, e.g. more males than females in total, class has a big effect on survival and so does sex, etc. Drawbacks of the line graph I can think of:

• The line goes through area were no category exists, e.g. there is nothing between first and second class. But: this seems to highlight what the changes between the categories are. Its kind of like a piecewise regression which shows the slope between two adjacent categories.
• It is confusing if we would include confidence intervalls here because the ci must not follow the line. But: Mosaic plots can not display ci either.

What are other drawbacks of the line graph here? Considering the rare use of the line graph in this case I guess there must be more. Or am I wrong and line graphs are a legitim/ common way to display nominal data?

• Note that class is not nominal, but ordinal - there is a clear ordered relationship among classes. This makes the line graph a bit more appropriate, since you expect to see trends when moving from group to group. With nominal data, one should generally not expect to see across-group trends, since the ordering of groups is entirely arbitrary. Nov 23, 2021 at 14:10
• @NuclearHoagie That is a great point! Ill try to find a better example (or notice that without any order a line graph is not more informative, which would partly answer my question).
– user248711
Nov 23, 2021 at 14:18

Beforehand: 2 groups

For binary nominal variables the line plot provides a clear representation where the slope shows how the frequency changes if we go from one group to the other. Consider the following line plot for the frequencies of sex: Here the slope shows the change of the frequency between males and females.

The problem: >2 groups

Consider the line plot for the nominal variable hair colour, which in the following data has four groups: Here, the lines shows changes between two adjacent groups, e.g. the line goes up from Black to Brown, meaning that there are more people with black hair than with brown.

For a nominal variable with k groups there are (k^2 + k)/ 2 possible comparisons. But the line plot only depicts the changes between two adjacent groups, i.e. k-1 slopes. Since nominal data has no natural order, the placement of the groups on the x axis is arbitrary. Thus, depicting nominal data with a line plot means highlighting the k-1 changes which are arbitrary choosen from (k^2 +k)/ 2 possible group comparisons. We can see this in the second plot: The plot shows the frequency increasment while we go from black to brown hair colour but the plot does not display the slope between black and red neither the one between black and blonde hair colour.

We can connect all possible group combinations with the line graph to provide complete information of the data but this is quite overhelming: To sum up

For ordinal, interval and ratio variables the line plot makes sense because it displays the trend of the data. For nominal data the location of the groups is arbitrary placed on the x axis and the lines of the line plot connect only two adjacent groups, i.e. groups that by coincidence lay next to each other. This is missleading. On the other hand, connecting all possible group comparisons results in an overhelming plot.

Remove the lines and make the shapes larger and you'd have a "dot plot". I'd say that is a common way of visualizing this type of data-- using the markers to show the points without the "area" of a bar plot potentially confusing the viewer-- but without the unnecessary (and potentially misleading) interpolation done by connecting it with lines.

Often, these would have the axes flipped (coord_flip() in ggplot2) and then you would sort the axis so that non-ordinal values were sorted in ascending or descending order, depending on what were emphasizing (putting the "most interesting" groups at the top of the Y axis).

A version of that with more pizzaz is the "lollipop" chart which is simply the dot plot with a thin line drawn from the axis to the dot. Those lines don't add anything except aesthetic value. They add "chart junk", decrease the "data-ink ratio" but they do look cool sometimes. For someone who hasn't seen my charts besides bar graphs it may help them intuitively understand how to read the dots. Here's an example that looks nice which was made in excel (https://policyviz.com/2016/02/04/lollipop_graph_in_excel/).

• I think this is not a big change to the plot styles discussed in the question. It just looks tidy since there is only one grouping variable. But using multiple variable (Sex, Country, ...) would lead to the very same difficulties in readability. Besides, my question was about the use of line plots for nominal data. I included other plot styles just for illustration. I could have included your plot as another example in my question and the question would be the same: What are other drawbacks of the line graph here?
– user248711
Nov 23, 2021 at 15:14