An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100122/6407aa29/attachment.pl>
Rotating the axis labels in the basic graphic device ?
10 messages · Tal Galili, Marc Schwartz, Uwe Ligges +1 more
On 22.01.2010 21:26, Tal Galili wrote:
Hello dear R help group,
I learned recently that one can change the rotation of labels in the axis,
when using a lattice plot, for example:
library(lattice)
barchart(yield ~ variety , data = barley,
groups = year,
ylab = "Barley Yield (bushels/acre)",
scales = list(rot = 45))
My question is: Is there an application of "rot" in something like barplot ?
The only solution I know of is using "las = X" (X is 1,2, or 3)
Is there another solution/hack for this ?
No, by design there is just the "las" way ... Uwe Ligges
Thanks! Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili at gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com/ (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]]
______________________________________________ R-help at 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.
On Jan 23, 2010, at 9:51 AM, Uwe Ligges wrote:
On 22.01.2010 21:26, Tal Galili wrote:
Hello dear R help group,
I learned recently that one can change the rotation of labels in the axis,
when using a lattice plot, for example:
library(lattice)
barchart(yield ~ variety , data = barley,
groups = year,
ylab = "Barley Yield (bushels/acre)",
scales = list(rot = 45))
My question is: Is there an application of "rot" in something like barplot ?
The only solution I know of is using "las = X" (X is 1,2, or 3)
Is there another solution/hack for this ?
No, by design there is just the "las" way ... Uwe Ligges
Actually, there is a method and it is in the R FAQs: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f HTH, Marc Schwartz
On 23.01.2010 16:56, Marc Schwartz wrote:
On Jan 23, 2010, at 9:51 AM, Uwe Ligges wrote:
On 22.01.2010 21:26, Tal Galili wrote:
Hello dear R help group,
I learned recently that one can change the rotation of labels in the axis,
when using a lattice plot, for example:
library(lattice)
barchart(yield ~ variety , data = barley,
groups = year,
ylab = "Barley Yield (bushels/acre)",
scales = list(rot = 45))
My question is: Is there an application of "rot" in something like barplot ?
The only solution I know of is using "las = X" (X is 1,2, or 3)
Is there another solution/hack for this ?
No, by design there is just the "las" way ... Uwe Ligges
Actually, there is a method and it is in the R FAQs: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f
Yes you are right, Marc, thank you! I would not call this as "by design" and it sometimes need quite a lot fiddling if font sizes change. Best, Uwe
HTH, Marc Schwartz
On Jan 23, 2010, at 9:59 AM, Uwe Ligges wrote:
On 23.01.2010 16:56, Marc Schwartz wrote:
On Jan 23, 2010, at 9:51 AM, Uwe Ligges wrote:
On 22.01.2010 21:26, Tal Galili wrote:
Hello dear R help group,
I learned recently that one can change the rotation of labels in the axis,
when using a lattice plot, for example:
library(lattice)
barchart(yield ~ variety , data = barley,
groups = year,
ylab = "Barley Yield (bushels/acre)",
scales = list(rot = 45))
My question is: Is there an application of "rot" in something like barplot ?
The only solution I know of is using "las = X" (X is 1,2, or 3)
Is there another solution/hack for this ?
No, by design there is just the "las" way ... Uwe Ligges
Actually, there is a method and it is in the R FAQs: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f
Yes you are right, Marc, thank you! I would not call this as "by design" and it sometimes need quite a lot fiddling if font sizes change. Best, Uwe
Quite right Uwe, it is not by design, but is consistent with:
library(fortunes)
fortune("yoda")
;-)
As you note, it took some understanding and tweaking of base graphics parameters and such to get that method to work.
Cheers,
Marc
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100123/a0cf6747/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100123/12ca09c9/attachment.pl>
On Jan 23, 2010, at 10:25 AM, Tal Galili wrote:
Marc, Following the R FAQ you linked to, I wonder how to ALWAYS have the text and the plot region fit. I know that if the text is too long, one can use the par(mar = c(big.number, 4, 4 ,4)) and get the text to fit. The question is: Is there a way to make the plot "know" what "big.number" should be so the text wouldn't go beyond plot regions ? (I suspect my question might get lost inside this topic, if so - I'll repeat it with a different header) Thanks again, Tal
<snip> Tal, I suspect that you would to create an algorithm using functions such as strwidth() and strheight() to get the plot metrics for the sizes of the character labels to have a sense of how much room would be required given other parameters. I am guessing that if you were to look at the appropriate source code in the lattice package, something along these lines is implemented there, since lattice supports rotated labels 'out of the box' and would logically have to consider these plotting characteristics at some level. Otherwise, it is a manual tweaking process. HTH, Marc
On 23.01.2010 17:42, Marc Schwartz wrote:
On Jan 23, 2010, at 10:25 AM, Tal Galili wrote:
Marc, Following the R FAQ you linked to, I wonder how to ALWAYS have the text and the plot region fit. I know that if the text is too long, one can use the par(mar = c(big.number, 4, 4 ,4)) and get the text to fit. The question is: Is there a way to make the plot "know" what "big.number" should be so the text wouldn't go beyond plot regions ? (I suspect my question might get lost inside this topic, if so - I'll repeat it with a different header) Thanks again, Tal
<snip> Tal, I suspect that you would to create an algorithm using functions such as strwidth() and strheight() to get the plot metrics for the sizes of the character labels to have a sense of how much room would be required given other parameters. I am guessing that if you were to look at the appropriate source code in the lattice package, something along these lines is implemented there, since lattice supports rotated labels 'out of the box' and would logically have to consider these plotting characteristics at some level.
Well, lattice relies on grid and grid can place arbitrary viewports with arbitrary rotations everywhere by design.
Otherwise, it is a manual tweaking process.
Indeed, that's the thing I meant with "not by design". ;-) Best wishes, Uwe
HTH, Marc
On 01/24/2010 03:25 AM, Tal Galili wrote:
Marc, Following the R FAQ you linked to, I wonder how to ALWAYS have the text and the plot region fit. I know that if the text is too long, one can use the par(mar = c(big.number, 4, 4 ,4)) and get the text to fit. The question is: Is there a way to make the plot "know" what "big.number" should be so the text wouldn't go beyond plot regions ?
Hi Tal, I've been working on this, as it often appears on the help list. The function getMarginWidth in the plotrix package tries to solve the common problem of fitting text or legends in the margins of the plot. I would like to improve this function and perhaps extend it so that the user can specify an area in which something must fit and get the appropriate "par" argument to use. All suggestions are welcome. Jim