Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text wrap for plot titles

Tags:

plot

r

I have a long title for a plot in R and it keeps extending outside the plot window. How can I wrap the title over 2 rows?

like image 257
Concerned_Citizen Avatar asked Sep 09 '11 20:09

Concerned_Citizen


People also ask

How do I wrap text around a title in R?

You can use strwrap and paste to automatically wrap the title of your graph. The width need to be adapted to your media width. R should do that automatically, nobody want cropped title.

How do you break a text in R?

To split a string in R, use the strsplit() method. The strsplit() is a built-in R function that splits the string vector into sub-strings. The strsplit() method returns the list, where each list item resembles the item of input that has been split.


1 Answers

try adding "\n" (new line) in the middle of your title. For example:

plot(rnorm(100), main="this is my title \non two lines") 

enter image description here

like image 179
JD Long Avatar answered Sep 28 '22 00:09

JD Long