problem-4.6
problem-4.6
A table shows the relationship between manufacturer
and vitamin type by shelf location:
## load and attach data set
> library(MASS); attach(UScereal)
> table(mfr, vitamins, shelf)
, , shelf = 1
, , shelf = 3
vitamins
mfr 100% enriched none
G 3 6 0
K 2 8 0
N 0 1 0
P 0 6 0
Q 0 1 1
R 0 1 0
The most obvious relationship is that 100% fortified cereal
appears only on the highest shelf. This leaves space for the
kid-desirable, sugar-laden cereals on the coveted second
shelf.
The bubble plot is produced with the commands
> plot(calories ~ sugars, data=UScereal, cex=2*sqrt(fat))
There appears to be a linear relationship between sugars and
calories, as expected. The larger bubbles appear to be above the
smaller ones, indicating that more fat implies more calories as
well.
A pairs plot (pairs(UScereal)) shows many
relationships. For example, the fibre, shelf plot
shows some relationship. A better plot than the scatterplot for
showing a factor and a numeric variable is the boxplot:
> boxplot(fibre ~ shelf, data=UScereal)
The high-fiber cereals live on the top shelf for presumably the
same reason that the fortified cereals do.