R - 仅绘制文本

Eco*_*tis 20 string plot text r

好奇如何创建一个只包含文本信息的情节.这基本上是绘图窗口的"打印".

我到目前为止找到的最佳选择如下:

  library(RGraphics)
  library(gridExtra)

    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",
           "       One might imagine useful informaiton here")
    grid.arrange(splitTextGrob(text))
Run Code Online (Sandbox Code Playgroud)


在此输入图像描述


但是,对于字体类型,大小,对齐等,人们无法控制(据我所知).

ZNK*_*ZNK 40

您可以使用基本图形来完成此操作.首先,您需要从绘图窗口中删除所有边距:

par(mar = c(0,0,0,0))
Run Code Online (Sandbox Code Playgroud)

然后你将绘制一个空图:

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')
Run Code Online (Sandbox Code Playgroud)

这是这里发生的事情的指南(使用?plot.default?par更多细节):

  • ann - 显示Annotoations(设置为FALSE)
  • bty - 边境类型(无)
  • type - Plot Type(不产生点或线的)
  • xaxt - x轴类型(无)
  • yaxt - y轴类型(无)

现在来绘制文字.我拿出了额外的空间,因为它们似乎没有必要.

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")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在恢复默认设置

par(mar = c(5, 4, 4, 2) + 0.1)
Run Code Online (Sandbox Code Playgroud)

我希望有所帮助!


sck*_*ott 15

你可以使用annotateggplot2

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())
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当然,你可以删除绘图边距,轴等,只有文本


Eco*_*tis 7

这也是一个方便的例子:

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.34, y = 0.9, paste("This is a plot without a plot."), 
     cex = 1.5, col = "black", family="serif", font=2, adj=0.5)

text(x = 0.34, y = 0.6, paste("    Perhpas you'll:"), 
     cex = 1.2, col = "gray30", family="sans", font=1, adj=1)
text(x = 0.35, y = 0.6, paste("Find it helpful"), 
     cex = 1.2, col = "black", family="mono", font=3, adj=0)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述