There are multiple ways you can achieve this. I guess the easiest would be to create a function that saves a bar chart for your KPI to a file:
save_KPI_plot <- function(fn, kpi_data) {
png(paste0(fn, ".png"))
# Plot code
dev.off()
}
You can call the function either as follows,
save_KPI_plot("kpi_1", kpi_1_data)
or store your file names in one list and your data in another and loop over both:
kpi_fns <- list("filename_1", "filename_2")
kpi_data <- list(kpi_1_data, kpi_2_data)
for (i in seq_along(kpi_fns)) {
save_KPI_plot(kpi_fns[i], kpi_data[i])
}
If you prefer to have a different image format you can change png()
to bmp()
or jpeg()
.