There are some good ideas here: https://github.com/IOHprofiler/IOHanalyzer/blob/7d758472a03e98d76a65baf6d6fea4d8bdbba6ef/R/plot.R#L339