Graphics Reference
In-Depth Information
See Also
For more on using colors in bar graphs, see Using Colors in a Bar Graph .
To reorder the levels of a factor based on the values of another variable, see Changing the Order
of Factor Levels Based on Data Values .
Making a Bar Graph of Counts
Problem
Your data has one row representing each case, and you want plot counts of the cases.
Solution
Use geom_bar() without mapping anything to y ( Figure 3-7 ):
ggplot(diamonds, aes(x = cut)) + geom_bar()
# Equivalent to using geom_bar(stat="bin")
Search WWH ::




Custom Search