For three faceted variables, try facet_wrap.
facet_wrap(~ cut + color + clarity)
I re-read the question. If you really need a few graphs (it wasn’t so clear from the phrase), then just go through the levels clarity.
for(clarity in levels(diamonds$clarity))
{
p <- qplot(carat, price, data = diamonds[diamonds$clarity == clarity, ]) +
facet_grid(cut ~ color)
print(p)
}
Or if you are for-loop-phobic,
l_ply(
levels(diamonds$clarity),
function(clarity)
{
qplot(carat, price, data = diamonds[diamonds$clarity == clarity, ]) +
facet_grid(cut ~ color)
}
)
If you are typing on the screen, first enable history recording. Otherwise, enable the call ggsavein your loop.