jeudi 2 avril 2015

R - how append newlines to plotted text

Say I have a plot in R:



plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n');


And I have a vector of comments:



comments = c("cool use of a string", "wow", "very very interesting")


And then I want to plot some text:



text(x = 0, y = 0.5, comments, cex = 0.9, col = "black", adj=0);


This is going to overwrite each line at the same position, causing a black blurry mess. It also exceeds the number of characters I'd like to see on each line. I can call strwrap, of course, but adding a "\n" prefix doesn't add the newlines as I'd like.



text(x = 0, y = 0.5, strwrap(comments, width=15, prefix="\n"), cex = 0.9, col = "black", adj=0);


My question: How do I plot an array of strings so that each line is wrapped at, say, 15 characters, and each string is plotted on a new line?


Aucun commentaire:

Enregistrer un commentaire