R - 仅绘制文本 [英] R - Plot Only Text
问题描述
好奇如何创建一个只有文本信息的情节.这基本上是绘图窗口的打印".
Curious how one might create a plot with only text information. This will essentially be a "print" for the plot window.
到目前为止,我发现的最佳选择如下:
The best option I've found so far is the following:
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))
但是,人们无法控制(据我所知)字体类型、大小、对齐方式等.
However, one doesn't have control (as far as I can tell) over font type, size, justification and so on.
推荐答案
您可以使用基本图形来做到这一点.首先,您需要从绘图窗口中删除所有边距:
You can do this using base graphics. First you'll want to take away all of the margins from the plot window:
par(mar = c(0,0,0,0))
然后你将绘制一个空图:
And then you'll plot an empty plot:
plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')
这是这里发生的事情的指南(使用 ?plot.default
和 ?par
了解更多详细信息):
Here's a guide to what's going on here (use ?plot.default
and ?par
for more details):
- ann - 显示注释(设置为 FALSE)
- bty - 边框类型(无)
- type - 绘图类型(不产生点或线的类型)
- xaxt - x 轴类型(无)
- yaxt - y 轴类型(无)
- ann - Display Annotoations (set to FALSE)
- bty - Border Type (none)
- type - Plot Type (one that produces no points or lines)
- xaxt - x axis type (none)
- yaxt - y axis type (none)
现在绘制文本.我去掉了多余的空格,因为它们似乎没有必要.
Now to plot the text. I took out the extra spaces because they didn't seem to be necessary.
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)
希望能帮到你!
这篇关于R - 仅绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!