Re: [R] setting par(srt) according to plot aspect ratio
Levi Waldron wrote: For posterity's sake, here is the solution I figured out. Putting the following lines after the plot(f) command seems to set the angle correctly: myasp - (par(fin)[2]-par(mai)[1]-par(mai)[3])/(par(fin)[1]-par(mai)[2]-par(mai)[4]) (f_angle - atan(myasp)*180/pi) (g_angle - atan(2*myasp)*180/pi) Hi Levi, Why not just: plotpin-par(pin) myasp-plotpin[2]/plotpin[1] Jim __ R-help@r-project.org mailing list 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.
Re: [R] setting par(srt) according to plot aspect ratio
On Fri, Aug 28, 2009 at 1:48 AM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: Note that the aspect ratio changes when you resize the plot but the angle of the plotted text will not. So the only safe route is to set 'asp' and use that setting to select the angle. That is true with screen output, although I can run the code block again after re-sizing to correct the text angle along with the aspect ratio. And for my purpose which is writing to file, it isn't an issue, for example the following plots which need different aspect ratios all work correctly: png(example%d.png) makeplot() #as per example code par(mfrow=c(2,1)) makeplot() makeplot() par(mfrow=c(1,2)) makeplot() makeplot() dev.off() -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] setting par(srt) according to plot aspect ratio
How can I look up the aspect ratio of a plot, so I can use that to correctly adjust the angle of text which is supposed to be parallel to a line in the plot? The following example code works for a 1:1 aspect ratio, but puts the text at the wrong angle if the plot region is short and wide or tall and narrow. I can't find a par() component containing the plot aspect ratio. It will be for png() or postscript() output, if that matters. f - function(x) x g - function(x) 2*x (f_angle - atan(1)*180/pi) (g_angle - atan(2)*180/pi) xpos - 0.2 plot(f) plot(g,add=TRUE) par(srt=f_angle) text(xpos,f(xpos),label=y=x,pos=3) par(srt=g_angle) text(xpos,g(xpos),label=y=2x,pos=3) -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] setting par(srt) according to plot aspect ratio
I frequently use R's help facilities and I know about the asp argument to plot, but this doesn't answer my question. I would like to allow the aspect to be determined automatically but *query* the aspect ratio for future use. I suppose one work-around would be to use the data ranges and plot region dimensions to estimate an appropriate value for asp, but this more complicated than I was hoping for. Thanks, Levi On Thu, Aug 27, 2009 at 6:19 PM, Bert Gunter gunter.ber...@gene.com wrote: Use R's help facilities, please. help.search(aspect ratio) gets you to ?plot.window which then gets you to ?plot (actually plot.default() ) Bert Gunter Genentech Nonclinical Biostatisics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Levi Waldron Sent: Thursday, August 27, 2009 1:54 PM To: r-help@r-project.org Subject: [R] setting par(srt) according to plot aspect ratio How can I look up the aspect ratio of a plot, so I can use that to correctly adjust the angle of text which is supposed to be parallel to a line in the plot? The following example code works for a 1:1 aspect ratio, but puts the text at the wrong angle if the plot region is short and wide or tall and narrow. I can't find a par() component containing the plot aspect ratio. It will be for png() or postscript() output, if that matters. f - function(x) x g - function(x) 2*x (f_angle - atan(1)*180/pi) (g_angle - atan(2)*180/pi) xpos - 0.2 plot(f) plot(g,add=TRUE) par(srt=f_angle) text(xpos,f(xpos),label=y=x,pos=3) par(srt=g_angle) text(xpos,g(xpos),label=y=2x,pos=3) -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] setting par(srt) according to plot aspect ratio
For posterity's sake, here is the solution I figured out. Putting the following lines after the plot(f) command seems to set the angle correctly: myasp - (par(fin)[2]-par(mai)[1]-par(mai)[3])/(par(fin)[1]-par(mai)[2]-par(mai)[4]) (f_angle - atan(myasp)*180/pi) (g_angle - atan(2*myasp)*180/pi) -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.