Information Technology Reference
In-Depth Information
a bar chart of the mean temperature by month in two steps. First, we compute the
means:
>
heights <- tapply(airquality$Temp, airquality$Month, mean)
That gives the heights of the bars, from which we create the bar chart:
>
barplot(heights)
The result is shown in the lefthand panel of
Figure 1-4
. The result is pretty bland, as
you can see, so it's common to add some simple adornments: a title, labels for the bars,
and a label for the
y
-axis:
>
barplot(heights,
+
main="Mean Temp. by Month",
+
names.arg=c("May", "Jun", "Jul", "Aug", "Sep"),
+
ylab="Temp (deg. F)")
Mean Temp. by Month
5
6
7
8
9
May
Jun
Jul
Aug
Sep
Figure 1-4. Bar charts, plain (left) and adorned (right)
The righthand panel of
Figure 1-4
shows the improved bar chart.
See Also
The
barchart
function in the
lattice
package is another way to produce a bar chart.
1.18 Creating a Box Plot
Problem
You want to create a box plot of your data.