4

In the dummy code below, I want to display word "bold" in bold and all word "red" in red. How to do it with one annotate()?

library(ggplot2) 
ggplot(mtcars, aes(x = wt, y = mpg)) + 
geom_point() +
annotate("text", x = 4, y = 25, 
         label = "This is bold. This is red.\nThis is red again")

enter image description here

GL_Li
  • 1,758
  • 1
  • 11
  • 25
  • Afaik, you can't. – jtr13 Mar 05 '17 at 13:08
  • These posts should get you there: [Multicolor text in R](http://blog.revolutionanalytics.com/2009/01/multicolor-text-in-r.html), [Using different font styles in annotate (ggplot2)](http://stackoverflow.com/questions/31568453/using-different-font-styles-in-annotate-ggplot2) and [text() R-function - how to change the font of a single word?](http://stackoverflow.com/questions/10408542/text-r-function-how-to-change-the-font-of-a-single-word). – Henrik Mar 05 '17 at 13:10
  • @Henrik can you explain how to mix base and grid graphics in this manner? – Roman Luštrik Mar 05 '17 at 13:29
  • @RomanLuštrik Sorry, I'm not quite sure I follow you here. `ggplot` handles the `plotmath` universe, and the use of `expression`, `bquote`, `atop` et al. fine. Another example: [putting mathematical symbols and subscripts mixed with regular letters in R/ggplot2](http://stackoverflow.com/questions/15125628/putting-mathematical-symbols-and-subscripts-mixed-with-regular-letters-in-r-ggpl) – Henrik Mar 05 '17 at 13:38
  • @RomanLuštrik That said, I don't claim it's 'easy' to achieve OPs desired result, I just wanted to point to some (IMHO) relevant approaches...;) – Henrik Mar 05 '17 at 13:46

0 Answers0