Bar charts are useful for comparing the numbers of elements within subgroups of a population. However, they can be used for other purposes, such as comparing the means of a continuous variable across the levels of a categorical variable. You can create bar charts in
geom_bar(). As an exercise, create a bar chart of numbers of patients by ethnicity by turning the variable
ETH into a factor by using
factor(). The syntax is as follows:
W <- ggplot(T, aes(factor(ETH))) + geom_bar() W
The height of each bar gives the number of patients within each ethnicity. As an exercise, you can create a horizontal bar chart by adding the layer
coord_flip() layer also works for other types of graph, including ...