У меня есть несколько объектов заговора, которые я хотел бы нарисовать в pdf. Как я могу отредактировать код ниже, чтобы создать функцию для создания одинаковых pdf-графиков:
Графики имеют разные названия 'main'.
pdf(file="results/sitar_df3df8_m.pdf")
plot(alsp_logbmc_sitar_m_3df, ylim = c(500,3500), main = "ALSPAC Males: df=3", xlab = "Age - y", ylab = "BMC - g")
plot(alsp_logbmc_sitar_m_4df, ylim = c(500,3500), main = "ALSPAC Males: df=4", xlab = "Age - y", ylab = "BMC - g")
plot(alsp_logbmc_sitar_m_5df, ylim = c(500,3500), main = "ALSPAC Males: df=5", xlab = "Age - y", ylab = "BMC - g")
plot(alsp_logbmc_sitar_m_6df, ylim = c(500,3500), main = "ALSPAC Males: df=6", xlab = "Age - y", ylab = "BMC - g")
plot(alsp_logbmc_sitar_m_7df, ylim = c(500,3500), main = "ALSPAC Males: df=7", xlab = "Age - y", ylab = "BMC - g")
plot(alsp_logbmc_sitar_m_8df, ylim = c(500,3500), main = "ALSPAC Males: df=8", xlab = "Age - y", ylab = "BMC - g")
plot(bmdcs_logbmc_sitar_m_3df, ylim = c(500,3500), main = "BMDCS Males: df=3", xlab = "Age - y", ylab = "BMC - g")
plot(bmdcs_logbmc_sitar_m_4df, ylim = c(500,3500), main = "BMDCS Males: df=4", xlab = "Age - y", ylab = "BMC - g")
plot(bmdcs_logbmc_sitar_m_5df, ylim = c(500,3500), main = "BMDCS Males: df=5", xlab = "Age - y", ylab = "BMC - g")
plot(bmdcs_logbmc_sitar_m_6df, ylim = c(500,3500), main = "BMDCS Males: df=6", xlab = "Age - y", ylab = "BMC - g")
plot(bmdcs_logbmc_sitar_m_7df, ylim = c(500,3500), main = "BMDCS Males: df=7", xlab = "Age - y", ylab = "BMC - g")
plot(bmdcs_logbmc_sitar_m_8df, ylim = c(500,3500), main = "BMDCS Males: df=8", xlab = "Age - y", ylab = "BMC - g")
dev.off()