我正在从4个统计模型中创建子集“病毒”变量的图形。我不知道如何根据“病毒”变量放置图表标题。
我制作了这个可复制的套装:
library(dplyr)
library(tidyr)
library(lubridate)
library(mgcv)
library(purrr)
set.limpio <- data.frame(Codigo= 1:1000, Dia = rnorm(1000,100,2),
R = rbinom(1000,1,.5),
virus = c(rep("V1",250),
rep("V2",250),
rep("V3",250),
rep("V4",250)))
plots <- set.limpio %>%
filter(.$Dia < 250) %>%
split(.$virus) %>%
map(~ gam(R ~ s(Dia) + s(Codigo, bs = "re"), data = .,
family = binomial(link = "logit"), method = "REML")) %>%
map( ~ plot.gam(.,shade = T, scale = 0, scheme = 3,
xlab = "Days",
ylab = "Positivity"))
此部分应为标题
map( ~ plot.gam(.,shade = T, scale = 0,scheme = 3,xlab = "Days", ylab =
"Positivity", main = "here should be the title"))
我尝试过:
main = paste(names(.))
也可以
deparse(substitute(obj))
但是他们都不起作用。
答案 0 :(得分:2)
如马库斯所说,您可以使用imap
。
plots <- set.limpio %>%
filter(.$Dia < 250) %>%
split(.$virus) %>%
map(~ gam(R ~ s(Dia) + s(Codigo, bs="re"), data = .,
family = binomial(link = "logit"), method="REML")) %>%
imap( ~ plot.gam(.,shade = T, scale = 0,scheme = 3,xlab = "Days", ylab =
"Positivity", main= .y))
我刚刚将第二个map
调用替换为imap
,并添加了参数main = .y
如果目标只是显示绘图(plot.gam
不返回绘图对象),则应该使用iwalk
,而无需将其分配给plots
保持沉默。
请参见?imap