In a previous post I explained how to create all possible combinations of the levels of two factors using
expand.grid(). Another use for this function is to create a regular grid for two variables to create a levelplot or a contour plot.
For example, let’s say that we have fitted a multiple linear regression to predict wood stiffness (stiff, the response) using basic density (bd) and a measure of microfibril angle (t) as explanatory variables. The regression equation could be something like
stiffness = 3.439 + 0.009 bd - 0.052 t. In our dataset bd had a range of 300 to 700 kg m-3, while t had a range from 50 to 70.