4
我試圖作出這樣的格子條形圖功能的包裝(使默認使用ggplot主題):爲什麼這個格子條形圖包裝器不工作?
require(ggplot2)
require(lattice)
require(latticeExtra)
data(Titanic)
mytheme = ggplot2like()
gbarchart = function(...) {
barchart(..., par.settings=mytheme)
}
gbarchart(Class ~ Freq | Sex + Age,
as.data.frame(Titanic),
groups = Survived,
stack = TRUE,
layout = c(4, 1),
auto.key = list(title = "Survived", columns = 2),
scales = list(x = "free"))
它給出了一個錯誤:
Error in eval(expr, envir, enclos) :
..3 used in an incorrect context, no ... to look in
而如果par.settings=mytheme
添加到barchart
直接,它的工作原理:
barchart(Class ~ Freq | Sex + Age,
as.data.frame(Titanic),
groups = Survived,
stack = TRUE,
layout = c(4, 1),
auto.key = list(title = "Survived", columns = 2),
scales = list(x = "free"),
par.settings=mytheme)
什麼是個人的論點和成對列表之間的區別是什麼? – qed
'paired.f < - function(list(x = 1))doSomeTasks'和'inv.f < - function(x = 1)doSomeTasks'。 – agstudy
所以'...'是一個配對列表,'do.call(func,...)'使用列表中的單個參數? – qed