【r<-方案|绘图】如何只绘制文本?

作者: 王诗翔 | 来源:发表于2019-05-21 15:15 被阅读14次

    如果想要只在图上写文本,这还是需要先创建一个空白的图形,然后将文本加上去。

    使用base plot

    par(mar = c(0,0,0,0))
    plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')
    
    text(x = 0.5, y = 0.5, paste("The following is text that'll appear in a plot window.\n",
                                 "As you can see, it's in the plot window\n",
                                 "One might imagine useful informaiton here"), 
         cex = 1.6, col = "black")
    

    恢复默认设定:

    par(mar = c(5, 4, 4, 2) + 0.1)
    

    ggplot2

    library(ggplot2)
    text = paste("\n   The following is text that'll appear in a plot window.\n",
             "       As you can see, it's in the plot window\n",
             "       One might imagine useful informaiton here")
    ggplot() + 
      annotate("text", x = 4, y = 25, size=8, label = text) + 
      theme_bw() +
      theme(panel.grid.major=element_blank(),
        panel.grid.minor=element_blank())
    

    原文出处:https://stackoverflow.com/questions/19918985/r-plot-only-text

    相关文章

      网友评论

        本文标题:【r<-方案|绘图】如何只绘制文本?

        本文链接:https://www.haomeiwen.com/subject/trdjzqtx.html