【发布时间】:2018-11-29 20:45:20
【问题描述】:
我正在尝试将参数列表传递给facet_grid() 以赋予函数更大的灵活性,但facet_grid() 似乎将列表中的所有内容视为分面变量或其他内容。它没有返回错误,但也没有我预期的行为。以下是我尝试编写的代码:
facet_plot <- function(facet.args){
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
geom_point() +
facet_grid(paste0('~', facet.args$facets), facet.args[which(names(facet.args) != 'facets')])
}
facet_plot(list(facets = 'Species', scales = 'free_x'))
我想要实现的是:
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
geom_point() +
facet_grid(~Species, scales = 'free_x')
我希望能够将任意数量的附加参数传递给facet_grid()。
【问题讨论】:
标签: r ggplot2 facet-grid