O'Reilly logo

R for Data Science by Dan Toomey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Bar charts and plots

In this section, I will show you how to generate bar charts and bar plots using R. I think whether you call a particular graphic a bar chart or a bar plot is up to you. There are minor differences between bar charts and bar plots. In both cases, we have bars representing counts; we display them across your graphic. The steps (and results) involved are similar.

Bar plot

R programming allows us to create bar charts in a variety of ways. The standard function in R is the barplot function. The barplot function only requires a list of the heights to be displayed. All of the following parameters are optional.

Usage

The barplot function is used as follows:

> barplot(data)

The various parameters are as follows:

 height, width = 1, space ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required