

Here is a simple bar chart: library(ggplot2) # Counts of elements in each of the three groups. The y axis values are drawn from a uniform distribution and represent a proportion of respondents that correctly answered corresponding questions. Let it be a result of a hypothetical survey with 9 questions labelled from Q1 to Q9 and combined into 3 groups. I deliberately keep charts simple with no customization of colours, etc.įirst, let’s simulate the data for the bar chart. The line chart will have dates on the x axis as this is probably the most popular case.


The bar chart (plot A below) is an example where data points from different groups should not be connected and a line chart (plot B below) is an example where data points should be connected both within and between groups:īelow, I discuss possible solutions to multi-level labels for these two charts. An important aspect is whether data points between groups should be connected. A 15-minute Google-fu provided me with various solutions described on Stack Overflow that worked with varying success for different types of charts. For example, survey questions may be grouped by topics and dates on the timeline may be grouped by years. Multi-level labels imply some sort of hierarchical structure in data.
#Rename x categories ggplot how to
Recently I needed to create multi-level labels with ggplot2 and had no idea how to do it.
