Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - Plot Only Text

Tags:

string

text

plot

r

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


enter image description here


However, one doesn't have control (as far as I can tell) over font type, size, justification and so on.

like image 420
EconomiCurtis Avatar asked Nov 12 '13 00:11

EconomiCurtis


1 Answers

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

Here's a guide to what's going on here (use ?plot.default and ?par for more details):

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

enter image description here

Now to restore the default settings

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

I hope that helps!

like image 50
ZNK Avatar answered Sep 20 '22 16:09

ZNK