1

I want to include a partly italic text (*p=*0.x) into my graph using geom_text. I found this solution How do I include italic text in geom_text_repel or geom_text labels for ggplot?

I tried this:

geom_text(parse=TRUE, aes(x=2, y = 104, label=expression(paste(italic("p="),"0.052"))), size=5)

this is the output: Don't know how to automatically pick scale for object of type expression. Defaulting to continuous. Error: Column label must be a 1d atomic vector or a list

I'm quite new in R and ggplot2 and most of time have no idea what I'm doing. Could somebody explain me why this doesn't work?

Mi Bumak
  • 11
  • 1
  • 3
  • 2
    Could you try to remove `expression`: `label = 'paste(italic("p="),"0.052")'`. – Stéphane Laurent Mar 07 '19 at 11:26
  • `label = 'paste(italic("p="),"0.052")'` writes paste(italic("p="),"0.052") `label = paste(italic("p="),"0.052")` leads to Error in italic("p=") : could not find function "italic" – Mi Bumak Mar 07 '19 at 14:07
  • 1
    For me this works. Did you set `parse = TRUE` ? – Stéphane Laurent Mar 07 '19 at 14:22
  • `geom_text(parse=TRUE, aes(x=2, y = 104, label=paste(italic("p="),"0.052")), size=5)` leads to Error in italic("p=") : could not find function "italic" . Is it possible the interpretation depends on some other settings somewhere? If I use the expression(paste(italic())) constuct in axis title, there is no problem at all. Do I use the parse in the correct place? – Mi Bumak Mar 07 '19 at 22:58
  • 2
    `label = 'paste(italic("p="),"0.052")'` ! – Stéphane Laurent Mar 08 '19 at 00:34
  • I used ggtitle(expression(paste("(",italic("F"),"=41.88, ",italic("P>F"),"<7.8e-9)"))) – TimothyEbert Sep 10 '20 at 12:09
  • 1
    I've had similar issues (can't find `italic`, etc.). By combining with another question (https://stackoverflow.com/questions/43728261/change-geom-text-to-bold-when-parse-true), I was able to make it work with this expression: `label = paste0(" italic(n)==", N)`. The key appears to be using `==` instead of `=`. – Eitan Feb 23 '22 at 17:43

0 Answers0