Bar chart

Useful when comparing quantities across categories, bar charts are very simple in base graphics, particularly when combined with the table() command. We will use the mpg dataset, which comes with the ggplot2 package; it summarizes the different characteristics of a range of cars. First, let's install the ggplot2 package. You can do this straight from the console using the following code:

> install.packages("ggplot2")

Alternatively, you can use the built-in package functions in IDEs such as RStudio or RKWard. We'll need to load the package at the beginning of each session in which we want to use this dataset, or in the ggplot2 package itself. From the console, type the following command:

> library(ggplot2)

We will use the table() ...

Get Web Application Development with R Using Shiny - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.