[R] Coordinate or top left corner + offset

David L Carlson dcarlson at tamu.edu
Tue Feb 10 14:55:40 CET 2015


Thanks, I didn't know about corner.label. I started with legend but I couldn't find a way to make the box small enough. It always covered much more of the corner than the letter which could have obscured data points.

David

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ben Bolker
Sent: Monday, February 9, 2015 5:43 PM
To: r-help at stat.math.ethz.ch
Subject: Re: [R] Coordinate or top left corner + offset

David L Carlson <dcarlson <at> tamu.edu> writes:

> 
> This is more complicated, but it could be rolled up into a function.
Replace your mtext() call with the following:
> 
> # Set character expansion size
> cx <- 2.5
> # Get the plot coordinates and the character size
> ur <- par("usr")[c(1, 4)]
> chr <- par("cxy")
> rect(ur[1]+chr[1]/10, ur[2]-chr[2]*cx, ur[1]+chr[1]*cx, ur[2]-chr[1]/10, 
>      border=NA, col="white")
> text(ur[1]+chr[1]*cx/2, ur[2]-chr[2]*cx/2, "a", font=2, cex=2.5, col="red")
> 
> 1) Assign to cx the cex= value that you are using in text().
> 2) Then get the upper right corner of the plot window and the size of the
default character width in user
> coordinate units.
> 3) Draw a white rectangle the size of the character you are plotting (in
this case cex=2.5). Shrink the left
> and top edge so that the box around the plot area is not obscured.
> 4) Plot your character in the center of the box.
> 

  There are two more tricks you can use here:

  (1) cheat by using legend()

plot(0:10,0:10)
legend("topleft",legend=NA,title="hello",bty="n")

  (2) use plotrix::corner.label

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list