Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
ok this is these are the final results: by relation free vs sliced vs scale component function relation free http://r.789695.n4.nabble.com/file/n4551068/relation_free.png relation sliced http://r.789695.n4.nabble.com/file/n4551068/relation_sliced.png scale component function http://r.789695.n4.nabble.com/file/n4551068/scale_component_function.png at the very end (I hope) of this troubled story I think the only approach can guarantee the full accomplishment of what I need is the last one by elai dealing with the scale component function; I've been reading of something alike in Sarkaar book (page 147) but I could not make it working thank you all for spending time in this thread, I've been learning a lot! bye max -- View this message in context: http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4551068.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
On Wed, Apr 11, 2012 at 7:16 AM, David Winsemius wrote: > > On Apr 11, 2012, at 9:03 AM, David Winsemius wrote: > >> >> On Apr 11, 2012, at 6:28 AM, maxbre wrote: >> >>> hi, I just realised I want to go a little further in the control of the >>> chart >>> appearance and I would like to have the same number of ticks displayed in >>> both axes of all panels >> >> I'm wondering if you should be using relation="free" when you have already >> set a panel specific range for the x and y limits? I'm thinking that the >> panel function may be reversing your earlier prepanel efforts. (No data >> offered ... why don't you use one of the many test datasets in the examples >> of the lattice package?) > > > On further meandering up this thread I see that you omitted the context of > earlier data offerings, so not I in turn offer what I think is a your > request. Change relation from "free" to "sliced" David, you make a good point. Seems OP's long and winding road {end quote} is slowly circling back to the origin (see the first couple of messages in thread). "slice" is better than "free", but isn't tick.number just a suggestion ? i.e. a better choice of n in ?pretty will override ? For example this data (below), barely noticeable, but see panel(2,1) has 7 ticks compare with 6 for the others. Any one please correct me (as I find I mess with these myself too often... :) but I think if OP wants to force equal ticks (and lose the "pretty" axis) there is no avoiding changes to x and yscale.components ? tm <- structure(list(name_short = structure(1:29, .Label = c("D4", "D5", "D6a", "D6b", "D6c", "D7", "D8", "F4", "F5a", "F5b", "F6a", "F6b", "F6c", "F6d", "F7a", "F7b", "F8", "P105", "P114", "P118", "P123", "P126", "P156", "P157", "P167", "P169", "P189", "P77", "P81"), class = "factor"), sub_family = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L), .Label = c("pcb mono-ortho subs", "pcb non-ortho subs", "pcdd", "pcdf"), class = "factor"), tv = c(1.069, 6.461, 5.461, 12.764, 10.86, 117.912, 256.875, 452.204, 124.02, 327.856, 88.469, 61.539, 17.794, 84.117, 121.668, 13.414, 68.409, 3023.333, 428, 19454.667, 151.333, 324, 11478.667, 1220.667, 5335.333, 124.667, 1542.667, 594.667, 193.333), ms = c(1.787, 4.831, 3.456, 14.105, 10.808, 116.02, 296.957, 30.533, 21.821, 32.969, 33.767, 29.799, 12.812, 49.637, 126.522, 17.522, 106.087, 1787.5, 130, 6751.5, 81, 23, 370, 33.5, 147.5, 5.406, 18.5, 415, 69.906)), .Names = c("name_short", "sub_family", "tv", "ms"), class = "data.frame", row.names = c(NA, -29L)) # changing to "sliced" xyplot(tv ~ ms | sub_family, data=tm, #as.table=TRUE, aspect="xy", xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), scales= list(x=list(relation="sliced", log=10, cex=0.8), y=list(relation="sliced", log=10, cex=0.8)), prepanel = function(x, y, subscripts) { rr<- range(cbind(x,y)) list(xlim = rr, ylim= rr) }, panel = function(x, y ,subscripts,...) { panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col ="gray") panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3, offset=0.5, srt=0, adj=c(1,1)) }, subscripts=TRUE, xscale.components = xscale.components.logpower, yscale.components = yscale.components.logpower ) # Compare with xyplot(tv ~ ms | sub_family, data=tm, #as.table=TRUE, aspect="xy", xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), scales= list(relation="free", log=10, cex=0.8), prepanel = function(x, y, subscripts) { rr<- range(cbind(x,y)) list(xlim = rr, ylim= rr) }, panel = function(x, y ,subscripts,...) { panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col ="gray") panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3, offset=0.5, srt=0, adj=c(1,1)) }, subscripts=TRUE, xscale.components = function(...) { ans <- xscale.components.logpower(...) range <- ans$num.limit newtck <- round(seq(range[1],range[2],l=7),1) ans$bottom$ticks$at <- newtck ans$bottom$labels$at <- newtck ans$bottom$labels$labels <- parse(text=paste('10^',newtck,sep='')) ans } , yscale.components = function(...) { ans <- yscale.components.logpower(...) range <- ans$num.limit newtck <- round(seq(range[1],range[2],l=7),1) ans$left$ticks$at <- newtck ans$left$labels$at <- newtck ans$left$labels$labels <- parse(text=paste('10^',newtck,sep=''))
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
Oh yes, I see now the problem... thank you max -- View this message in context: http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4549180.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
On Apr 11, 2012, at 9:03 AM, David Winsemius wrote: On Apr 11, 2012, at 6:28 AM, maxbre wrote: hi, I just realised I want to go a little further in the control of the chart appearance and I would like to have the same number of ticks displayed in both axes of all panels given this code xyplot(tv ~ ms | sub_family, data=tm, #as.table=TRUE, aspect="xy", xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), scales= list(x=list(relation="free", log=10, cex=0.8), y=list(relation="free", log=10, cex=0.8)), I'm wondering if you should be using relation="free" when you have already set a panel specific range for the x and y limits? I'm thinking that the panel function may be reversing your earlier prepanel efforts. (No data offered ... why don't you use one of the many test datasets in the examples of the lattice package?) On further meandering up this thread I see that you omitted the context of earlier data offerings, so not I in turn offer what I think is a your request. Change relation from "free" to "sliced" scales= list(x=list(relation="sliced", log=10, cex=0.8, tick.number=5), y=list(relation="sliced", log=10, cex=0.8, tick.number=5)) -- David. prepanel = function(x, y, subscripts) { rr<- range(cbind(x,y)) list(xlim = rr, ylim= rr) }, panel = function(x, y ,subscripts,...) { panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col ="gray") panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3, offset=0.5, srt=0, adj=c(1,1)) }, subscripts=TRUE, xscale.components = xscale.components.logpower, yscale.components = yscale.components.logpower ) ...I have been trying to insert in the 'prepanel' and also in the 'panel' the statement 'tick.number=5' but this does not seem to have any effect some useful hints for this? thanks a lot David Winsemius, MD West Hartford, CT __ R-help@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 __ R-help@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.
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
On Apr 11, 2012, at 6:28 AM, maxbre wrote: hi, I just realised I want to go a little further in the control of the chart appearance and I would like to have the same number of ticks displayed in both axes of all panels given this code xyplot(tv ~ ms | sub_family, data=tm, #as.table=TRUE, aspect="xy", xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), scales= list(x=list(relation="free", log=10, cex=0.8), y=list(relation="free", log=10, cex=0.8)), I'm wondering if you should be using relation="free" when you have already set a panel specific range for the x and y limits? I'm thinking that the panel function may be reversing your earlier prepanel efforts. (No data offered ... why don't you use one of the many test datasets in the examples of the lattice package?) prepanel = function(x, y, subscripts) { rr<- range(cbind(x,y)) list(xlim = rr, ylim= rr) }, panel = function(x, y ,subscripts,...) { panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col ="gray") panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3, offset=0.5, srt=0, adj=c(1,1)) }, subscripts=TRUE, xscale.components = xscale.components.logpower, yscale.components = yscale.components.logpower ) ...I have been trying to insert in the 'prepanel' and also in the 'panel' the statement 'tick.number=5' but this does not seem to have any effect some useful hints for this? thanks a lot David Winsemius, MD West Hartford, CT __ R-help@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.
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
hi, I just realised I want to go a little further in the control of the chart appearance and I would like to have the same number of ticks displayed in both axes of all panels given this code xyplot(tv ~ ms | sub_family, data=tm, #as.table=TRUE, aspect="xy", xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), scales= list(x=list(relation="free", log=10, cex=0.8), y=list(relation="free", log=10, cex=0.8)), prepanel = function(x, y, subscripts) { rr<- range(cbind(x,y)) list(xlim = rr, ylim= rr) }, panel = function(x, y ,subscripts,...) { panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col ="gray") panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3, offset=0.5, srt=0, adj=c(1,1)) }, subscripts=TRUE, xscale.components = xscale.components.logpower, yscale.components = yscale.components.logpower ) ...I have been trying to insert in the 'prepanel' and also in the 'panel' the statement 'tick.number=5' but this does not seem to have any effect some useful hints for this? thanks a lot -- View this message in context: http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4548502.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
yes elai, that's what I want! thank you for support maxbre -- View this message in context: http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4518205.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
On Thu, Mar 29, 2012 at 3:04 AM, maxbre wrote: > To answer your question: > - I did not put relation=’same’ because that is not what I want: i.e **for > each single panel** (in my case 4) I want to set the same limits for both x > and y axes (I want the diagonal line exactly bisect each panel); see what > happen by putting relation=’same’…(I do not want to group the panels by a > single x and y axes) > - I need to set the same number of thick arks for both x and y axes *of each > panel*, but with log scale it’s quite tricky at least seems so to myself) Oh. I missed the *for each panel* aspect of your question. I believe you are 5 key strokes away (the change is to prepanel). Is this what you want ? xyplot(tv ~ ms | sub_family, data=tm, #as.table=TRUE, aspect="xy", xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), scales= list(x=list(relation="free", log=10, cex=0.8), y=list(relation="free", log=10, cex=0.8)), prepanel = function(x, y, subscripts) { rr<- range(cbind(x,y)) list(xlim = rr, ylim= rr) }, panel = function(x, y ,subscripts,...) { panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col ="gray") panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3, offset=0.5, srt=0, adj=c(1,1)) }, subscripts=TRUE, xscale.components = xscale.components.logpower, yscale.components = yscale.components.logpower ) Cheers > > Thanks for your help > > max > > > -- > View this message in context: > http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4514868.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. __ R-help@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.
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
Elai Ok, this is my reproducible example tm<-structure(list(name_short = structure(1:29, .Label = c("D4", "D5", "D6a", "D6b", "D6c", "D7", "D8", "F4", "F5a", "F5b", "F6a", "F6b", "F6c", "F6d", "F7a", "F7b", "F8", "P105", "P114", "P118", "P123", "P126", "P156", "P157", "P167", "P169", "P189", "P77", "P81"), class = "factor"), sub_family = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L), .Label = c("pcb mono-ortho subs", "pcb non-ortho subs", "pcdd", "pcdf"), class = "factor"), tv = c(1.069, 6.461, 5.461, 12.764, 10.86, 117.912, 256.875, 452.204, 124.02, 327.856, 88.469, 61.539, 17.794, 84.117, 121.668, 13.414, 68.409, 3023.333, 428, 19454.667, 151.333, 324, 11478.667, 1220.667, 5335.333, 124.667, 1542.667, 594.667, 193.333), ms = c(1.787, 4.831, 3.456, 14.105, 10.808, 116.02, 296.957, 30.533, 21.821, 32.969, 33.767, 29.799, 12.812, 49.637, 126.522, 17.522, 106.087, 1787.5, 130, 6751.5, 81, 23, 370, 33.5, 147.5, 5.406, 18.5, 415, 69.906)), .Names = c("name_short", "sub_family", "tv", "ms"), class = "data.frame", row.names = c(NA, -29L)) and this is my code #start library(lattice) library(latticeExtra) xyplot(tv ~ ms | sub_family, data=tm, #as.table=TRUE, aspect="xy", xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), scales= list(x=list(relation="free", log=10, cex=0.8), y=list(relation="free", log=10, cex=0.8)), prepanel = function(x, y, subscripts) { list(xlim = c(min(x,y), max(x,y))) list(ylim= c(min(x,y), max(x,y))) }, panel = function(x, y ,subscripts,...) { panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col ="gray") panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3, offset=0.5, srt=0, adj=c(1,1)) }, subscripts=TRUE, xscale.components = xscale.components.logpower, yscale.components = yscale.components.logpower ) #end And here in attachment is the graphic output http://r.789695.n4.nabble.com/file/n4514868/output.png output.png To answer your question: - I did not put relation=’same’ because that is not what I want: i.e **for each single panel** (in my case 4) I want to set the same limits for both x and y axes (I want the diagonal line exactly bisect each panel); see what happen by putting relation=’same’…(I do not want to group the panels by a single x and y axes) - I need to set the same number of thick arks for both x and y axes *of each panel*, but with log scale it’s quite tricky at least seems so to myself) Thanks for your help max -- View this message in context: http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4514868.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)
On Wed, Mar 28, 2012 at 4:21 AM, maxbre wrote: > After a long and winding road (sorry but I'm a novice) I get to a final > result which is quite close to what I need; > nevertheless I would like to tweak a little further the xyplot Without dput(mydata) you are the only one who can do that... so that I can > get ***for each single panel defined by variable z*** a finer control over: > -the x and y the limits: I would like to be the same for both axes; relation='same' in the scales. BTW this is the default, why did you change to 'free' ? > -the number of thick marks: again I would like to be same for both axes; Most modifications of tick marks, labels and limits are easy through the scales argument. ?xyplot and examples. Best, Elai > > the (general) code snippet here attached does not get this result; > any help for this ? > > thank you > > > #my example > > xyplot(y ~ x | z, data=mydata, > aspect="xy", > scales= list(x=list(relation="free", log=10), > y=list(relation="free", log=10)), > > prepanel = function(x, y, subscripts) { > list(xlim = c(min(x,y), max(x,y))) > list(ylim= c(min(x,y), max(x,y))) > }, > > panel = function(x, y ,subscripts,...) { > #panel.xyplot(x, y, xlim = c(min(x,y), max(x,y)), ylim = > c(min(x,y), max(x,y)),...) > panel.xyplot(x, y, ...) > panel.abline(a = 0, b = 1, lty = 2, col ="gray") > panel.text(x, y, labels=mydata$name[subscripts]) > }, > > subscripts=TRUE, > xscale.components = xscale.components.logpower, > yscale.components = yscale.components.logpower > ) > > in attachment http://r.789695.n4.nabble.com/file/n4511897/my_example.png > my_example.png > > -- > View this message in context: > http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4511897.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. __ R-help@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.
[R] xyplot lattice fine control of axes limits and thick marks (with log scale)
After a long and winding road (sorry but I'm a novice) I get to a final result which is quite close to what I need; nevertheless I would like to tweak a little further the xyplot so that I can get ***for each single panel defined by variable z*** a finer control over: -the x and y the limits: I would like to be the same for both axes; -the number of thick marks: again I would like to be same for both axes; the (general) code snippet here attached does not get this result; any help for this ? thank you #my example xyplot(y ~ x | z, data=mydata, aspect="xy", scales= list(x=list(relation="free", log=10), y=list(relation="free", log=10)), prepanel = function(x, y, subscripts) { list(xlim = c(min(x,y), max(x,y))) list(ylim= c(min(x,y), max(x,y))) }, panel = function(x, y ,subscripts,...) { #panel.xyplot(x, y, xlim = c(min(x,y), max(x,y)), ylim = c(min(x,y), max(x,y)),...) panel.xyplot(x, y, ...) panel.abline(a = 0, b = 1, lty = 2, col ="gray") panel.text(x, y, labels=mydata$name[subscripts]) }, subscripts=TRUE, xscale.components = xscale.components.logpower, yscale.components = yscale.components.logpower ) in attachment http://r.789695.n4.nabble.com/file/n4511897/my_example.png my_example.png -- View this message in context: http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4511897.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.