[R] Coordinate or top left corner + offset
Ben Bolker
bbolker at gmail.com
Tue Feb 10 16:59:36 CET 2015
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 15-02-10 08:55 AM, David L Carlson wrote:
> 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
>
Not sure, but setting the background to NA (bg=NA) might? help.
> -----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
>
> ___________________________________
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iQEcBAEBAgAGBQJU2iroAAoJEOCV5YRblxUHV/YIAMn8cmOdQv035AUCYJCPgMl6
DDPztxTUIEsynQWPxyz2f853GnycIrsIkRDwWWKWaiGjsjeYEK2yb3kDpgLMyIca
JusoldnnIXGSwod2Hx8ozJFx2ggTDDyuP7uTkKWlXBTyM90XxVlZvEf8ZrbMSbly
dni6JMLdlUEBaYWvOV8dLuCYBFO1Mv5VXitY3YpoLGM5h3WIEK/6ABTVFBFXI9VH
Hujb1R7680mfY4V0jGmeY2vTdiIGZH6MGkOdLXNZhBwS1zjkBnoPJ6p6UMNVHbt0
DAgiNrfY+asG/NPEVgvvqeLpJ3TJ4xdt22o2ScG2vcbP0Qg6asrfnxqgrUc3vxM=
=94Ln
-----END PGP SIGNATURE-----
More information about the R-help
mailing list