ggplot italicize part of caption AND divide text over two lines

Viewed 6918

I like to add the following caption to my graph:

Note: Market concentration averages in the United States, United Kingdom, and the Netherlands are, respectively, 1920, 1388, and 1244

Where 'Note:' needs to be italicized, and 'Netherlands are, respectively, 1920, 1388, and 1244' should be placed on a new line.

Using the paste function, I can italize a part. But using the \n within paste, mixes every thing up as you can see here (this is an edited image, made using Paul's advice below):

enter image description here

I tried various other solutions, but without succes. Here is the code I am using:

library(ggplot2)

note = expression(paste(italic("Note: "), "Market concentration averages in the United States, United Kingdom, and the \nNetherlands are, respectively, 1920, 1388, and 1244"))

gg <- ggplot(mtcars, aes(wt, mpg)) + geom_point()+

# Title
labs(caption=note)

gg + theme(plot.caption=element_text(size=7.5, hjust=0, margin=margin(t=15)))
3 Answers

Does this give you what you want ?

note = expression(paste(italic("Note: \n "), 
                        "Market concentration averages in the United States, United Kingdom, and the \nNetherlands are, respectively, 1920, 1388, and 1244"))

(The difference is that the "Note" part now also includes a newline)

Related