Metaprogramming with ggplot2

后端 未结 2 1259
别跟我提以往
别跟我提以往 2020-12-19 16:18

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.

相关标签:
2条回答
  • 2020-12-19 16:24

    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)))
    
    0 讨论(0)
  • 2020-12-19 16:42

    You should use

    ... + facet_grid(as.formula(sprintf("%s ~ %s", rowfacet, colfacet))
    

    in your code.

    0 讨论(0)
提交回复
热议问题