I have a character string:
str1 <- "aaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaa aaa aaa"
str1
nchar(str1)
I would like to insert \n automatically after every 16 characters, including spaces, in order to create a wrap text function for use in base graphics plot.
I tried:
str2 <- strwrap(str1, width = 16)
str2
but this did not work
plot(1:10,main=str2)
mtext(str2, side=1, line=0, outer=F,cex=1,col="blue")
Also is there a way to split the words properly and add extra spaces where necessary as in a proper word wrap function. Thank you for your help.