R 绘图时输出公式

library(dplyr)
p.value <- wilcox.test(x$Normal,x$Cancer)$p.value %>% 
    signif(.,3) %>% as.character() %>% strsplit(.,split = "e-") %>% unlist() %>% as.numeric()
a <- p.value[1]
b <- p.value[2]

ggplot(x,aes(x=Type,y=Value,fill=Type))+
    geom_boxplot()+
    annotate("text",x=1.5,y=6,label = substitute(paste(italic('P value'),"=", a%*%10^b )))+
    labs(x="",y= substitute(paste(log[10],(FTO),+ 5)))+
    theme_bw()+
    theme(
      axis.title = element_text(size=12,face="bold"),
      axis.text = element_text(face="bold",size=12,color = "black"),
      legend.position = ""
    )

如上面代码所示,为了输出有上标的 p值也是煞费苦心,如果有更方便的方式请告知。还实现了字符串斜体和数学公式。

参考

https://blog.csdn.net/weixin_41929524/article/details/88577902
https://blog.csdn.net/weixin_41929524/article/details/103610743
https://blog.csdn.net/songzhilian22/article/details/49487467

你可能感兴趣的:(R 绘图时输出公式)