Creating bar charts
A bar chart is the simplest chart that displays the frequency of a categorical variable or the summary statistics of a numeric variable over the category of other variables. In this recipe, we will learn how we can produce a bar chart using the ggplot2
library.
Getting ready
Let's call the ggplotdata
dataset that was created in the preceding section. We intend to produce a bar chart that will represent the mean of a numeric variable on the y axis over the category of the economic status variable on the x-axis. So, we need to prepare the summarized dataset as follows:
library(plyr) bardata <- ddply(ggplotdata,.(econ_status),summarize,meandisA=mean(disA), meandisB=mean(disB),meandisC=mean(disC),meadisD=mean(disD))
The description ...
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.