Graphics Programs Reference
In-Depth Information
This tells R to graph the Dogs.eaten column, and you should get Figure 4-6.
FIGurE 4-6 Default graph of number of hot dogs and buns eaten, using barplot() in R
Not bad, but you can do better. Use the names.arg argument in barplot() to
specify the names of each bar. In this case, it is the year of each contest.
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year)
This gives you Figure 4-7. There are now labels on the bottom.
FIGurE 4-7 Bar graph with labels for years
You can apply a number of other arguments. You can add axis labels,
change borders, and change colors, as shown in Figure 4-8.
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col=”red”,
border=NA, xlab=”Year”, ylab=”Hot dogs and buns (HDB) eaten”)
The col argument can be your pick of colors (specified in R documentation)
or a hexadecimal number such as #821122 . Here you specified no border
Search WWH ::




Custom Search