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?
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.
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.
try adding "\n" (new line) in the middle of your title. For example:
plot(rnorm(100), main="this is my title \non two lines")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With