Dear all, I have a question about the lattice package, more specifically about the control of the x-axis length in the different panels. I use the following code to make the stacked barchart: barchart(country ~ climatechangefocalpoint + meteorologyservice + adaptationorvulnerability + cdmcarbonmarkets + energy + aviationmaritimetransport + forestry + pressofficer|period, data=graph5, as.table=T, xlim=c(0,150), layout=c(3,1), par.strip.text=list(cex=1.5), scales = list(alternating = 3, cex=1.2, tick.number=5), xlab="", col=c("grey15","grey75","grey30","grey90","grey45","grey0","grey60","grey100"), #col=c(grey(100:1/100), grey(50:1/100), grey(0:1/100)), stack=T) Unfortunately, in the first two periods there are much less data, hence the bars are much shorter in those two panels and most of the space is unused, as the axis still run to 150 as for the last panel. Does anyone know how to cut the x-axis for the first two panels at, say, 50, while leaving it for the third panel as it is? Google and looking through old conversations here didn't help me, so I'm not quite sure whether this is possible at all. Thanks and best, Florian -- View this message in context: http://r.789695.n4.nabble.com/Lattice-different-axis-length-tp4364450p4364450.html Sent from the R help mailing list archive at Nabble.com.
Hi, set scales=list(x=list(relation='free')) may help. Weidong Gu On Tue, Feb 7, 2012 at 6:42 AM, Florian Weiler <fweiler08 at jhubc.it> wrote:> Dear all, > > I have a question about the lattice package, more specifically about the > control of the x-axis length in the different panels. I use the following > code to make the stacked barchart: > > barchart(country ~ climatechangefocalpoint + meteorologyservice + > adaptationorvulnerability + cdmcarbonmarkets + ?energy + > aviationmaritimetransport + ? ? forestry + ? ? ?pressofficer|period, data=graph5, > ? ? ? ? as.table=T, > ? ? ? ? xlim=c(0,150), > ? ? ? ? layout=c(3,1), > ? ? ? ? par.strip.text=list(cex=1.5), > ? ? ? ? scales = list(alternating = 3, cex=1.2, tick.number=5), > ? ? ? ? xlab="", > > col=c("grey15","grey75","grey30","grey90","grey45","grey0","grey60","grey100"), > ? ? ? ? #col=c(grey(100:1/100), grey(50:1/100), grey(0:1/100)), > ? ? ? ? stack=T) > > Unfortunately, in the first two periods there are much less data, hence the > bars are much shorter in those two panels and most of the space is unused, > as the axis still run to 150 as for the last panel. Does anyone know how to > cut the x-axis for the first two panels at, say, 50, while leaving it for > the third panel as it is? Google and looking through old conversations here > didn't help me, so I'm not quite sure whether this is possible at all. > > Thanks and best, > Florian > > -- > View this message in context: http://r.789695.n4.nabble.com/Lattice-different-axis-length-tp4364450p4364450.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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 Feb 7, 2012, at 6:42 AM, Florian Weiler wrote:> Dear all, > > I have a question about the lattice package, more specifically about > the > control of the x-axis length in the different panels. I use the > following > code to make the stacked barchart: > > barchart(country ~ climatechangefocalpoint + meteorologyservice + > adaptationorvulnerability + cdmcarbonmarkets + energy + > aviationmaritimetransport + forestry + pressofficer|period, > data=graph5, > as.table=T, > xlim=c(0,150), > layout=c(3,1), > par.strip.text=list(cex=1.5), > scales = list(alternating = 3, cex=1.2, tick.number=5), > xlab="", > > col > = > c > ("grey15 > ","grey75","grey30","grey90","grey45","grey0","grey60","grey100"), > #col=c(grey(100:1/100), grey(50:1/100), grey(0:1/100)), > stack=T) > > Unfortunately, in the first two periods there are much less data, > hence the > bars are much shorter in those two panels and most of the space is > unused, > as the axis still run to 150 as for the last panel. Does anyone know > how to > cut the x-axis for the first two panels at, say, 50, while leaving > it for > the third panel as it is? Google and looking through old > conversations here > didn't help me, so I'm not quite sure whether this is possible at all.in the scales list you could add: y=list(relation="free") ?xyplot and look at the relation sub-section in the scales section for more information.> > Thanks and best, > Florian > > -- > View this message in context: http://r.789695.n4.nabble.com/Lattice-different-axis-length-tp4364450p4364450.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
Thanks a lot for your help! I found that the relation="free" command was very helpful, but then I had a little space between the axis and where the bars actually begun. I tried to deal with it in a panel function but was unable to do so. However, I found a way providing a list to xlim: barchart(country ~ new + cdmcarbonmarkets + energy + aviationmaritimetransport + forestry|period, data=graph5, as.table=T, layout=c(3,1), par.strip.text=list(cex=1.5), * xlim=list(c(.7,10),c(.8,12),c(8,130)), scales = list(alternating = 3, cex=1.2,x=list(relation="free")),* xlab="", col=c("grey25","grey75","grey0","grey100","grey50"), stack=T) Oddly enough, I had to play around with the initial value to make the gap go away. The above code now produces exactly what I want (i.e. the bar start at 0 and have the right length). I do not really know why this is the case though. I would have expected the bars to be too short??? Still, I am happy with the result and thank you again for you help -- View this message in context: http://r.789695.n4.nabble.com/Lattice-different-axis-length-tp4364450p4364948.html Sent from the R help mailing list archive at Nabble.com.