|
R does a great job with the fine details regarding plots. e.g in the
following: library(lattice) y <- -4:4/10 xyplot(y~1, las=1) the y axis is labelled with numbers -0.4, -0.2, 0.0, 0.2, 0.4 with the numbers aligned on the decimal point. How do I get the same behaviour in the colorkey of a levelplot? e.g. levelplot(matrix(y,3,3)) the numbers in the colorkey seem left-aligned, and because of the minus sign, the numbers now do not align on the decimal point. Likewise when the number of digits changes: levelplot(matrix(4:12,3,3)) Thanks, Stephen ______________________________________________ [hidden email] 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 Sat, Jun 16, 2012 at 2:11 AM, Stephen Eglen <[hidden email]>wrote:
> R does a great job with the fine details regarding plots. e.g in the > following: > > library(lattice) > y <- -4:4/10 > xyplot(y~1, las=1) > > No. las is a parameter in base graphics ?par. It was simply ignored here: xyplot(y~1,scales=list(rot=45), las=1) > > the numbers in the colorkey seem left-aligned, and because of the minus > sign, the numbers now do not align on the decimal point. Likewise when > the number of digits changes: > > levelplot(matrix(4:12,3,3)) > > The labels are aligned to the colored rect. You want them aligned differently, change it manually. See the colorkey details in ?levelplot (also can help with your next thread on positioning). One obvious way is to add white spaces: levelplot(matrix(seq(4,120,l=9),3,3)) # or levelplot(matrix(seq(4,120,l=9),3,3),colorkey=list(at=seq(0,120,20),labels=c(' 0',' 20',' 40',' 60',' 80','100','120'))) (If your mail client gobbled them, in the above labels, 0 has two white spaces before it, 20 has 1 white space, etc.) Cheers > Thanks, Stephen > > ______________________________________________ > [hidden email] 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. > [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
|
In reply to this post by Stephen Eglen
On Sat, Jun 16, 2012 at 1:41 PM, Stephen Eglen
<[hidden email]> wrote: > R does a great job with the fine details regarding plots. e.g in the > following: > > library(lattice) > y <- -4:4/10 > xyplot(y~1, las=1) > > the y axis is labelled with numbers -0.4, -0.2, 0.0, 0.2, 0.4 with the > numbers aligned on the decimal point. > > How do I get the same behaviour in the colorkey of a levelplot? e.g. > > levelplot(matrix(y,3,3)) > > the numbers in the colorkey seem left-aligned, and because of the minus > sign, the numbers now do not align on the decimal point. Likewise when > the number of digits changes: > > levelplot(matrix(4:12,3,3)) Justification is hard-coded, and that's not easy to change. This is not only for the colorkey; e.g., xyplot(y~1, scales = list(alternating = 3)) will also give you left-aligned axes on the right. My only suggestion (other than custom labels as suggested by ilai) is levelplot(matrix(4:12,3,3), colorkey = list(space = "left")) -Deepayan ______________________________________________ [hidden email] 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. |
|
>
> Justification is hard-coded, and that's not easy to change. This is > not only for the colorkey; e.g., > > xyplot(y~1, scales = list(alternating = 3)) > > will also give you left-aligned axes on the right. > > My only suggestion (other than custom labels as suggested by ilai) is > > levelplot(matrix(4:12,3,3), colorkey = list(space = "left")) Thanks Deepayan; I tried the custom labels approach, but unfortunately I don't think that works as-is; the labels are of different widths as the font is not fixed-width. Stephen ______________________________________________ [hidden email] 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 Tue, Jun 19, 2012 at 10:55 PM, Stephen Eglen
<[hidden email]> wrote: >> >> Justification is hard-coded, and that's not easy to change. This is >> not only for the colorkey; e.g., >> >> xyplot(y~1, scales = list(alternating = 3)) >> >> will also give you left-aligned axes on the right. >> >> My only suggestion (other than custom labels as suggested by ilai) is >> >> levelplot(matrix(4:12,3,3), colorkey = list(space = "left")) > > Thanks Deepayan; I tried the custom labels approach, but unfortunately I > don't think that works as-is; the labels are of different widths as the > font is not fixed-width. You can specify a fixed-width fontfamily if that helps: levelplot(matrix(seq(4,120,l=9),3,3), colorkey = list(at = seq(0, 120, 20), labels = list(labels = c(' 0',' 20',' 40',' 60',' 80','100','120'), fontfamily = "courier", font = 1))) -Deepayan ______________________________________________ [hidden email] 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. |
|
Deepayan Sarkar <[hidden email]> writes: > You can specify a fixed-width fontfamily if that helps: > > levelplot(matrix(seq(4,120,l=9),3,3), > colorkey = list(at = seq(0, 120, 20), > labels = list(labels = c(' 0',' 20',' 40',' > 60',' 80','100','120'), > fontfamily = "courier", > font = 1))) Thanks Deepayan; I think I finally found a solution which worked much easier than I thought: ## Thanks to "R graphics, 2nd ed" Paul Murrell, page 250 shows how to edit ## an existing plot. levelplot(matrix(-90:89,20,20)) grid.edit("[.]colorkey.labels$", grep=TRUE, just="right", global=T, x=unit(0.95, "npc")) I can live with adjusting the x position by hand. Stephen ______________________________________________ [hidden email] 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. |
| Powered by Nabble | Edit this page |
