Graphics Reference
In-Depth Information
Figure 2-9. Left: histogram with qplot() from ggplot2, with default bin width; right: with wider bins
If the vector is in a data frame, you can use the following syntax:
library(ggplot2)
qplot(mpg, data
=
mtcars, binwidth
=
4
)
# This is equivalent to:
ggplot(mtcars, aes(x
=
mpg))
+
geom_histogram(binwidth
=
4
)
See Also
For more in-depth information about creating histograms, see Recipes and .
Creating a Box Plot
Problem
You want to create a box plot for comparing distributions.
Solution
yvalues. When xis a factor (as opposed to a numeric vector), it will automatically create a box
plot:
plot(ToothGrowth$supp, ToothGrowth$len)