def add_value_labels(ax, spacing=5, include_percentage=True, precision=0):
    """Add labels to the end of each bar in a bar chart.

    Arguments:
        ax (matplotlib.axes.Axes): The matplotlib object containing the axes
            of the plot to annotate.
        spacing (int): The distance between the labels and the bars.
    """
    total_count = 0
    if include_percentage:
        for rect in ax.patches:
            total_count = total_count + rect.get_height()
    for rect in ax.patches:
        y_value = rect.get_height()
        x_value = rect.get_x() + rect.get_width() / 2
        space = spacing
        va = 'bottom'
        if y_value < 0:
            space *= -1
            va = 'top'
        label_value = '{:.{prec}f}'.format(y_value, prec=precision)
        if include_percentage:
            label_percent = '{:.2f}'.format(y_value * 100 / total_count)
            label = label_value + ' (' + label_percent + '%)'
        else:
            label = label_value
        ax.annotate(label, (x_value, y_value), xytext=(0, space),
            textcoords='offset points', ha='center', va=va)
