Home > other >  Multiple lines of text/ label in mixed italic and regular fonts in ggplot
Multiple lines of text/ label in mixed italic and regular fonts in ggplot

Time:10-13

I have trying several options to add significance Levels as text labels to a plot. I got the result using geom_richtext() in the ggtext package. Although the labels turn out fine, I am getting the code pasted on the graph/ plot. Any idea how to avoid that! Or is there any other option?

geom_richtext(x = 1.15, 
                            y = 0.2, 
                            label.color = "black",
                            label = "<b>Significance Levels</b><br>ns <i>p</i> > 0.05<br>* <i>p</i> <= 0.05<br>** <i>p</i> <= 0.01<br>*** <i>p</i> <= 0.001<br>**** <i>p</i> <= 0.0001")[enter image description here][1]

CodePudding user response:

Try this:

library(gridtext)
library(ggplot2)

label <- "<b>Significance Levels</b><br>ns <i>p</i> > 0.05<br>* <i>p</i> <= 0.05<br>** <i>p</i> <= 0.01<br>*** <i>p</i> <= 0.001<br>**** <i>p</i> <= 0.0001"

ggplot(BOD, aes(Time, demand))  
  geom_point()   
  annotation_custom(richtext_grob(label), ymin = 0.2)

screenshot

  • Related