Graphics Reference
In-Depth Information
Figure 2-7. Left: bar graph of counts with qplot() with continuous x variable; right: with x variable
converted to a factor
If the vector is in a data frame, you can use the following syntax:
# Bar graph of values. This uses the BOD data frame, with the
#"Time" column for x values and the "demand" column for y values.
qplot(Time, demand, data = BOD, geom = "bar" , stat = "identity" )
# This is equivalent to:
ggplot(BOD, aes(x = Time, y = demand)) + geom_bar(stat = "identity" )
# Bar graph of counts
qplot(factor(cyl), data = mtcars)
# This is equivalent to:
ggplot(mtcars, aes(x = factor(cyl))) + geom_bar()
See Also
See Chapter 3 for more in-depth information about creating bar graphs.
Creating a Histogram
Problem
You want to view the distribution of one-dimensional data with a histogram.
Solution
To make a histogram ( Figure 2-8 ), use hist() and pass it a vector of values:
Search WWH ::




Custom Search