27

好奇如何创建一个只有文本信息的情节。这基本上是绘图窗口的“打印”。

到目前为止,我发现的最佳选择如下:

  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))


在此处输入图像描述


然而,一个人无法控制(据我所知)字体类型、大小、对齐方式等。

4

4 回答 4

48

您可以使用基本图形来做到这一点。首先,您需要从绘图窗口中删除所有边距:

par(mar = c(0,0,0,0))

然后你将绘制一个空图:

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

这是这里发生的事情的指南(使用?plot.default?par了解更多详细信息):

  • ann - 显示注释(设置为 FALSE)
  • bty - 边框类型(无)
  • 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")

在此处输入图像描述

现在恢复默认设置

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

我希望这会有所帮助!

于 2013-11-12T04:05:36.240 回答
22

你可以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 information here")
ggplot() + 
  annotate("text", x = 4, y = 25, size=8, label = text) + 
  theme_void()

在此处输入图像描述

您当然可以删除绘图边距、轴等以仅显示文本

于 2013-11-12T01:20:14.457 回答
8

这也是一个方便的例子:

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)

在此处输入图像描述

于 2013-11-13T23:54:05.033 回答
1

继续阅读?parfamily通过和font参数 选择字体类型的能力有限。

于 2013-11-12T12:45:12.517 回答