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

with histograms, which are highly different. (A histogram 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

sacrifices 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.

Sponsors


 

Ggplot2 barplot


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

 

Barplot alternatives


The barplot is one of the most common dataviz types. It it thus sometimes accused of being a boring way to convey information, even if it is actually 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 provides a barplot() function that is very convenient. 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 in building a grouped barplot or a stacked barplot. The R graph gallery has 2 dedicated sections for them. Just in case, here is an overview of what you could find there:

 

 

Other charts involving barplot


Here is a selection of graphics that do not directly use barplots, but involve them or relate to them. See also the histogram and boxplot categories.

 

Related