Manuel Kunz
2013-Feb-25 15:47 UTC
[R] lattice: column titles using xlab.top in multipanel xyplot
Hi, I created a xyplot with a three-column layout. As suggested by Deepayan I tried to put titles to each column by using xlab.top. Unfortunately, as my y-axis scale relation = "free", the column titles are not centered at the three x axes anymore. Any idea how to center the titles? #Example: require(lattice) #require(latticeExtra) e <- data.frame(a = c(1:30), b = c(1:10, 20:29, 990:999), d = c(rep("A", 10), rep("B", 10), rep("C", 10))) #column titles centered for relation = "same" xyplot(b ~ a | d, e, scales = list(y = list(relation = "same", rot = 0)), aspect = 1.8, layout = c(3, 1), xlab.top = c("This is centered", "Bla", "Bla") ) #column titles not centered for relation = "free" xyplot(b ~ a | d, e, scales = list(y = list(relation = "free", rot = 0)), aspect = 1.8, layout = c(3, 1), xlab.top = c("This is not centered", "Bla", "Bla") ) # end of example Best regards, manuel
Duncan Mackay
2013-Feb-25 21:34 UTC
[R] lattice: column titles using xlab.top in multipanel xyplot
Hi manuel Have a look at http://tolstoy.newcastle.edu.au/R/e2/help/07/05/17666.html Just plugging in your xlabs everything is OK for Deepayan's example xyplot(1:9 ~ 1:9 | gl(3, 1, 9), layout = c(3, 1), xlab = myXlabGrob('Trial number', 'Subject number', 'Experimental condition'), strip = FALSE ) But when I use myXlabGrob to your example the labels are not centered xyplot(b ~ a | d, e, scales = list(y = list(relation = "free", rot = 0)), aspect = 1.8, layout = c(3, 1), strip = F, xlab.top = myXlabGrob('Trial number', 'Subject number', 'Experimental condition') ) Is there something extra you can do with xlab.top? Otherwise you could do it with grid.text but that is a bit of a pain. HTH GTG Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mackay at northnet.com.au At 01:47 26/02/2013, you wrote:>Hi, > >I created a xyplot with a three-column layout. As suggested by >Deepayan I tried to put titles to each column by using xlab.top. >Unfortunately, as my y-axis scale relation = "free", the column >titles are not centered at the three x axes anymore. Any idea how to >center the titles? > >#Example: >require(lattice) >#require(latticeExtra) >e <- data.frame(a = c(1:30), b = c(1:10, 20:29, 990:999), > d = c(rep("A", 10), rep("B", 10), rep("C", 10))) >#column titles centered for relation = "same" >xyplot(b ~ a | d, e, > scales = list(y = list(relation = "same", rot = 0)), > aspect = 1.8, layout = c(3, 1), > xlab.top = c("This is centered", "Bla", "Bla") > ) >#column titles not centered for relation = "free" >xyplot(b ~ a | d, e, > scales = list(y = list(relation = "free", rot = 0)), > aspect = 1.8, layout = c(3, 1), > xlab.top = c("This is not centered", "Bla", "Bla") > ) ># end of example > >Best regards, >manuel > >______________________________________________ >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.
Peter Ehlers
2013-Feb-25 22:35 UTC
[R] lattice: column titles using xlab.top in multipanel xyplot
On 2013-02-25 07:47, Manuel Kunz wrote:> Hi, > > I created a xyplot with a three-column layout. As suggested by Deepayan I tried to put titles to each column by using xlab.top. Unfortunately, as my y-axis scale relation = "free", the column titles are not centered at the three x axes anymore. Any idea how to center the titles? > > #Example: > require(lattice) > #require(latticeExtra) > e <- data.frame(a = c(1:30), b = c(1:10, 20:29, 990:999), > d = c(rep("A", 10), rep("B", 10), rep("C", 10))) > #column titles centered for relation = "same" > xyplot(b ~ a | d, e, > scales = list(y = list(relation = "same", rot = 0)), > aspect = 1.8, layout = c(3, 1), > xlab.top = c("This is centered", "Bla", "Bla") > ) > #column titles not centered for relation = "free" > xyplot(b ~ a | d, e, > scales = list(y = list(relation = "free", rot = 0)), > aspect = 1.8, layout = c(3, 1), > xlab.top = c("This is not centered", "Bla", "Bla") > ) > # end of example > > Best regards, > manuelIf this is a one-off, then I would just add a sufficient number of spaces, obtained by trial and error, to each label. On the other hand, why not use lattice's built-in facility to put your labels in the top strips, using the factor.levels argument. But perhaps your real use is more involved than the example. Peter Ehlers
Possibly Parallel Threads
- xlab at top in xyplot()
- Using Lattice, LatticeExtra - Hide right and top axes in multipanel plots
- lattice: aligning independent graphs
- ylab spacing in resizePanels in latticeExtra
- drawing a line indicating extent of each factored data series in multipanel lattice xyplot