wrap a character string to a plotting area. It gives the optimal cex and width. It works once plot device has been called idea to use strwrap from https://stackoverflow.com/questions/7367138/text-wrap-for-plot-titles

wrap_string_to_plot(
  string,
  max_cex = 1,
  min_cex = 0.5,
  string_font = 2,
  max_height = graphics::par("din")[2] - graphics::par("pin")[2] -
    graphics::par("omi")[1] - graphics::par("mai")[1] - 0.2,
  init_strwrap_width = 50,
  min_width = 0.9 * graphics::par("din")[1],
  max_width = 0.9 * graphics::par("din")[1],
  whole = TRUE
)

Arguments

string

A character vector with the text to be plotted

max_cex

A real number, giving the maximum *cex* (**c**haracter **ex**pansion) for the string to be plotted

min_cex

minimum character expansion to be used on the title

string_font

font type to be used on the title

max_height

A real number, giving the maximum height to be covered by the text

init_strwrap_width

A real number indicating the minimum number of characters to be plotted by line

min_width

A real number, giving the minimum width to be occupied by the string

max_width

A real number, giving the maximum width to be occupied by the string

whole

Boolean, indicating if the whole string should be plotted even if it surpasses the limits established in previous arguments