Creating bar charts
In this recipe, we will learn how to make bar plots that are useful to visualize summary data across various categories, such as sales of products or results of elections.
Getting ready
First, we need to load the citysales.csv
example data file (you can download this file from the code download section of the book's companion website):
sales<-read.csv("citysales.csv",header=TRUE)
How to do it...
Just like the plot()
function we used to make scatter plots and line graphs in the earlier recipes, the barplot()
and
dotchart()
functions are part of the base graphics library in R. This means that we don't need to install any additional packages or libraries to use these functions.
We can make bar plots using the
barplot()
function as ...
Get R: Data Analysis and Visualization 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.