I want to add several lines of text to a plot, in which some words are in italics. This is what the text should look like:
Italic Text: Some
words with
new lines.
More italic text: Yet
more words divided
by new lines.
Italics again: And more
text with
new lines.
The following code prints a single line of text with italic words:
plot(c(0, 2), c(0, 2))
text(1, 1, bquote(
paste(
italic("Italic Text:"),
" Some words with new lines. ",
italic("More italic text:"),
"Yet more words divided by new lines. ",
italic("Italics again:"),
"And more text with new lines.",
sep = ""
)
)
)
And this creates line breaks, but no italics:
plot(c(0, 2), c(0, 2))
text(1, 1, "Italic Text: Some\nwords with\nnew lines.\n\nMore italic text: Yet\nmore words divided\nby new lines.\n\nItalics again: And more\ntext with\nnew lines.")
But when I try to break the text into lines and add italics, the newline characters lead to strange results:
plot(c(0, 2), c(0, 2))
text(1, 1, bquote(
paste(
italic("Italic Text:"),
" Some\nwords with\nnew lines.\n\n",
italic("More italic text:"),
"Yet\nmore words divided\nby new lines.\n\n",
italic("Italics again:"),
"And more\ntext with\nnew lines.",
sep = ""
)
)
)
atop()
, as suggested in other answers, only works with two lines.
What's the easiest method to add multiple lines of text with several words in italics to a plot?
- Ideally, using only base R.
- And without painfully positioning each line of text separately.