Wrap Long Sentences

str_wrap() wraps long sentences into nicely formatted paragraphs.

library(stringr)x <- "William Shakespeare was a poet, actor and dramatist and is often seen as the best writer in the English language. He lived in the late 16th and early 17th century, but his plays are still widely performed today."
# print without wrapingcat(x)

Output:

William Shakespeare was a poet, actor and dramatist and is often seen as the best writer in the English language. He lived in the late 16th and early 17th century, but his plays are still widely performed today.
# wrap texts, with not more than 60 characters in each linecat(str_wrap(x, width = 60)) 

Output:

William Shakespeare was a poet, actor and dramatist and is
often seen as the best writer in the English language. He
lived in the late 16th and early 17th century, but his plays
are still widely performed today.

str_wrap() is a powerful tool to handle long texts in data visualization, as demonstrated in this example to wrap extended plot titles.