A barplot (or barchart) is one of the most common type of graphic. It shows the relationship between a numerical variable and a categorical variable. For example, you can display the height of several individuals using bar chart. Barcharts are often confounded

with histograms, which is highly different. (It has only a numerical variable as input and shows its distribution). A common mistake is to use barplots to represent the average value of each group. If you have several values per group, showing only the average

dissimulate a part of the information. In this case, consider doing a boxplot or a violinplot. At least, you should show the number of observation per group and the confidence interval of each group. Last tip: ordering the bars often makes the chart more informative.



Ggplot2 barplot

As usual, I highly advise to use the ggplot2 library to build your graphic. It provides a geom_bar() function that allows to build any sort of barplot. The chart #218 will give you all the basic concepts you need to build your barplot in minutes. Next examples describe the most common customisation like reordering, adding error bars or customising width. Note that the gallery offers a dedicated sections for stacked barplot and another for circular barplot.


Barplot alternative

Barplot is one of the most common dataviz type. It it thus sometimes accused of being a boring way to convey information, even if it is really effective. Nevertheless if you want an alternative, you can think about doing a lollipop plot or a circular barplot. Both have a dedicated section in the gallery:


BaseR barplot

Of course, baseR also provide a barplot() function that is really convenient to make your barplot. Here are a few examples describing its utilisation.


Custom barplot


Grouped and stacked barplot

If you have several groups in your data set, you are probably interested by building a grouped barplot or a stacked barplot. The R graph gallery has 2 dedicated section for them. Just in case, here is an overview of what you could find in these section.



Other charts involving barplot

There is a selection of graphics that do not target barplots, but involve it. See also the histogram and boxplot categories.