0

Is there a function where I can reduce the line of repeated plot codes for different data sets?

plot_missing(prospects6K, 
             group = c("Excellent" = 0.01, "Good" = 0.3, "Ok" = 0.6, "Bad" = 0.9),
             missing_only = T,
             title= "Missing User Data",
             ggtheme = theme_minimal(),
             theme_config = list(legend.position = c("bottom"))
)

plot_missing(testing5K, 
             group = c("Excellent" = 0.01, "Good" = 0.3, "Ok" = 0.6, "Bad" = 0.9),
             missing_only = T,
             title= "Missing User Data",
             ggtheme = theme_minimal(),
             theme_config = list(legend.position = c("bottom"))
)

plot_missing(training15K, 
             group = c("Excellent" = 0.01, "Good" = 0.3, "Ok" = 0.6, "Bad" = 0.9),
             missing_only = T,
             title= "Missing User Data",
             ggtheme = theme_minimal(),
             theme_config = list(legend.position = c("bottom"))
)
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
wahlaoeh
  • 45
  • 7

1 Answers1

1

Assuming you are working with data frames, first create a list of them:

plot_list <- list(prospects6K, testing5K, training15K)

Then you can use lapply:

lapply(plot_list, \(x) plot_missing(x, 
             group = c("Excellent" = 0.01, "Good" = 0.3, "Ok" = 0.6, "Bad" = 0.9),
             missing_only = T,
             title= "Missing User Data",
             ggtheme = theme_minimal(),
             theme_config = list(legend.position = c("bottom"))
)
René Martínez
  • 179
  • 1
  • 3
  • 11