I\'ve been trying to cut down on the amount of copying and pasting required to make a large number of charts with slightly differing functions / slices of the data.
facet_grid()
takes a formula object, and you can create a formula object from a string with as.formula()
. So you should be able to do something like:
facet_grid(as.formula(paste(rowfacet, "~", colfacet)))
You should use
... + facet_grid(as.formula(sprintf("%s ~ %s", rowfacet, colfacet))
in your code.