This worked very well for me.
Thanks, Naresh ________________________________ From: P Tennant <philipt...@iinet.net.au> Sent: Saturday, November 5, 2016 7:57 PM To: Naresh Gurbuxani Cc: R-help@r-project.org Subject: Re: [R] lattice graph with free scales and reversed axis values Hi Naresh, You could calculate the ranges explicitly and then supply to scales(): holdRange <- vector('list', length(unique(my.df$name))) for(i in 1:length(holdRange)){ holdRange[[i]] <- rev(range(my.df$x[my.df$name==unique(my.df$name)[i]])) } holdRange # [[1]] # [1] -5.052890 -9.967671 # [[2]] # [1] 2.648870 -2.629866 xyplot(y ~ x | name, data = my.df, type = c("p", "g"), scales = list(relation="free", limits=holdRange)) Philip On 6/11/2016 9:59 AM, Naresh Gurbuxani wrote: > I want to draw a lattice graph where different panels have different ranges > AND the order of values is reversed. I am struggling to achieve both at the > same time. Can you help? > > Thanks, > Naresh > > # Create dummy data for illustration > my.df<- data.frame(x = runif(100, min = -10, max = -5), name = "A") > my.df<- rbind(my.df, data.frame(x = rnorm(100), name = "B")) > my.df<- within(my.df, {y<- x + 0.2 * rnorm(200)}) > > # This works. Both x and y axes show values in reverse order. > xyplot(y ~ x, groups = name, data = my.df, xlim = rev(range(my.df$x)), ylim = > rev(range(my.df$y)), type = c("p", "g")) > > # This works. Both x and y axes show values in reverse order. > xyplot(y ~ x | name, data = my.df, xlim = rev(range(my.df$x)), ylim = > rev(range(my.df$y)), type = c("p", "g")) > > # This does not work as intended. x and y values are in reverse order. But > both panels have the same and x and y ranges. scales argument does not seem > to have any effect. > xyplot(y ~ x | name, data = my.df, xlim = rev(range(my.df$x)), ylim = > rev(range(my.df$y)), scales = list(x = "free", y = "free"), type = c("p", > "g")) > > # This does not work at all. panel.xyplot does not see to take xlim or ylim > arguments. > xyplot(y ~ x | name, data = my.df, scales = list(x = "free", y = "free"), > panel = function(x,y,subscripts, ...) { > panel.xyplot(x,y, ylim = rev(range(y[subscripts]), xlim = > rev(range(x[subscripts])))) > }) > > ______________________________________________ > R-help@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]] ______________________________________________ R-help@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.