Deepayan Sarkar
2020-Feb-13 05:16 UTC
[R] Increasing space for main title in a lattice (xyplot()) graphics.
On Thu, Feb 13, 2020 at 10:39 AM Richard M. Heiberger <rmh at temple.edu> wrote:> > It works as anticipated for me > > > xyplot(1 ~ 1, > + main="The quick brown fox jumped\n over the lazy dog.") > > xyplot(1 ~ 1, > + main="The quick brown fox jumped over the lazy dog.") > > Something else you are doing is probably causing the difficulty.Yes, the necessary space should be automatically allocated. Details of version / device might help diagnosing the problem. -Deepayan> > Rich > > On Wed, Feb 12, 2020 at 11:59 PM Rolf Turner <r.turner at auckland.ac.nz> wrote: > > > > > > I'm trying to do an xyplot() with a longish main title that I'd like to > > split into two lines, something like > > > > xyplot(<whatever>, > > main="The quick brown fox jumped\n over the lazy dog.") > > > > When I do this I only get the last half, i.e. the "over the lazy dog." > > bit, and the first half doesn't appear. > > > > In base graphics I'd handle this sort of thing by increasing the third > > entry of the "mar" parameter. > > > > How can increase the space allocated for the title in lattice graphics? > > I've done a substantial amount of Googling and can't find anything > > helpful. I've fiddled about with trellis.par.set() and cannot seem to > > get any effect. > > > > Could someone please give my poor feeble brain some guidance? Ta. > > > > cheers, > > > > Rolf Turner > > > > -- > > Honorary Research Fellow > > Department of Statistics > > University of Auckland > > Phone: +64-9-373-7599 ext. 88276 > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Bert Gunter
2020-Feb-13 06:06 UTC
[R] Increasing space for main title in a lattice (xyplot()) graphics.
OK. Now for a tougher problem: how to make the first line bold font and the second line normal font (and/or different colors)? My reading of the docs did not reveal how to do it, but I found a way using a textGrob for the title (i.e. main ). But it's tricky, as the "obvious solution" of using different y values for the lines caused lattice to enlarge the title viewport too much, shrinking the graph panels so that details were lost. I think I have found a way to avoid this and make it work, but I'll delay giving my somewhat clumsy "solution" until some of you have a chance to find a more sensible approach, if you care to try. Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Feb 12, 2020 at 9:19 PM Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:> On Thu, Feb 13, 2020 at 10:39 AM Richard M. Heiberger <rmh at temple.edu> > wrote: > > > > It works as anticipated for me > > > > > xyplot(1 ~ 1, > > + main="The quick brown fox jumped\n over the lazy dog.") > > > xyplot(1 ~ 1, > > + main="The quick brown fox jumped over the lazy dog.") > > > > Something else you are doing is probably causing the difficulty. > > Yes, the necessary space should be automatically allocated. Details of > version / device might help diagnosing the problem. > > -Deepayan > > > > > Rich > > > > On Wed, Feb 12, 2020 at 11:59 PM Rolf Turner <r.turner at auckland.ac.nz> > wrote: > > > > > > > > > I'm trying to do an xyplot() with a longish main title that I'd like to > > > split into two lines, something like > > > > > > xyplot(<whatever>, > > > main="The quick brown fox jumped\n over the lazy dog.") > > > > > > When I do this I only get the last half, i.e. the "over the lazy dog." > > > bit, and the first half doesn't appear. > > > > > > In base graphics I'd handle this sort of thing by increasing the third > > > entry of the "mar" parameter. > > > > > > How can increase the space allocated for the title in lattice graphics? > > > I've done a substantial amount of Googling and can't find anything > > > helpful. I've fiddled about with trellis.par.set() and cannot seem to > > > get any effect. > > > > > > Could someone please give my poor feeble brain some guidance? Ta. > > > > > > cheers, > > > > > > Rolf Turner > > > > > > -- > > > Honorary Research Fellow > > > Department of Statistics > > > University of Auckland > > > Phone: +64-9-373-7599 ext. 88276 > > > > > > ______________________________________________ > > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > 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-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
Deepayan Sarkar
2020-Feb-13 07:07 UTC
[R] Increasing space for main title in a lattice (xyplot()) graphics.
Hi Bert, You are right that the general solution is for 'main' to be a (grid) grob. It is not clear (to me) what the "height" of a textGrob with multiple labels should be, but the following gives reasonable results: xyplot(1 ~ 1, main = textGrob(c("The quick brown fox jumped", "over the lazy dog"), x = unit(0.5, "npc"), y = unit(c(0.75, 0.25), "cm"))) I'm guessing your first attempt was with the default units ("npc") for y. The correct grob (allowing more detailed control) to use for complex grid objects is a frameGrob. lattice does have an interface to create (simple) frameGrobs, for constructing legends. This can be (ab)used as follows: xyplot(1 ~ 1, main = draw.key(key = list(text = list(c("The quick brown fox jumped", "over the lazy dog"), font = c(1, 2), col = c(2, 3))))) -Deepayan On Thu, Feb 13, 2020 at 11:36 AM Bert Gunter <bgunter.4567 at gmail.com> wrote:> > OK. Now for a tougher problem: how to make the first line bold font and the second line normal font (and/or different colors)? > > My reading of the docs did not reveal how to do it, but I found a way using a textGrob for the title (i.e. main ). But it's tricky, as the "obvious solution" of using different y values for the lines caused lattice to enlarge the title viewport too much, shrinking the graph panels so that details were lost. I think I have found a way to avoid this and make it work, but I'll delay giving my somewhat clumsy "solution" until some of you have a chance to find a more sensible approach, if you care to try. > > Bert > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Wed, Feb 12, 2020 at 9:19 PM Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote: >> >> On Thu, Feb 13, 2020 at 10:39 AM Richard M. Heiberger <rmh at temple.edu> wrote: >> > >> > It works as anticipated for me >> > >> > > xyplot(1 ~ 1, >> > + main="The quick brown fox jumped\n over the lazy dog.") >> > > xyplot(1 ~ 1, >> > + main="The quick brown fox jumped over the lazy dog.") >> > >> > Something else you are doing is probably causing the difficulty. >> >> Yes, the necessary space should be automatically allocated. Details of >> version / device might help diagnosing the problem. >> >> -Deepayan >> >> > >> > Rich >> > >> > On Wed, Feb 12, 2020 at 11:59 PM Rolf Turner <r.turner at auckland.ac.nz> wrote: >> > > >> > > >> > > I'm trying to do an xyplot() with a longish main title that I'd like to >> > > split into two lines, something like >> > > >> > > xyplot(<whatever>, >> > > main="The quick brown fox jumped\n over the lazy dog.") >> > > >> > > When I do this I only get the last half, i.e. the "over the lazy dog." >> > > bit, and the first half doesn't appear. >> > > >> > > In base graphics I'd handle this sort of thing by increasing the third >> > > entry of the "mar" parameter. >> > > >> > > How can increase the space allocated for the title in lattice graphics? >> > > I've done a substantial amount of Googling and can't find anything >> > > helpful. I've fiddled about with trellis.par.set() and cannot seem to >> > > get any effect. >> > > >> > > Could someone please give my poor feeble brain some guidance? Ta. >> > > >> > > cheers, >> > > >> > > Rolf Turner >> > > >> > > -- >> > > Honorary Research Fellow >> > > Department of Statistics >> > > University of Auckland >> > > Phone: +64-9-373-7599 ext. 88276 >> > > >> > > ______________________________________________ >> > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > > 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-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > 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-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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.
Rolf Turner
2020-Feb-13 09:02 UTC
[R] Increasing space for main title in a lattice (xyplot()) graphics.
On 13/02/20 6:16 pm, Deepayan Sarkar wrote:> On Thu, Feb 13, 2020 at 10:39 AM Richard M. Heiberger <rmh at temple.edu> wrote: >> >> It works as anticipated for me >> >>> xyplot(1 ~ 1, >> + main="The quick brown fox jumped\n over the lazy dog.") >>> xyplot(1 ~ 1, >> + main="The quick brown fox jumped over the lazy dog.") >> >> Something else you are doing is probably causing the difficulty. > > Yes, the necessary space should be automatically allocated. Details of > version / device might help diagnosing the problem. > > -DeepayanAaaarrrgghhh!!! The diagnosis of the problem was, as usual, trivial. It was all down to my overwhelming stupidity. I put together the main title by pasting together various bits --- and FORGOT to include the very first bit, which was the first line of the two-line title. (Smoke comes out of ears!!!) Took me hours, with accompanying hair loss, to track down that particular piece of stupidity. Tried everything except the obvious!!! Sorry for the noise. cheers (said he, not very cheerfully), Rolf -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276