【发布时间】:2023-01-07 22:37:45
【问题描述】:
gggrid 允许直接使用网格对象(grobs)修改 ggplot2 图。函数grid_panel() 接受 grob 或函数作为第一个参数。我正在寻找将附加参数传递给此函数的方法(除了 data 和 coords)。
只要我坚持使用默认参数,它似乎就可以工作,但是一旦我设置了这个参数,我就会收到一个错误。
library(ggplot2)
library(gggrid)
data("mtcars")
lab1 <- function(data, coords, label = "ABC") {
textGrob(label)
}
# This works fine
ggplot(mtcars, aes(x=disp, y=mpg)) +
geom_point() +
grid_panel(lab1)
# This does not work
ggplot(mtcars, aes(x=disp, y=mpg)) +
geom_point() +
grid_panel(lab1(label = "BCD"))
# Error in lab1(label = "BCD") :
# argument "data" is missing, with no default
【问题讨论】: