Chris
Chris

Reputation: 1489

R plot: Print text on margin in top left corner

I have the following basic code to plot a grid.

grid <- expand.grid( pi=seq(50, 95, 5) / 100, mu2=seq(5, .5, -.5) )
pi <- seq(44, 100, .5) / 100
par( mai=c(.05, .05, .05, .05), oma=c(2.9, 2.9, 0, 0) ) # Make room for label
plot( grid, cex=.5, xlab="", ylab="", cex.axis=.7 )

How can I plot a text label such as "(A)" in the top left corner as indicated by the red circle?

Edit: The "(A)" should be printed in regular, i.e., horizontal, reading direction; not vertically along with the y-axis.

enter image description here

Upvotes: 2

Views: 9128

Answers (2)

csgillespie
csgillespie

Reputation: 60462

You can use mtext to place text outside of the margins:

##Look at the help page for further details    
mtext("A", 2, adj=1, line=2)

##To rotate "A", try
mtext("A", 2, adj=5, las=1, padj=-22)

to get:

enter image description here

Upvotes: 6

Henrik
Henrik

Reputation: 67778

You may try this:

text(x = 0.44, y = 5, labels = "(A)", xpd = NA)

See also ?par how you can adjust plot margins with mar, if you need more space for the text. enter image description here

Upvotes: 3

Related Questions