June 2016
Beginner to intermediate
1783 pages
71h 22m
English
In this first recipe, we will learn how to make bar charts for data with more than one category. Such bar charts are commonly used to compare values of the same measure across different categories.
We will use the base library barplot() function, but we will also use the RColorBrewer package to choose a good color palette. So, let's first install and load that package:
install.packages("RColorBrewer") #if not already installed
library(RColorBrewer)Let's reuse the citysales.csv example dataset that we used in the first chapter:
citysales<-read.csv("citysales.csv") barplot(as.matrix(citysales[,2:4]), beside=TRUE, legend.text=citysales$City, args.legend=list(bty="n",horiz=TRUE), ...Read now
Unlock full access