Resolved: How to create a textbox-like object without plot

In this post, we will see how to resolve How to create a textbox-like object without plot

Question:

I’m creating some R scripts. In one of them, I would like to write formatted text enclosed in a box to a png. I don’t know how many lines of text there are, or what the length of the longest line is until I get into the R script, but I want to keep the formatting of the line and have the text fairly tightly enclosed. When I use a plot and a textbox, the plot comes with a large amount of graphical baggage and undesired behavior.
Is there anything that displays text on the device area that
  • does not require a plot,
  • wraps lines if they exceed a desired width, and
  • tightly surrounds the final text with a box?

Best Answer:

You can use ggtext::geom_textbox() in conjunction with theme_void():

You’ll likely need to play with font size, box size, and plot size.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com