Bug 7931 - Wishlist: strwidth allow for rotation of text
Summary: Wishlist: strwidth allow for rotation of text
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: old
Hardware: All All
: P5 normal
Assignee: Jitterbug compatibility account
URL:
Depends on:
Blocks:
 
Reported: 2005-06-11 08:06 UTC by Jitterbug compatibility account
Modified: 2005-06-11 16:01 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2005-06-11 08:06:33 UTC
From: Elizabeth Purdom <epurdom@stanford.edu>
Hi,

This is not a bug, but an enhancement suggestion. "strwidth" only gives the 
width of the text according to the x-axis user coordinates, and similarly 
for "strheight". Even if the par setting "srt" is changed to rotate the 
text, the resulting width (resp. height) is in terms of the non-rotated 
text. Currently, if I want to know how much space to leave for vertical 
text in the user coordinates, I manually invert the user coordinates, and 
then change them back.

Even if arbitrary "srt" is too much, just having the option for 90 degree 
rotation would be helpful. If it were implemented for arbitrary srt, then I 
personally think it's x-axis and y-axis dimensions are of interest, and not 
the actual length of the rotated text.

I'm using R 2.1.0, Windows XP

Thanks,
Elizabeth Purdom

Example:
plot(1:100,seq(2,5,length=100), type="n")
par("usr")
# [1]  -2.96 103.96   1.88   5.12
strwidth("hello","user")
# [1] 7.613353
par(srt=90) #rotate 90 degrees
strwidth("hello","user") #still gives same width of text
# [1] 7.613353
par(usr=par("usr")[c(3,4,1,2)])
strwidth("hello","user")
# [1] 0.2307077

Comment 1 Jitterbug compatibility account 2005-06-11 16:01:55 UTC
From: Duncan Murdoch <murdoch@stats.uwo.ca>
epurdom@stanford.edu wrote:
> Hi,
> 
> This is not a bug, but an enhancement suggestion. "strwidth" only gives the 
> width of the text according to the x-axis user coordinates, and similarly 
> for "strheight". Even if the par setting "srt" is changed to rotate the 
> text, the resulting width (resp. height) is in terms of the non-rotated 
> text. Currently, if I want to know how much space to leave for vertical 
> text in the user coordinates, I manually invert the user coordinates, and 
> then change them back.
> 
> Even if arbitrary "srt" is too much, just having the option for 90 degree 
> rotation would be helpful. If it were implemented for arbitrary srt, then I 
> personally think it's x-axis and y-axis dimensions are of interest, and not 
> the actual length of the rotated text.

I think it's pretty standard to measure text this way.  You can get a 
very good approximation to arbitrary rotation by treating the text as a 
width by height rectangle, and using a bit of trig to calculation the 
rotated dimensions of that - but it's much harder to get the original 
dimensions back after doing this.

So I'd suggest that you should write a little function to calculate 
rotated dimensions, document it, and offer it to one of the Misc 
collections.

If you want to waste a lot of time on it you could try to do it in a way 
that can tell the difference between "Ay" and "yA" after a 45 degree 
rotation (the first is wider), but I think it will be hard to get that 
right.

Duncan Murdoch

Comment 2 Jitterbug compatibility account 2005-06-14 18:44:34 UTC
Audit (from Jitterbug):
Tue Jun 14 13:44:34 2005	ripley	moved from incoming to wishlist