4

I have a dataset of Key Performance Indicator (KPI) and for each KPI I have a current level of achivement and 2 targets : Target1 and Target2.

How can I automatically generate one graphic for each achievement as in the file attached here.

As I have many KPIs I would like to generate my graphics in a batch process

Samy Koffi
  • 55
  • 5

1 Answers1

3

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().

Stereo
  • 1,423
  • 9
  • 24