Re: [R] corrgram with two datasets
?pairs On Thu, Jun 27, 2013 at 2:48 AM, Meesters, Aesku.Kipp Institute meest...@aesku-kipp.com wrote: Hi, I would like to display inter-parameter scatter plots like those with the corrgram package (see upper triangle here: http://www.statmethods.net/advgraphs/images/corrgram2.png ), just that I would like to plot two datasets instead of one. Say one with black and one with red dots. Or a merged dataset where an indicator column is used to assign different colors to particular dots - with still the same layout. Is there a method to generate such a plots around? TIA Christian [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] Optim seems not to work properly in foreach
On Mon, Jun 3, 2013 at 11:37 AM, Simon Zehnder szehn...@uni-bonn.de ... [Some not minimal, self contained, reproducible code]... Data simulation and thecreation of startpar works fine, but the parameters in res$par are always the start parameters. If I run the same commands directly on the shell I get in res$par the optimized parameters - only inside the foreach loop optim seems not to work. What could that be? Don't know, but but this makes me doubt it has anything to do with optim being inside foreach: fr - function(x) { x1 - x[1] ; x2 - x[2] 100 * (x2 - x1 * x1)^2 + (1 - x1)^2 } grr - function(x) { x1 - x[1] ; x2 - x[2] c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1) , 200 * (x2 - x1 * x1)) } library(doMC) registerDoMC(2) RNGkind(L'Ecuyer) set.seed(54321) foreach(i = 1:2) %do% { ret - foreach(j = 1:2) %do%{ strtpar - c(-2,2)+rnorm(2) optim(strtpar, fr, grr, method = L-BFGS-B,control=list(trace=TRUE))$par } ret } Also, wouldn't you want to register 4 cores by default if nesting 2 loops of 2 ? (to comment on the wisdom of doing so in terms of overhead is beyond my expertise) HTH Best Simon __ 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. [[alternative HTML version deleted]] __ 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] highlight points in lattice cloud plot
On Wed, May 29, 2013 at 7:57 AM, Stefan Lüdtke slued...@gfz-potsdam.dewrote: x=runif(100, 1, 2) y=runif(100, 2, 4) z=runif(100, 1, 4) data_xyz=as.data.frame(cbind(x, y, z, a=rep(c(1:10), 10), b=rep(c(1:2), each=50))) custom.panel = function(x, y, z, subscripts, ...) { highlight=(data_xyz$a == 1) highlight.panel = highlight[subscripts] panel.cloud(x[highlight.panel], y[!highlight.panel], z[!highlight.panel], type='p', pch=18) panel.cloud(x[highlight.panel], y[highlight.panel], z[highlight.panel], type='b', col=tomato3) } If you args(panel.cloud) or ?panel.cloud you'll notice the order is x , y , subscripts , z ,... *not* x,y,z, hence the error message z not found or something to that effect you should have been getting. In any case you're code is IMHO a little clunky with groups=TRUE and a panel function just to get the groups condition. Would something like this do the job? cloud(z~x*y|b, groups=factor(a==1), data=data_xyz, pch=c(1,19), type='b', par.settings=list(superpose.line=list(col=c(0,#ff00ff #that works of course cloud(z~x*y|b, data=data_xyz) #that not cloud(z~x*y|b, data=data_xyz, groups=TRUE, panel=custom.panel) ## On 05/29/2013 03:36 PM, John Kane wrote: No attachment. The R-help list tendst to strip out many type of attached files though pdf and txt , among others get through. It is better to supply the example in the email itself if possible. Have a look at https://github.com/hadley/devtools/wiki/Reproducibility for suggestions. John Kane Kingston ON Canada -Original Message- From: slued...@gfz-potsdam.de Sent: Tue, 28 May 2013 15:50:33 -0700 (PDT) To: r-help@r-project.org Subject: [R] highlight points in lattice cloud plot Dear list, I am struggling with the following problem. In a 2d case I managed to highlight a subset of points through the panel.xyplot function. However, I was trying the same in 3d using panel.cloud, but now luck. I attached a minimal example, I think the first plot shows the idea. Thanks, Stefan -- View this message in context: http://r.789695.n4.nabble.com/highlight-points-in-lattice-cloud-plot-tp4668157.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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] query in plot(intervals....
On Tue, May 14, 2013 at 10:05 AM, Michelle Morters mm...@hermes.cam.ac.ukwrote: Hi - I would like the plot ordered by intercept. One way will be to tweak the ?intervals.lmList object require(nlme) fm1 - intervals(lmList(distance ~ age | Subject, Orthodont)) fm2 - fm1[order(fm1[,2,1]),,] class(fm2) - class(fm1) plot(fm2) Next time please, *you* provide the reproducible example... Ordering is doable if the intervals function is substituted with the confint function and order=1 included. Is ordering doable with intervals function, please? Thanks! M results-lmList(x~slope|id,data) plot(intervals(results)) [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] 3D Histograms on a Geographical Map
Also combining the code for figures 6.5, 13.8 and 13.9 in the following link http://lmdvr.r-forge.r-project.org/figures/figures.html gets you there. On Fri, Apr 19, 2013 at 8:38 AM, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote: On Fri, Apr 19, 2013 at 3:13 PM, Lorenzo Isella lorenzo.ise...@gmail.com wrote: Dear All, I like very much figure 2.a) and 2.b) of this paper http://www.nature.com/srep/2013/130410/srep01640/pdf/srep01640.pdf and I probably need a similar visualization. Is anything like that doable in R? I have some experience with R and gadm (gadm.org), but that is only to produce maps colored according to a scalar. I do not know how to visualize maps with a perspective, let alone adding the histograms in 3D. Sorry for not providing an example script, but if I had one I would not be posting at all. The panel B maps are created by using R so they are definitely doable in R. I suspect they are using the rgl package for 3d graphics. You just have to get the country outline data, give it a Z of 0, draw it using the rgl 3d line functions, then add the bars (they're not histograms) by starting at (x,y,0) and drawing a 3d line to (x,y,H) for each value of H. You might try asking on R-sig-geo for more on mapping stuff with R. Clearly my papers don't have enough 3d nonsense graphics to get into Nature... Barry __ 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. [[alternative HTML version deleted]] __ 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] densityplot(~x+y) for vectors of different lengths does what?
Hmmm... is this a (unknown or even a) bug ? Not sure this is what OP was getting at and I haven't gone through the lattice docs to see if this is mentioned, but, with unequal sizes the extended formula is not producing what one (or at least I) might expect: require(latticeExtra) set.seed(4321) ; x - rnorm(20) ; y - rnorm(10 , 50) c(dsp - densityplot( ~ x + y) , densityplot( ~ data , groups = which , make.groups(x, y) ) ) # because all.equal(dsp$panel.args[[1]]$x, c(x, y) ) # but regroups ignoring original lengths summary(dsp$panel.args.common$groups) An obvious BTW: problem persists using n={19,11} or n = {20,11} sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-linux-gnu (64-bit) attached base packages: [1] grDevices utils datasets stats graphics methods base other attached packages: [1] nlme_3.1-104latticeExtra_0.6-24 RColorBrewer_1.0-5 [4] lattice_0.20-10 On Wed, Feb 13, 2013 at 6:38 AM, Michael Stob s...@calvin.edu wrote: densityplot(~x+y) does what I expect it to do if x and y have equal length. I know how to get what I want if x and y have different lengths. But what is this actually doing if x and y have different lengths?The relevant example is x=rnorm(10) y=rnorm(50,1) densityplot(~x+y) __ 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. [[alternative HTML version deleted]] __ 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] Border width on symbols plotted with the lattice package
Like this ? xyplot(4:5~4:5, groups=4:5, lex = 5 , par.settings = simpleTheme(cex=10, pch=21, lwd=5), auto.key=TRUE) On Fri, Feb 8, 2013 at 6:46 AM, Karl Ove Hufthammer k...@huftis.org wrote: Dear list members, I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice' package to respect the 'lwd' value for specifying the border with for *symbols* (for lines it works fine). Example: - # Base graphics works fine (gives a 'fat circle) plot(5, cex=10, pch=21, lwd=10) # But 'xyplot' or 'dotplot' doesn't library(lattice) xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21, lwd=5), auto.key=TRUE) - For 'xyplot' or 'dotplot' the border stays thin no matter what I set 'lwd' to. However, the symbols shown in the *legend* has the 'lwd' correctly applied. How can I fix this? Or is it simply a bug in the 'lattice' package? Karl Ove Hufthammer Output of 'sessionInfo()': R version 2.15.2 (2012-10-26) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Norwegian-Nynorsk_**Norway.1252 [2] LC_CTYPE=Norwegian-Nynorsk_**Norway.1252 [3] LC_MONETARY=Norwegian-Nynorsk_**Norway.1252 [4] LC_NUMERIC=C [5] LC_TIME=Norwegian-Nynorsk_**Norway.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.20-13 loaded via a namespace (and not attached): [1] grid_2.15.2 tools_2.15.2 __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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 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] Border width on symbols plotted with the lattice package
On Fri, Feb 8, 2013 at 10:14 AM, David Winsemius dwinsem...@comcast.netwrote: On Feb 8, 2013, at 8:55 AM, ilai wrote: Like this ? xyplot(4:5~4:5, groups=4:5, lex = 5 , par.settings = simpleTheme(cex=10, pch=21, lwd=5), auto.key=TRUE) And if I had used a more general search strategy I might have found it, too, rather than hacking my way to a less adequate solution; less adequate in the sense of no supporting a proper coloring of points. http://markmail.org/search/?q=list%3Aorg.r-project.r-help+xyplot+points++lwd On the other hand this solution has possibly undesireable effects on the key symbols. Not sure I follow you, but lex (among others) is described in ?grid::gpar which indeed may not be pointed to by lattice docs - took the hint from an old posting myself. -- On Fri, Feb 8, 2013 at 6:46 AM, Karl Ove Hufthammer k...@huftis.org wrote: Dear list members, I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice' package to respect the 'lwd' value for specifying the border with for *symbols* (for lines it works fine). Example: - # Base graphics works fine (gives a 'fat circle) plot(5, cex=10, pch=21, lwd=10) # But 'xyplot' or 'dotplot' doesn't library(lattice) xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21, lwd=5), auto.key=TRUE) - For 'xyplot' or 'dotplot' the border stays thin no matter what I set 'lwd' to. However, the symbols shown in the *legend* has the 'lwd' correctly applied. How can I fix this? Or is it simply a bug in the 'lattice' package? Karl Ove Hufthammer Output of 'sessionInfo()': R version 2.15.2 (2012-10-26) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Norwegian-Nynorsk_**Norway.1252 [2] LC_CTYPE=Norwegian-Nynorsk_**Norway.1252 [3] LC_MONETARY=Norwegian-Nynorsk_**Norway.1252 [4] LC_NUMERIC=C [5] LC_TIME=Norwegian-Nynorsk_**Norway.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.20-13 loaded via a namespace (and not attached): [1] grid_2.15.2 tools_2.15.2 __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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 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 Alameda, CA, USA [[alternative HTML version deleted]] __ 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] Remove and add to many matrices in list.
1) We don't have your previous email and I doubt anyone here committed your code to memory 2) No offense but this post is still an eye sore. Actually I am guessing even worse than the first because there is no working example. The idea is to provide *minimal* code that reproduces the problem - without extra info/functionality (setting attributes, stages of the simulation not needed etc.). 3) There is (still ?) important info missing like what does fail mean ? with what error ? at what stage of the simulation (initialization ? last stage ? different iteration every time ? ). 4) Your pseudo-code is worthless as any number of things can go wrong, for e.g. (but not limited to): consider your statement which.duplicate - sample(ncol(matrix[[I]], number.to.delete, replace=F) a) number.to.delete/duplicate is not an integer b) missing a closing on ncol(), c) supposed to be number.to.duplicate d) ncol(matrix[[I]]) is less than number.to.delete/duplicate ... 5) In the mean time, you could try adding print statements to different objects in your function so if it is the random component in the simulation causing the fail, you'll see the origin (e.g. prop.to.delete == 1). HTH On Tue, Feb 5, 2013 at 4:42 AM, Benjamin Ward (ENV) b.w...@uea.ac.ukwrote: Hi all, I realised that my last email question and code was probably going to be a bit of an eyesore for some people and that perhaps the best thing for me to do is to pose the question of what it is I want to achieve, rather than what I've written, if it helps people: I'm writing a simulation, and during that simulation I have a list of matrices of variable number of columns. For every matrix in this list I want to randomly select a proportion of them for removal from the matrix, and a proportion for duplication. Proportions of columns to be duplicated of deleted are set out in a n by 2 matrix: Delete Duplicate 0.99 0.43 0.340.32 0.540.56 .. And so on. So for each matrix in the list of matrices, I want to: * Calculate the number of columns to be deleted or duplicated: something like * number.to.delete - ncol(matrix list[[I]])*proportionsmatrix[I,1] * number.to.duplicate - ncol(matrix list[[I]])*proportionsmatrix[I,2] * Then I want to sample the columns to be deleted, and those to be copied : something like: * which.delete - sample(ncol(matrix[[I]], number.to.delete, replace=F) * which.duplicate - sample(ncol(matrix[[I]], number.to.delete, replace=F) * Then I want to make the new matrices: something like: * new.matrices- matrix[,-which.delete] * new.matrices-cbind(new.matrices, matrix[,which.duplicate] From my previous email you'll see I did this by making a function which will do this for one matrix out of the entire list, and the applying the function to the entire list with lapply. Which works when I copy and paste the code into R with usable data, but as part of the simulation it fails. This is strange since I do other similar operations on these matrices without problem, with the same method of indexing. Debug() and running the sim step by step the data does not appear to be altered such that would affect the function. Best, Ben. [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] glm poisson and quasipoisson
On Thu, Jan 31, 2013 at 2:13 PM, Wim Kreinen wkrei...@gmail.com wrote: Hello, I have a question about modelling via glm. I think you are way off track. Either the data, glm, or both, are not what you think they are. I have a dataset skn300.tab - structure(list(n = 1:97, freq = c(0L, 0L, 0L, 0L, 1L, 7L, 40L, 100L, 276L, 543L, 952L, 1414L, 1853L, 2199L, 2435L, 2270L, 2042L, 1679L, 1386L, 1108L, 922L, 792L, 642L, 597L, 453L, 424L, 370L, 297L, 278L, 218L, 208L, 172L, 174L, 149L, 124L, 98L, 98L, 67L, 78L, 67L, 46L, 34L, 31L, 42L, 34L, 21L, 28L, 18L, 18L, 18L, 10L, 19L, 6L, 9L, 10L, 6L, 6L, 5L, 3L, 9L, 4L, 3L, 4L, 5L, 2L, 6L, 4L, 2L, 2L, 3L, 3L, 0L, 0L, 0L, 0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 2L, 1L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 1L), kum = c(0L, 0L, 0L, 0L, 1L, 8L, 48L, 148L, 424L, 967L, 1919L, L, 5186L, 7385L, 9820L, 12090L, 14132L, 15811L, 17197L, 18305L, 19227L, 20019L, 20661L, 21258L, 21711L, 22135L, 22505L, 22802L, 23080L, 23298L, 23506L, 23678L, 23852L, 24001L, 24125L, 24223L, 24321L, 24388L, 24466L, 24533L, 24579L, 24613L, 24644L, 24686L, 24720L, 24741L, 24769L, 24787L, 24805L, 24823L, 24833L, 24852L, 24858L, 24867L, 24877L, 24883L, 24889L, 24894L, 24897L, 24906L, 24910L, 24913L, 24917L, 24922L, 24924L, 24930L, 24934L, 24936L, 24938L, 24941L, 24944L, 24944L, 24944L, 24944L, 24944L, 24946L, 24947L, 24947L, 24947L, 24947L, 24947L, 24947L, 24948L, 24948L, 24948L, 24949L, 24951L, 24952L, 24952L, 24952L, 24952L, 24952L, 24954L, 24954L, 24954L, 24954L, 24955L)), .Names = c(n, freq, kum), row.names = c(NA, -97L), class = data.frame) that looks like as if it where poisson distributed (actually I would appreciate that) but it isnt plot(skn300.tab) My guess, we are looking at the pdf and cdf (maybe even of a Poisson process), but not at any data that lends itself to a (generalized) linear model. Consult a statistician, post on stackexchange, read about regression, or better define your actual R problem here, demonstrating this is not homework - see the posting guide. Cheers because mean unequals var. mean (x) [1] 901.7827 var (x) [1] 132439.3 Anyway, I tried to model it via poisson and quasipoisson. Actually, just to get an impression how glm works. But I dont know how to interprete the data. Of course this is the case because my knowledge concerning logistic regressions is rather limited. Hoping there is somebody with mercy I would like to understand which parameters are important, e.g. which paramter might give me a hint that a poisson model is a bad idea. For hints concerning some tutorials about reading glm-output I would appreciate as well. Thanks Wim skn300.glmp - glm (freq~n, data=skn300.tab, family=poisson) summary (skn300.glmp) Call: glm(formula = freq ~ n, family = poisson, data = skn300.tab) Deviance Residuals: Min 1Q Median 3Q Max -51.332 -9.383 -6.599 -3.959 55.111 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 7.2374375 0.0093285 775.8 2e-16 *** n -0.0539424 0.0003699 -145.8 2e-16 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 71731 on 96 degrees of freedom Residual deviance: 37383 on 95 degrees of freedom AIC: 37800 Number of Fisher Scoring iterations: 6 skn300.glmq - glm (freq~n, data=skn300.tab, family=quasipoisson) summary (skn300.glmq) Call: glm(formula = freq ~ n, family = quasipoisson, data = skn300.tab) Deviance Residuals: Min 1Q Median 3Q Max -51.332 -9.383 -6.599 -3.959 55.111 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 7.237438 0.186381 38.831 2e-16 *** n -0.053942 0.007391 -7.298 8.8e-11 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 (Dispersion parameter for quasipoisson family taken to be 399.1874) Null deviance: 71731 on 96 degrees of freedom Residual deviance: 37383 on 95 degrees of freedom AIC: NA Number of Fisher Scoring iterations: 6 dput (skn300.tab) structure(list(n = 1:97, freq = c(0L, 0L, 0L, 0L, 1L, 7L, 40L, 100L, 276L, 543L, 952L, 1414L, 1853L, 2199L, 2435L, 2270L, 2042L, 1679L, 1386L, 1108L, 922L, 792L, 642L, 597L, 453L, 424L, 370L, 297L, 278L, 218L, 208L, 172L, 174L, 149L, 124L, 98L, 98L, 67L, 78L, 67L, 46L, 34L, 31L, 42L, 34L, 21L, 28L, 18L, 18L, 18L, 10L, 19L, 6L, 9L, 10L, 6L, 6L, 5L, 3L, 9L, 4L, 3L, 4L, 5L, 2L, 6L, 4L, 2L, 2L, 3L, 3L, 0L, 0L, 0L, 0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 2L, 1L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 1L), kum = c(0L, 0L, 0L, 0L, 1L, 8L, 48L, 148L, 424L, 967L, 1919L, L, 5186L, 7385L, 9820L, 12090L, 14132L, 15811L, 17197L, 18305L, 19227L, 20019L, 20661L, 21258L, 21711L, 22135L, 22505L, 22802L, 23080L, 23298L, 23506L, 23678L, 23852L, 24001L,
Re: [R] different legends in lattice panels
On Sat, Jan 26, 2013 at 10:26 AM, Tito de Morais Luis luis.tito-de-mor...@ird.fr wrote: Hi listers, I want to make lattice plots xyplots with the indication of legends inside each panel with only the points and the lines actually ploted inside each given panel according to the group(ing) factor. The code below shows what I have achieved so far and I hope will make clear what I want to have. It seems to me that my solution is a very dirty hack and there certainly is a much simple and clean way to do it. Besides, there is no concordance in lty and pch between the legend above the graph with those inside the panels. No. Look again. It is your panel legends that don't correspond to the actual plot. The plot symbols and line types for the chosen theme != pch[1:10] and lty[1:10]. You can either explicitly set the pch and lty in the plot and auto.key to be 1:10 and proceed with trellis.focus or insert draw.key in the panel function to automate the procedure and query the groups and graphical parameters of each panel : xyplot(lbt ~ de | type, data=dataf, groups =sta, type=c(p,g,r), layout=c(4,1), par.settings = standard.theme(color = FALSE), auto.key=list(space=top, columns=5, lines=TRUE), panel=function(x,y,groups,subscripts,...){ panel.xyplot(x,y,groups=groups,subscripts=subscripts,...) pug - levels(groups)[levels(groups)%in%groups[subscripts]] draw.key(key=list(text = list(as.character(pug)), lines = list(lty = rep(trellis.par.get('superpose.line')$lty,10)[as.numeric(pug)]), points = list(pch = rep(trellis.par.get('superpose.symbol')$pch,10)[as.numeric(pug)]) ), draw=TRUE , vp=viewport(x=0.25,y=0.9)) }) HTH I have searched the archive and the web and found some hints that helped me a lot to write the code below. But I am not very familiar with lattice trellis graphs and I am sure that I am missing something. I would appreciate any suggestion that will help me to improve this. Thank you in advance, Tito require(lattice) require(grid) # some random data lbt - abs(rnorm(100)) # any biological value de - rep(1:10,10) # the depth type - rep(c(A,C,F,S), c(20,30,40,10)) # the type of sampling zone sta - as.factor(rep(1:10, c(10,10,10,10,10,10,10,10,10,10))) # the station number dataf - data.frame(lbt,de,type,sta) # the dataframe # key creation keyA - list(border = FALSE, text = list(levels(dataf$sta)[1:2]),lines=TRUE,points=TRUE,lty=c(1:2),pch=c(1:2)) keyC - list(border = FALSE, text = list(levels(dataf$sta)[3:5]),lines=TRUE,points=TRUE,lty=c(3:5),pch=c(3:5)) keyF - list(border = FALSE, text = list(levels(dataf$sta)[6:9]),lines=TRUE,points=TRUE,lty=c(6:9),pch=c(6:9)) keyS - list(border = FALSE, text = list(levels(dataf$sta)[10]),lines=TRUE,points=TRUE,lty=c(10),pch=c(10)) # the plot xyplot(lbt ~ de | type, data=dataf, groups = sta,type=c(p,g,r),layout=c(4,1),par.settings = standard.theme(color = FALSE), auto.key=list(space=top, columns=5, lines=TRUE)) # add legends inside the panels trellis.focus(panel, 1, 1) ; draw.key(keyA, draw = TRUE, vp = viewport(.25, .9)) trellis.focus(panel, 2, 1) ; draw.key(keyC, draw = TRUE, vp = viewport(.75, .9)) trellis.focus(panel, 3, 1) ; draw.key(keyF, draw = TRUE, vp = viewport(.75, .9)) trellis.focus(panel, 4, 1) ; draw.key(keyS, draw = TRUE, vp = viewport(.75, .9)) trellis.unfocus() -- Luis Tito de Morais IRD - UMR LEMAR (IRD/UBO/CNRS/IFREMER) Tél. : +33 2 98 49 86 35 Mob. : +33 6 37 67 21 40 Courriel-1 : luis.tito-de-mor...@ird.fr Courriel-2 : luis.titodemor...@univ-brest.fr Pages web : Lab. : http://www-iuem.univ-brest.fr/UMR6539/recherche/equipe-5 Pers. : http://ird.academia.edu/LuisTitodeMorais Reshal : http://www.netvibes.com/reshal#Accueil Biblio. : http://www.citeulike.org/user/ltitodem [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] italic font for legend text when using expression function for symbols
plot(1) legend('topleft',legend=expression(A,italic(A),bolditalic(A),Delta*italic(D))) On Wed, Jan 23, 2013 at 9:45 AM, raz barvazd...@gmail.com wrote: Hello, I'm trying to add a symbol (Delta) to plot legend with text using expression(paste()) but this disables the text.font that allows to use bold or italic text. as follows: x=c(1:10) y=c(1:10) plot(x,y) legend(1,10,legend=c(A,B,C,expression(paste(Delta, D))), pch=c(24,18,17,16),cex=2,text.font=3,bty=n) Any suggestion to how I can add the Delta symbol and have a italic font? Thanks -- \m/ [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] Lattice levelplot- remove unused levels per panel
On Sun, Jan 20, 2013 at 1:59 AM, ronny ronny.recht...@evogene.com wrote: Hi, I am using levelplot, and would like remove from each panel (condition) its unused x levels. Uneven scales on categorical axes lead to distortion and a miss representation (as in your example - the area for levels 4,6 in vs1 will be bigger than for vs0). In short, don't do it. IMO a solution such as levelplot(mpg ~ factor(cyl) * factor(gear) | factor(vs) , mtcars, par.settings=list(panel.background=list(col='grey'))) is much better. Note, your request could make sense for some continuous variables, so if you insist you could always levelplot(mpg ~ as.numeric(cyl) * factor(gear) | factor(vs) , mtcars, scales=list(x=list(relation='free'))) HTH e.g. Remove from panel vs=1 the cyl level=8. data(mtcars) levelplot(mpg~factor(cyl)*factor(gear)|factor(vs)) Thanks for your help, Ronny -- View this message in context: http://r.789695.n4.nabble.com/Lattice-levelplot-remove-unused-levels-per-panel-tp4656087.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. [[alternative HTML version deleted]] __ 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] Log scale on y axis of parallel coordinate plot (lattice)
On Wed, Jan 16, 2013 at 12:05 PM, Patrick Connolly p_conno...@slingshot.co.nz wrote: On Mon, 07-Jan-2013 at 10:21PM +1100, Roland Seubert wrote: | Hello all, | | I would like to make a parallel coordinate plot with lattice. The | plot should have vertical log scale axes, and should in principle | look like this one (I put less chemical elements in my example | below): | | http://www.geokem.com/images/scans/epr-and-N_Chile_Ridge.gif | | The data I am trying to plot are chemical analyses of rock samples | (data frame df). The data needs to be normalised against a | reference sample (vector norm), to get the actual data to be | plotted (data frame df_n). Here is a simplified example: | | df - data.frame(La = c(3.0, 2.9, 2.7), Eu = c(0.86, 0.76, 0.66), | Lu = c(0.07, 0.04, 0.04), row.names = c(sample1, sample2, | sample3)) | norm - c(0.237, 0.0563, 0.0246) | df_n - df / norm | df_n |LaEuLu | sample1 12.65823 3.628692 0.2953586 | sample2 51.50977 13.499112 0.7104796 | sample3 109.75610 26.829268 1.6260163 | | The plot needs the same scale for all axes, so my simple panel | function would be: | | panel.myplot - function(..., common.scale) {panel.parallel(..., | common.scale = TRUE)} | | I tried to plot the data with the following command to get vertical | axes with a log scale: | | parallelplot(~ df_n, panel = panel.myplot, horizontal.axis = | FALSE, scales = list(y = list(log = 10))) | | The problem is that lattice simply ignores the log scale and gives | me the following warning: | | Warning message: | In parallelplot.formula(~df_n, panel = panel.spiderplot, | horizontal.axis = FALSE, : | cannot have log y-scale Check out how to use the scales list in the help for xyplot(). You might need to brush up on how the help for axis() to see which parameters you need to set. Actually I don't think that's the OP's problem. My guess the attempt to set the scale for y was because horizontal.axis = FALSE, which makes intuitive sense but unfortunately is wrong for parallelplot (which uses y.scales for annotation of the categories regardless of direction). OP, try c(parallelplot(~ df_n, horizontal.axis = FALSE, scales=list(x = list(log = TRUE))) , parallelplot(~ df_n, horizontal.axis = FALSE)) Cheers HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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. [[alternative HTML version deleted]] __ 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] Log scale on y axis of parallel coordinate plot (lattice)
On Wed, Jan 16, 2013 at 12:46 PM, ilai ke...@math.montana.edu wrote: Oops... That's require(latticeExtra) c(parallelplot(~ df_n, horizontal.axis = FALSE, scales=list(x = list(log = TRUE))) , parallelplot(~ df_n, horizontal.axis = FALSE)) or you'll get the full printout of the two objects. Sorry HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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. [[alternative HTML version deleted]] __ 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] overlaying zoo plots in lattice
str(x) ; str(y) reveals #zoo series ... # ..$ : chr [1:3] a c b ## HERE # Index: Date[1:100], format: 2010-01-01 2010-01-02 2010-01-03 2010-01-04 ... #'data.frame':99 obs. of 3 variables: # $ ID : Factor w/ 3 levels a,b,c: ## HERE # ... #' So change the levels of ID in y or in the plot call to fit the zoo object: xyplot(x)+as.layer(xyplot(value~date|factor(ID,levels=c('a','c','b')), y)) On Fri, Jan 11, 2013 at 12:27 PM, A Duranel arnaud.duranel...@ucl.ac.ukwrote: Hello Let's say I have a multivariate zoo timeseries (synchronised automatic loggers at different places): library(zoo) library(lattice) library(latticeExtra) x-zoo(data.frame(a=rnorm(100), c=rnorm(100), b=rnorm(100)), seq(from=as.Date(2010-01-01), by=day, length.out=100)) and a dataframe with manual control points at variable dates: y-data.frame(ID=rep(c(b, c, a),33), value=rep(c(-2, 0, 2), 33)) y$date-seq(from=as.Date(2010-01-01), by=day, length.out=99) I would like to create a lattice graph with one panel per column of the zoo timeseries, and overlay on each of them the control points that correspond to it, on the basis of the ID factor in the dataframe that matches the column names of the zoo timeseries. I tried this: xyplot(x)+as.layer(xyplot(value~date|ID, y)) Unfortunately the points are not placed according to the name of the panels (and of the column names of the zoo timeseries), but to the alphabetical order of the ID factor it seems. Any help will be much appreciated! Arnaud -- View this message in context: http://r.789695.n4.nabble.com/overlaying-zoo-plots-in-lattice-tp4655281.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. [[alternative HTML version deleted]] __ 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] Changing mtext direction, or using text for the margin?
On Mon, Jan 7, 2013 at 11:52 AM, David Winsemius dwinsem...@comcast.netwrote: If you are going that route you may want to look at the gridBase package. Yes for mixing base and grid graphics but IMHO overkill here. Replacing the last mtext line with grid::grid.text('dependent B', 0.985 , 0.5 , rot = 270) should take care of it (leaving exact placement and justification to the OP) cheers -- David. Mike David Winsemius wrote: On Jan 7, 2013, at 8:06 AM, Michael Rennie wrote: Any thoughts on what that dirty hack might be or any leads on where to start? Perhaps a whole new plot region in the margin or something? Is that even possible? I'm having a difficult time imagining how I can do this. The `text` function accepts the 'xpd' argument for `par`. ?par ?text (Similar but not exactly the same as R-FAQ 7.27 How can I create rotated axis labels?) I'm not sure what sort of dirt Uwe was expecting, but I'm guessing he meant that you probably were not going to be getting exactly what you wanted with the first attempt and were going to need to adjust the locations by hand after digging around in the par documentation. David Winsemius, MD Alameda, CA, USA __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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 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] Focus on a sub-panel of a splom with trellis.focs() -- return coordinate of sub-panel, or names of variables therein
You could try require(grid) trellis.focus() names(iris)[round(unlist(grid.locator()))] trellis.unfocus() cheers On Tue, Dec 11, 2012 at 11:59 AM, Eric Stone eric.st...@temple.edu wrote: Hi, I'd like to be able to generate a splom plot in R and then use my mouse to click on one of the sub-panels (panel.pairs, specifically) and have R return either the coordinates of that sub-panel, or even better, the names of the corresponding variables plotted in that sub-panel. Here's an example to work with: library(lattice) splom(~iris[1:4], groups = Species, data = iris, + panel = panel.superpose, + key = list(title = Three Varieties of Iris, + columns = 3, + points = list(pch = super.sym$pch[1:3], +col = super.sym$col[1:3]), + text = list(c(Setosa, Versicolor, Virginica This is what I've been able to come up with so far, but I know it's not what I need. I'd like to be able to select an entire sub-panel trellis.focus() panel.link.splom() #click on a point in the plot, then hit 'esc' [1] 80 111 trellis.unfocus() #to end trellis.focus Thanks for your help, Eric [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] Error message R2Jags
On Wed, Nov 28, 2012 at 11:37 AM, alexB alexandre.bud...@helsinki.fiwrote: The error was generated by jags not R or R2Jags (wrong list). Regardless, your problem is the prior loop is only 1:6 snip for (i in 1:6) { b[i] ~ dnorm(0.0, 0.01) # b[i] ~ dunif(-20, +20) So the error is literally b[7] is out of range Cheers } } ,fill = TRUE) sink() inits1 - function () { list(b = rnorm(7, 0, 0.01))} out1 - jags(data = win.data1, inits = inits1, parameters = params1, model.file = GLM.txt, n.thin = nt, n.chains = nc, n.burnin = nb, n.iter = ni) That's when R returns this error message: # #Compiling model graph # Resolving undeclared variables # Allocating nodes #Deleting model # #Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, : # RUNTIME ERROR: #Compilation error on line 13. #Subset out of range: b[7] # So I guess there's a problem with line 13 of the code (i.e. b[7] * I3[i]) causing the problem, but why... I really don't see the problem :( Any guess? Thanks in advance, aB -- View this message in context: http://r.789695.n4.nabble.com/Error-message-R2Jags-tp4651178.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. [[alternative HTML version deleted]] __ 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] Problem with glm, gaussian family with log-link
On Mon, Nov 26, 2012 at 5:33 AM, Florian Weiler fweile...@jhubc.it wrote: Dear all, I am using the book Generalized Linera Models and Extension by Hardin and Hilbe (second edition, 2007) at the moment. The authors suggest that instead of OLS models, the log link is generally used for response data that take only positive values on the continuous scale. snip specifying *family=gaussian(link=log) *I am asked to provide starting values. When I set them all equal to zero, I always get the message that the algorithm did not converge. Picking other values the message is sometimes the same, but more often I get: * * *Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, : * * NA/NaN/Inf in 'x' * * * As I said, in STATA I can run these models without setting starting values and without errors. I tried many different models, and different datasets, And yet you've failed to provide even one of them together with your code as a reproducible example ... # This works without starting values: set.seed(2341) x - rep(1:10,3) ; y - jitter(rpois(30,5+x)) plot(x,y) (gausslog - glm(y~x,family=gaussian(link='log'))) exp(coef(gausslog)) # This works only with starting values set.seed(2341) x - rep(1:10,3) ; y - jitter(rpois(30,x)) plot(x,y) ; summary(y) # yes,yes, some y 0, just trying to reproduce the error... (gausslog - glm(y~x,family=gaussian(link='log'))) (gausslog - glm(y~x,family=gaussian(link='log'),start=c(0,0))) # also set.seed(2341) x - rep(1:10,3) ; y - rnorm(30,0+0.1*x) plot(x,y) ; summary(y) (gausslog - glm(y~x,family=gaussian(link='log'),start=c(0,0))) So really this is a non issue without the offending data set and code. but the problem is always the same (unless I only include one single independent variable). Oh, more information... way to build up the suspense set.seed(2341) x - rep(1:10,3) ; xx - rep(seq(20,50,l=5),6) ; y - rnorm(30,5+3*x-2*xx) (gausslog - glm(y~x+xx,family=gaussian(link='log'),start=c(0,0,0))) No joy. Still fits. Could anyone tell me why this is the case, or what I do wrong, No or why the suggested models from the book might not be appropriate? I'd appreciate any help! Personally I don't care for reproducing some results from STATA and have no comment on the validity of the above but maybe someone in the list would have a better answer if you repost. Best, Florian Also this: [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] rjags and parallel chains
Specifying n 1 chains is not enough. You need some parallel backend. You can use snow/snowfall or doMC (these are R libraries) for example. Maybe others, google is your friend. Word of caution about doMC (maybe also snowfall, never tested it), you might need to specify RNG (seed, sampler) for each chain in the starting values list because once you split your job, each core thinks you are running just one chain and they all choose Wichmann-Hill with the same .Random.seed and you get 4 copies of the same chain. With different *parameter* starting values this might not be such a big deal for you, it depends on your application, just thought I'll mention it. See jags manual and ?RNG. Good luck On Sun, Nov 25, 2012 at 11:57 AM, Noah Silverman noahsilver...@ucla.eduwrote: Hello, I have a fairly complex hierarchical model that I using rjags to fit. Short test runs verify that it works and everything appears to be setup correctly. Now that I want to collect a larger sample from the posterior (5,000 or more). This looks like it will take several days to run on my hardware (Intel core i7, 16GB RAM) I read in the rjags documentation that there is an option for parallel chains. Since my cpu has 4 cores, it seems logical to run 4 chains in parallel, collection 1,250 samples each. Should provide a nice speedup. However, when calling rjags with the n.chains options set to 4, I don't see it actually doing anything in parallel. Watching a cpu monitor, I only see a single thread running on a single core. So clearly something isn't working correctly. Software versions: R 2.15.2 jags 3.2.0 Ubuntu 12.04 (64bit version) Can anyone suggest where I might look to get this running in parallel? Thanks -- Noah Silverman, M.S. UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095 __ 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. [[alternative HTML version deleted]] __ 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] lattice: defining grouping variable only for the upper/lower panel with splom
On Mon, Nov 19, 2012 at 5:42 AM, AnjaM a.miren...@gmail.com wrote: Using the mtcars dataset, how to define the grouping variable to be valid only for the upper or lower panel? The following doesn't work: # Code start Almost : splom(~data.frame(mpg, disp, hp, drat, wt, qsec), data=mtcars, pscales=0, auto.key=list(columns=3), upper.panel = function(...,groups){ panel.grid(...) panel.xyplot(groups=mtcars$cyl,...) } ) # Code end -- View this message in context: http://r.789695.n4.nabble.com/lattice-defining-grouping-variable-only-for-the-upper-lower-panel-with-splom-tp4650033.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. [[alternative HTML version deleted]] __ 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] [newbie] convert 3D spatial array to dataframe
Errr... You could reshape to a long format data.frame but an arguably easier way: dimnames(array.3d) - list(lat= 1:7 , long = 1:11 , lev = 1:5) # not needed just for clarity levelplot(array.3d) On Sat, Nov 17, 2012 at 9:36 PM, Tom Roche tom_ro...@pobox.com wrote: summary: how to convert a 3D array (as obtained from ncdf4::ncvar_get) to a dataframe suitable for use by lattice::levelplot(), e.g., levelplot(conc ~ lon * lat | lev, data = data.frame) details: I have atmospheric data in netCDF files specifying gas concentrations over a 3D space with dimensions longitude, latitude, and (vertical) level. I need to plot the data by level. Since there are several levels, I'm guessing I should use package=lattice, which I have not previously used. (I have used package=fields, and I would like to plot the levels over a map, but lattice seems to provide the best way to organize multiple plots--please correct me if wrong.) From reading Sarkar's excellent lattice book http://dx.doi.org/10.1007/978-0-387-75969-2 it seems that one best provides data to lattice::levelplot() via dataframe, since the dataframe provides a sort of namespace for the trellis formula. I know that ncdf4::ncvar_get will return my concentrations as the values in a 3D array with dimensions={lon, lat, lev} so I'm trying to find a way to convert a 3D array to a dataframe. Here's my small, self-contained example: lon=11 lat=7 lev=5 len=lon*lat*lev array.3d - array(data=c(1:len), dim=c(lat, lon, lev)) # Rewrite the array values more spatially, i.e., row-wise from # bottom left. If there's a more-R-ish way to fill this array # as specified, please let me know: I know 'for' loops are deprecated # in R. i=1 for (z in 1:lev) { for (x in lat:1) { for (y in 1:lon) { array.3d[x,y,z]=i ; i=i+1 } } } produces (with rows=latitudes and cols=longitudes) array.3d[,,1] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 67 68 69 70 71 72 73 74 757677 [2,] 56 57 58 59 60 61 62 63 646566 [3,] 45 46 47 48 49 50 51 52 535455 [4,] 34 35 36 37 38 39 40 41 424344 [5,] 23 24 25 26 27 28 29 30 313233 [6,] 12 13 14 15 16 17 18 19 202122 [7,]1234567891011 array.3d[,,lev] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 375 376 377 378 379 380 381 382 383 384 385 [2,] 364 365 366 367 368 369 370 371 372 373 374 [3,] 353 354 355 356 357 358 359 360 361 362 363 [4,] 342 343 344 345 346 347 348 349 350 351 352 [5,] 331 332 333 334 335 336 337 338 339 340 341 [6,] 320 321 322 323 324 325 326 327 328 329 330 [7,] 309 310 311 312 313 314 315 316 317 318 319 I want to convert array.3d to a dataframe with structure like the following (note order of data values is arbitrary): lon lat lev conc --- --- --- 171 1 271 2 371 3 ... 91175 101176 111177 ... 915 383 1015 384 1115 385 How to do that? I'm guessing this involves function=reshape, but I can't see how to make `reshape` work for this usecase. TIA, Tom Roche tom_ro...@pobox.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. [[alternative HTML version deleted]] __ 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] Calculateing means
On Fri, Nov 16, 2012 at 2:42 PM, Khan, Sohail skha...@nshs.edu wrote: Thanks. But aggregate will work on rows or columns. I need to calculate mean for subsets of rows in a matrix I.E. Indx x1 x2 x3 x4 x5 x6 x7 x8 x9 1 25 30 15 8 12 9 18 21 89 2 52 35 42 74 65 20 28 32 12 3 12 35 33 88 12 52 32 32 18 4 25 25 16 23 89 21 21 21 42 ... I would like to calculate means for x1-x3, x4-x6, x7-x9 For each row. matrix%*%kronecker(diag(6),rep(1/95,95))) assuming the original is set-up same as above (1-95 , 96 - 190 , ... -570) -Sohail -Original Message- From: John Kane [mailto:jrkrid...@inbox.com] Sent: Friday, November 16, 2012 4:35 PM To: Khan, Sohail; 'r-help@r-project.org' Subject: RE: [R] Calculateing means ?aggregate will do it. x - data.frame( height= c(50, 174, 145, 200, 210, 140, 175), age_group=c(1,2,2,1,1,2,1), ville= c(1,2,3,1,2,3,1)) aggregate(x$height,list(x$age_group, x$ville), mean) or have a look at the plyr or datatable packages. John Kane Kingston ON Canada -Original Message- From: skha...@nshs.edu Sent: Fri, 16 Nov 2012 15:58:17 -0500 To: r-help@r-project.org Subject: [R] Calculateing means Dear List, I have a data matrix with 570 columns containing 95 (samples) with 6 replicates each. How can I calculate the mean of the replicates for 95 samples? Thank you. The information contained in this electronic e-mail transmission and any attachments are intended only for the use of the individual or entity to whom or to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this communication is not the intended recipient, or the employee or agent responsible for delivering this communication to the intended recipient, you are hereby notified that any dissemination, distribution, copying or disclosure of this communication and any attachment is strictly prohibited. If you have received this transmission in error, please notify the sender immediately by telephone and electronic mail, and delete the original communication and any attachment from any computer, server or other electronic recording or storage device or medium. Receipt by anyone other than the intended recipient is not a waiver of any attorney-client, physician-patient or other priv! ilege. [[alternative HTML version deleted]] __ 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. Send any screenshot to your friends in seconds... Works in all emails, instant messengers, blogs, forums and social networks. TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if2 for FREE The information contained in this electronic e-mail transmission and any attachments are intended only for the use of the individual or entity to whom or to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this communication is not the intended recipient, or the employee or agent responsible for delivering this communication to the intended recipient, you are hereby notified that any dissemination, distribution, copying or disclosure of this communication and any attachment is strictly prohibited. If you have received this transmission in error, please notify the sender immediately by telephone and electronic mail, and delete the original communication and any attachment from any computer, server or other electronic recording or storage device or medium. Receipt by anyone other than the intended recipient is not a waiver of any attorney-client, physician-patient or other priv! ilege. __ 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. [[alternative HTML version deleted]] __ 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] strip.custom() with more than one conditioning variable
dotplot(variety ~ yield | year+ site, barley, strip = function(...,which.given,factor.levels) { if(which.given==2){ strip.default(which.given,factor.levels=substr(levels(barley$site), 1, 1),style=4,...) } else{ strip.default(which.given=which.given,factor.levels=factor.levels,style=3,...) } } ) Cheers On Thu, Nov 15, 2012 at 5:18 PM, p_conno...@slingshot.co.nz wrote: Thanks Duncan, but it's of no use. It still leaves space for two strips and doesn't use the first one. I don't actually want a style = 4. I used it as an example of when a factor.levels vector might be wanted. In my case I want a vector of expressions which can't be made factor levels. If I didn't need to show two conditioning variables, I'd have no problem. I need to work out how which.given is meant to be used. It doesn't make sense to use it the way I have and I'll desist as soon as I find out how to use it properly. best Patrick Quoting Duncan Mackay mac...@northnet.com.au: Hi Patrick Not sure what you finally want to achieve but will this do? I have reduced the size of the text to make them readible dotplot(variety ~ yield | year+ site, barley, strip = strip.custom(which.given = 2, style = 4, factor.levels = paste(levels(barley$year), substring(levels(barley$site), 1, 1)), par.strip.text = list(cex = 0.75)) ) __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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 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] How to include CI in a grouped barplot?
On Thu, Nov 8, 2012 at 12:14 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, If I understand it right, you can use the arrows() function with an angle of 90 to get ci bars. Using your data example, but with made up standard errors, a=c(10,15) b=c(20,24) c=c(21,23) hei=cbind(a,b,c) # Standard errors sigma - matrix(runif(6), ncol = 3) # helper function ci - function(x, conf = 0.95) x*qnorm(1 - (1 - conf)/2) lo - hei - ci(sigma) hi - hei + ci(sigma) graph1=barplot(hei, beside=T, ylim = c(0, max(hi))) arrows(graph1, hi, graph1, lo, length = 0.15, angle = 90, code=3) will suffice (code = 1,2,3 in ?arrows) sapply(1:ncol(graph1), function(j){ arrows(graph1[,j], hei[,j], graph1[,j], lo[,j], length = 0.15, angle = 90) arrows(graph1[,j], hei[,j], graph1[,j], hi[,j], length = 0.15, angle = 90) }) Hope this helps, Rui Barradas Em 08-11-2012 13:02, Thais Rangel escreveu: Hello everyone! I need to include the confidence interval bar in a grouped barplot. I've found some options on the web, but none of them solved my problem. The question is: my barplot was created using vectors for each pair of bar and them combining them using cbind. I mean: a=c(10,15) b=c(20,24) c=c(21,23) ... hei=cbind(a,b,c) graph1=barplot(hei, beside=T,...) I've tried to include each CI in a vector just like the height of the bars, but it hasn't worked (!!) Is there an easy way to do this?? Thanks a lot =) Thais Rangel (Rio de Janeiro, Brazil) [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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 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] plot.new() and grid functions in multipage pdfs
On Fri, Oct 19, 2012 at 6:28 PM, Ali Tofigh alix.tof...@gmail.com wrote: On Wed, Oct 17, 2012 at 4:08 PM, ilai ke...@math.montana.edu wrote: On Wed, Oct 17, 2012 at 11:10 AM, Ali Tofigh alix.tof...@gmail.com wrote: ## this works as intended with a mix of plot.new() and grid.newpage pdf(test3.pdf) plot.new(); my.plot(); grid.newpage(); my.plot() dev.off() Ahh. The evolution of problems in R-help threads...what a way to start the week... While grid and base don't play nice, that doesn't mean they *can't* be mixed through proper use of gridBase - which requires some trial and error on your part to see what works and what doesn't. For example this also works without explicit calls to newpage: my.plot - function(){ plot(1, type='n', axes=FALSE, bty='n', xlab='', ylab='') # a blank base plot grid.rect(c(0.25, 0.75), width=c(0.5, 0.5), gp=gpar(fill=c(blue, red)), vp=viewport(w=unit(.5, npc),just='left',clip='on'))# note the clipping pushViewport(viewport(w=unit(.5, npc),just='right')) par(fig=gridFIG(), new=TRUE) plot(1:10) popViewport() } pdf(file='test4.pdf') my.plot() ; my.plot() # onefile = TRUE by default dev.off() What's going on here ? well, maybe some grid gurus more knowledgeable than I can add insight here but I think you are mixing different issues. The example you gave, test1 didn't work because when you call par(new=T) the first time, there is still no plot to go on. Same issue as produces the warning graphics.off() par(new=T) Modify my.plot() so the grid.rect is drawn *after* the plot(1:10), your test1.pdf is correct with just a blank first page (from the extra call to par). Thus, new.page() in your test3 solved this annoying issue of the first par(new=T) call - which implies you can also draw the grid grobs first, but I would not call this a mix of new.page and grid.newpage. In the future, to get the most out of R-help my unsolicited advice is to remember you are the only one who knows how much / what help you need - and set up your question / reproducible code accordingly. We the list readers don't know your level, what things you tried etc. The original example made no mention of base graphics, and the second reply didn't give any hints as to how/why mixing base and grid matters here. Cheers /ali require(gridBase) pdf(test.pdf) grid.rect(gp = gpar(fill=blue)) grid.newpage() grid.rect(gp=gpar(fill='blue')) # mix in base+grid. adapted from ?gridPAR in gridBase par(fig=gridFIG(), new=TRUE) plot(1:10) # plot.new() # uncomment to see it's unnecessary plot(1:10) pushViewport(viewport(width=0.5, height=0.5)) ; grid.rect(gp=gpar(col=grey, lwd=2)) plot(rnorm(10)) grid.newpage() grid.rect(gp=gpar(fill='blue')) dev.off() I use grid as much as possible, but for example for plotting dendrograms, I don't know how to plot them other than using base graphics. So I use the functions in gridBase to produce those plots. Then you may have noticed the dendrogram examples in the gridBase docs don't use plot.new() either but use lattice for the layout. In order to do that I have to call plot.new() at some point in my code to initialize the base graphics, and that can mess things up. No. See example above or provide a minimal reproducible example that does require it. /ali On Tue, Oct 9, 2012 at 4:00 PM, Greg Snow 538...@gmail.com wrote: The plot.new function is for base graphics and base and grid graphics don't usually play well together. You probably want to use grid.newpage function instead. On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh alix.tof...@gmail.com wrote: Hi, when using the grid package, I've come across this weird behaviour where a call to plot.new() will start a new page for a multi-page pdf, but then the margins will somehow behave strangely for all but the first page: here is some code: pdf(test.pdf); plot.new(); grid.rect(gp = gpar(fill=blue)); plot.new(); grid.rect(gp = gpar(fill=blue)); dev.off() The first page is filled completely with a blue rectangle, but in the second page, the margins clip the rectangle. This is causing me considerable headache, as I rely on many grid functions for plotting. This seems like a bug to me, or is there something about the behaviour of plot.new() and/or grid functions that I don't understand? /Ali __ 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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.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
Re: [R] plot.new() and grid functions in multipage pdfs
On Wed, Oct 17, 2012 at 11:10 AM, Ali Tofigh alix.tof...@gmail.com wrote: my problem is that I usually have no choice but to mix grid and base graphics. What does that have to do with the answer you got ? did you even try it ? here it is (again) but this time mixing base+grid: require(gridBase) pdf(test.pdf) grid.rect(gp = gpar(fill=blue)) grid.newpage() grid.rect(gp=gpar(fill='blue')) # mix in base+grid. adapted from ?gridPAR in gridBase par(fig=gridFIG(), new=TRUE) plot(1:10) # plot.new() # uncomment to see it's unnecessary plot(1:10) pushViewport(viewport(width=0.5, height=0.5)) ; grid.rect(gp=gpar(col=grey, lwd=2)) plot(rnorm(10)) grid.newpage() grid.rect(gp=gpar(fill='blue')) dev.off() I use grid as much as possible, but for example for plotting dendrograms, I don't know how to plot them other than using base graphics. So I use the functions in gridBase to produce those plots. Then you may have noticed the dendrogram examples in the gridBase docs don't use plot.new() either but use lattice for the layout. In order to do that I have to call plot.new() at some point in my code to initialize the base graphics, and that can mess things up. No. See example above or provide a minimal reproducible example that does require it. /ali On Tue, Oct 9, 2012 at 4:00 PM, Greg Snow 538...@gmail.com wrote: The plot.new function is for base graphics and base and grid graphics don't usually play well together. You probably want to use grid.newpage function instead. On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh alix.tof...@gmail.com wrote: Hi, when using the grid package, I've come across this weird behaviour where a call to plot.new() will start a new page for a multi-page pdf, but then the margins will somehow behave strangely for all but the first page: here is some code: pdf(test.pdf); plot.new(); grid.rect(gp = gpar(fill=blue)); plot.new(); grid.rect(gp = gpar(fill=blue)); dev.off() The first page is filled completely with a blue rectangle, but in the second page, the margins clip the rectangle. This is causing me considerable headache, as I rely on many grid functions for plotting. This seems like a bug to me, or is there something about the behaviour of plot.new() and/or grid functions that I don't understand? /Ali __ 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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.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. [[alternative HTML version deleted]] __ 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] Filling points in a trellis object
On Wed, Oct 10, 2012 at 4:56 AM, Pierrick Bruneau pbrun...@gmail.comwrote: With the following code : dat1 - matrix(nrow=4, ncol=2) dat1[1,] - c(-2, 1) dat1[2,] - c(-1.7, 0.9) dat1[3,] - c(0.1, 0.6) dat1[4,] - c(0.5, 0.5) theplot - xyplot(V2 ~ V1, as.data.frame(dat1), pch=c(4,1,5,4)) plot(theplot, prefix=theplot) # for a predictable name grid.edit(theplot.xyplot.points.panel.1.1, gp=gpar(lwd=c(2,2,2,2), cex=c(2,3,3,2), col=1, fill=c(transparent, grey, grey, transparent))) I would like to plot 4 points, and have the circle and diamond shapes filledwith grey. What am I missing ? The correct pch+col (fill is for polygons) specification. Try theplot - xyplot(V2 ~ V1, as.data.frame(dat1), pch = c(4,19,18,4) , col = c(1,'grey35','grey65',1) ) plot(theplot, prefix=theplot) # for a predictable name grid.edit(theplot.xyplot.points.panel.1.1, gp = gpar( lwd = c(2,2,2,2) , cex = c(2,3,3,2) ) ) BTW in R you don't need to declare objects, i.e. dat1 - matrix(c(-2,-1.7,0.1,0.5,1,.9,.6,.5), nrow=4, ncol=2) works just as well (or IMHO better). Similarly, your plot can be generated in one go, no need to plot = edit, just put in the right args to begin with. HTH Thanks by advance for your help, Pierrick Bruneau Research Fellow CRP Gabriel Lippmann [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] Filling points in a trellis object
On Wed, Oct 10, 2012 at 4:56 AM, Pierrick Bruneau pbrun...@gmail.comwrote: With the following code : dat1 - matrix(nrow=4, ncol=2) dat1[1,] - c(-2, 1) dat1[2,] - c(-1.7, 0.9) dat1[3,] - c(0.1, 0.6) dat1[4,] - c(0.5, 0.5) theplot - xyplot(V2 ~ V1, as.data.frame(dat1), pch=c(4,1,5,4)) plot(theplot, prefix=theplot) # for a predictable name grid.edit(theplot.xyplot.points.panel.1.1, gp=gpar(lwd=c(2,2,2,2), cex=c(2,3,3,2), col=1, fill=c(transparent, grey, grey, transparent))) I would like to plot 4 points, and have the circle and diamond shapes filledwith grey. What am I missing ? The correct pch+col (fill is for polygons) specification. Try theplot - xyplot(V2 ~ V1, as.data.frame(dat1), pch = c(4,19,18,4) , col = c(1,'grey35','grey65',1) ) plot(theplot, prefix=theplot) # for a predictable name grid.edit(theplot.xyplot.points.panel.1.1, gp = gpar( lwd = c(2,2,2,2) , cex = c(2,3,3,2) ) ) BTW in R you don't need to declare objects, i.e. dat1 - matrix(c(-2,-1.7,0.1,0.5,1,.9,.6,.5), nrow=4, ncol=2) works just as well (or IMHO better). Similarly, your plot can be generated in one go, no need to plot = edit, just put in the right args to begin with. HTH Thanks by advance for your help, Pierrick Bruneau Research Fellow CRP Gabriel Lippmann [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] how to convert by lists in data.frames
On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Try do.call(data.frame, by.list) I don't think data.frame inside do.call works in this context. May need it on the outside to do the job (Only OK here since there is no mixture of numeric and character/factors in this summary). Something like by.list - by(warpbreaks[, 1], warpbreaks[, -1], summary) by.dtfrm - data.frame( do.call( rbind, by.list ) ) by.dtfrm - cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ), by.dtfrm ) Hope this helps, Rui Barradas Em 09-10-2012 17:53, Jesus Frias escreveu: Dear R-helpers, I've got a summary of results from a by() call that I am making with a list of more than two of factors not very different from the example in the by() help page require(stats) by(warpbreaks[, 1], warpbreaks[, -1], summary) The result of the command gives a list of the form wool: A tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 25.00 26.00 51.00 44.56 54.00 70.00 --- wool: B tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 14.00 20.00 29.00 28.22 31.00 44.00 --- And so on. I would like to convert this result in to a flat data.frame with variable names: Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max A, L , 25.00 26.00 51.00 44.56 54.00 70.00 B, L, 14.00 20.00 29.00 28.22 31.00 44.00 Although I've tried the argument simplify=T I haven't been able to get this converted. Is there a simple way to achieve this? Thanks in advance! Regards, Jesus Jesús María Frías Celayeta, PhD Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil Assistant Head, School of Food Science and Environmental Health, Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health, Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology, Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street, Dublin 1, Ireland F: +353-1-4024459 E: mailto:james.cur...@dit.ie jesus.fr...@dit.ie W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] how to convert by lists in data.frames
On Tue, Oct 9, 2012 at 12:25 PM, Bert Gunter gunter.ber...@gene.com wrote: The only wrinkle here (with either rbind or simplify2array) is getting the labels correct if the design is not fully crossed -- i.e. if some groups are missing so that expand.grid() won't work. Then you might have to work harder to extract the information from by.list. Agreed. In such a case I might decide to let aggregate(breaks~wool+tension, subset(warpbreaks, wool != 'A' | tension != 'H' ), summary) sort through the headache for me, and overlook the annoying result is actually a matrix put in as a single variable in the data.frame. Personal preference maybe but that never made sense to me in the data frame construct (even if it is just a list). Cheers str(by.list) might help here. -- Bert On Tue, Oct 9, 2012 at 11:14 AM, ilai ke...@math.montana.edu wrote: On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Try do.call(data.frame, by.list) I don't think data.frame inside do.call works in this context. May need it on the outside to do the job (Only OK here since there is no mixture of numeric and character/factors in this summary). Something like by.list - by(warpbreaks[, 1], warpbreaks[, -1], summary) by.dtfrm - data.frame( do.call( rbind, by.list ) ) by.dtfrm - cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ), by.dtfrm ) Hope this helps, Rui Barradas Em 09-10-2012 17:53, Jesus Frias escreveu: Dear R-helpers, I've got a summary of results from a by() call that I am making with a list of more than two of factors not very different from the example in the by() help page require(stats) by(warpbreaks[, 1], warpbreaks[, -1], summary) The result of the command gives a list of the form wool: A tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 25.00 26.00 51.00 44.56 54.00 70.00 --- wool: B tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 14.00 20.00 29.00 28.22 31.00 44.00 --- And so on. I would like to convert this result in to a flat data.frame with variable names: Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max A, L , 25.00 26.00 51.00 44.56 54.00 70.00 B, L, 14.00 20.00 29.00 28.22 31.00 44.00 Although I've tried the argument simplify=T I haven't been able to get this converted. Is there a simple way to achieve this? Thanks in advance! Regards, Jesus Jesús María Frías Celayeta, PhD Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil Assistant Head, School of Food Science and Environmental Health, Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health, Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology, Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street, Dublin 1, Ireland F: +353-1-4024459 E: mailto:james.cur...@dit.ie jesus.fr...@dit.ie W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML
Re: [R] plot.new() and grid functions in multipage pdfs
On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh alix.tof...@gmail.com wrote: Hi, when using the grid package, I've come across this weird behaviour pdf(test.pdf); plot.new(); grid.rect(gp = gpar(fill=blue)); plot.new(); grid.rect(gp = gpar(fill=blue)); dev.off() The first page is filled completely with a blue rectangle, but in the second page, the margins clip the rectangle. This is causing me considerable headache, as I rely on many grid functions for plotting. This seems like a bug to me, or is there something about the behaviour of plot.new() and/or grid functions that I don't understand? Why would you expect plot.new from base graphics to play nice with grid ? if you like/use grid graphics, stay in that world: pdf(test.pdf); grid.rect(gp = gpar(fill=blue)); grid.newpage(); grid.rect(gp = gpar(fill=blue)); dev.off() /Ali __ 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. [[alternative HTML version deleted]] __ 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] Coda, HPDinterval and multiple chains
How about require(coda) data(line) str(line) cline - as.mcmc(do.call(rbind,line)) str(cline) # Thus HPDinterval(cline) # (or any FUN.mcmc) sum(cline[,'alpha'] = median(cline[,'alpha']))/nrow(cline) Cheers On Thu, Oct 4, 2012 at 12:22 PM, NORRIS Paul p.nor...@ed.ac.uk wrote: Dear all, I'm not 100% sure if this question is best directed at the r-list, or a mailing list concerned with Bayesian analysis, so please accept my apologies if another audience may be more appropriate. I have been using the rjags package to run Jags models with multiple chains and store the results in a Coda based mcmc list. For instance, having created a jags model and done initial adapting and updating, I run the following command: coda_odp_gini_only - coda.samples(odp_gini_only, variable.names=c(beta,sigma2.u2, deviance), n.iter=itercount, thin=thincount) This create an object with 4 separate chains as requested in my initial call to Jags which created the object odp_gini_only. I then use the Coda package to look at the results stored in coda_odp_gini_only. Prior to running any analysis with Coda, I used the command, coda.options(combine.plots=TRUE, combine.stats=TRUE) to ask for results that combine the four separate chains. Sure enough, if I enter summary(coda_odp_gini_only), I am given a single set of output combining the four chains. However, if I enter HPDinterval(coda_odp_gini_only) I receive 4 sets of HPD figures, one for each chain. Is it possible to combine the four chains together to receive a single set of HPD estimates? In a similar vein, is it possible to use the Coda object to estimate the proportion of a given parameters distribution which is above (or below) a given value, for instance, the proportion of the distribution of beta[1] greater than zero? Again, in doing so, is it possible to combine the results of the four chains into a single estimate? Kind regards, and many thanks in advance for any advice anyone can offer me. Paul Dr Paul Norris Lecturer in Social Policy University of Edinburgh -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. __ 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. [[alternative HTML version deleted]] __ 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] changing outlier shapes of boxplots using lattice
On Fri, Sep 28, 2012 at 11:03 PM, Elaine Kuo elaine.kuo...@gmail.comwrote: Hello Thanks again. I got the attached graph Unsure why the color is still inconsistent. Please kindly share with your R version. It is not my version you need to worry about, but your own... Post the following outputs (without the prompt): sessionInfo() str(dataN) The complete code you run on a vanilla session (at this point I can only guess you changed mine somehow) dput(dataN) That will be better than having me or anyone in R-help play guess how I got this plot. Also, I want to add one line in the command. levels(dataN$Diet_B) - diet.code diet.code - c(Herbivore_t, Herbivore_w, Nectivore, Frugivore, Granivore, Scavenger, Carnivore, Insectivore_t, Insectivore_w, Insectivore_a, Molluscivore, Crustacean feeder, Omnivore) Please kindly help how to make the levels vertical instead of horizontal. Elaine On Sat, Sep 29, 2012 at 12:28 PM, ilai ke...@math.montana.edu wrote: Not sure why this is going wrong for you. Copy paste AS IS the following to your console in the directory containing for_lattice.csv str(dataN - read.csv('for_lattice.csv')[,2:3]) dataN$Diet_B - factor(dataN$Diet_B) Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2, sienna2,red2,firebrick3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38) require(lattice) bwplot(MS_midpoint_lat~Diet_B,dataN,pch='|', par.settings = list( plot.symbol =list(col = rep(Diet.colors,c(1,0,0,1,0,0,3,6,1,0,2,0,1)) ), box.dot =list(col=Diet.colors), box.rectangle=list(col=Diet.colors), box.umbrella=list(lty=1,col=Diet.colors))) Are you seeing this ? On Fri, Sep 28, 2012 at 7:06 PM, Elaine Kuo elaine.kuo...@gmail.comwrote: Hello Thanks for the quick response. For your code, the result is attached Q1. Please kindly help with the same color of box line and whisker just like box 1 of green. I attached my data and plot result (Q2). Please kindly help change the median from I to -. Thanks a lot. Elaine On Sat, Sep 29, 2012 at 8:21 AM, ilai ke...@math.montana.edu wrote: Me again... Sorry I just noticed you did provide reproducible code in your original. To get your plot: require(lattice) set.seed(5) Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2, sienna2,red2,firebrick3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38) bwplot(rgamma(20*13,1,.1)~gl(13,20), pch = |, par.settings = list( plot.symbol =list(col = rep(Diet.colors,c(0,1,1,3,1,0,3,0,0,1,1,1,0)) ), box.dot =list(col=Diet.colors), box.rectangle=list(col=Diet.colors), box.umbrella=list(lty=1,col=Diet.colors))) The box arguments set the box parameters (lty,col etc.) but the plot.symbol sets the outliers parameters (again pch, col etc.). Note the rep vector! it is because box 1 doesn't have an outlier, but box 4 has 3. You will need to construct it based on your real data or the colors will be off. Cheers On Fri, Sep 28, 2012 at 5:55 PM, ilai ke...@math.montana.edu wrote: On Fri, Sep 28, 2012 at 4:17 PM, Elaine Kuo elaine.kuo...@gmail.comwrote: Hello Ilai, Thank you for the response. It did help a lot. However, a beginner to lattice has three questions. Q1 Please kindly explain why in this case OP is using it with no at argument, Quoting from ?panel.bwplot.intermediate.hh (i.e. help file) Description: Panel function for bwplot that give the user control over the placement of the boxes. When used with a positioned factor, the boxes are placed according to the position associated with the factor. You did not supply a position factor (at argument) so all you are doing is using HH::panel.bwplot instead of the original lattice::panel.bwplot. This would have been OK but seems like there were some changes made to panel.bwplot.intermediate.hh so it doesn't give you what you want so it is possible to display the median and the outliers with different pch? Did you run my examples ? I see the attached for the second. Is this not what you want ? if you did run my examples and see something else, try again in a new R session with only lattice loaded. Let me know. Q2. what is the relationship between package HH and graphic-drawing? I checked ??HH and found little explanation on its function of graphic-drawing. Intro to R and many other web resources/books will explain the R architecture. In general packages hold functions, and there is no problem to have dependencies - i.e. function in one package calling a function from another. For example lattice has a bunch of plotting tools. HH calls one of them (panel.bwplot) and modifies it a little to get some effect (non auto placement of boxes). You can use whichever package::function you want or even build your local copy of the function. Richard can correct me and tell you more but I think HH is mostly a collection of his such local modifications. Q3 Please kindly advise how
Re: [R] changing outlier shapes of boxplots using lattice
On Sat, Sep 29, 2012 at 7:32 AM, ilai ke...@math.montana.edu wrote: On Fri, Sep 28, 2012 at 11:03 PM, Elaine Kuo elaine.kuo...@gmail.comwrote: Hello Thanks again. I got the attached graph Unsure why the color is still inconsistent. Please kindly share with your R version. It is not my version you need to worry about, but your own... Post the following outputs (without the prompt): sessionInfo() ls(pat = 'bwplot' ) str(dataN) The complete code you run on a vanilla session (at this point I can only guess you changed mine somehow) dput(dataN) That will be better than having me or anyone in R-help play guess how I got this plot. Also, I want to add one line in the command. levels(dataN$Diet_B) - diet.code diet.code - c(Herbivore_t, Herbivore_w, Nectivore, Frugivore, Granivore, Scavenger, Carnivore, Insectivore_t, Insectivore_w, Insectivore_a, Molluscivore, Crustacean feeder, Omnivore) Please kindly help how to make the levels vertical instead of horizontal. Elaine On Sat, Sep 29, 2012 at 12:28 PM, ilai ke...@math.montana.edu wrote: Not sure why this is going wrong for you. Copy paste AS IS the following to your console in the directory containing for_lattice.csv str(dataN - read.csv('for_lattice.csv')[,2:3]) dataN$Diet_B - factor(dataN$Diet_B) Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2, sienna2,red2,firebrick3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38) require(lattice) bwplot(MS_midpoint_lat~Diet_B,dataN,pch='|', par.settings = list( plot.symbol =list(col = rep(Diet.colors,c(1,0,0,1,0,0,3,6,1,0,2,0,1)) ), box.dot =list(col=Diet.colors), box.rectangle=list(col=Diet.colors), box.umbrella=list(lty=1,col=Diet.colors))) Are you seeing this ? On Fri, Sep 28, 2012 at 7:06 PM, Elaine Kuo elaine.kuo...@gmail.comwrote: Hello Thanks for the quick response. For your code, the result is attached Q1. Please kindly help with the same color of box line and whisker just like box 1 of green. I attached my data and plot result (Q2). Please kindly help change the median from I to -. Thanks a lot. Elaine On Sat, Sep 29, 2012 at 8:21 AM, ilai ke...@math.montana.edu wrote: Me again... Sorry I just noticed you did provide reproducible code in your original. To get your plot: require(lattice) set.seed(5) Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2, sienna2,red2,firebrick3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38) bwplot(rgamma(20*13,1,.1)~gl(13,20), pch = |, par.settings = list( plot.symbol =list(col = rep(Diet.colors,c(0,1,1,3,1,0,3,0,0,1,1,1,0)) ), box.dot =list(col=Diet.colors), box.rectangle=list(col=Diet.colors), box.umbrella=list(lty=1,col=Diet.colors))) The box arguments set the box parameters (lty,col etc.) but the plot.symbol sets the outliers parameters (again pch, col etc.). Note the rep vector! it is because box 1 doesn't have an outlier, but box 4 has 3. You will need to construct it based on your real data or the colors will be off. Cheers On Fri, Sep 28, 2012 at 5:55 PM, ilai ke...@math.montana.edu wrote: On Fri, Sep 28, 2012 at 4:17 PM, Elaine Kuo elaine.kuo...@gmail.comwrote: Hello Ilai, Thank you for the response. It did help a lot. However, a beginner to lattice has three questions. Q1 Please kindly explain why in this case OP is using it with no at argument, Quoting from ?panel.bwplot.intermediate.hh (i.e. help file) Description: Panel function for bwplot that give the user control over the placement of the boxes. When used with a positioned factor, the boxes are placed according to the position associated with the factor. You did not supply a position factor (at argument) so all you are doing is using HH::panel.bwplot instead of the original lattice::panel.bwplot. This would have been OK but seems like there were some changes made to panel.bwplot.intermediate.hh so it doesn't give you what you want so it is possible to display the median and the outliers with different pch? Did you run my examples ? I see the attached for the second. Is this not what you want ? if you did run my examples and see something else, try again in a new R session with only lattice loaded. Let me know. Q2. what is the relationship between package HH and graphic-drawing? I checked ??HH and found little explanation on its function of graphic-drawing. Intro to R and many other web resources/books will explain the R architecture. In general packages hold functions, and there is no problem to have dependencies - i.e. function in one package calling a function from another. For example lattice has a bunch of plotting tools. HH calls one of them (panel.bwplot) and modifies it a little to get some effect (non auto placement of boxes). You can use whichever package::function you want or even build your local copy of the function. Richard can correct me and tell you
Re: [R] changing outlier shapes of boxplots using lattice
On Fri, Sep 28, 2012 at 6:57 AM, Richard M. Heiberger r...@temple.eduwrote: Elaine, For panel.bwplot you see that the central dot and the outlier dots are controlled by the same pch argument. ??? I don't think so... bwplot(rgamma(20,.1,1)~gl(2,10), pch=rep(17,2), panel = lattice::panel.bwplot) I think you mean panel.bwplot.intermidiate.hh ? BTW thank you for the useful HH package but in this case OP is using it with no at argument, so why not Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2, sienna2,red2,firebrick3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38) bwplot(rgamma(20*13,1,.1)~gl(13,20), fill = Diet.colors, pch = |, par.settings = list(box.umbrella=list(lty=1))) cheers I initially set the pch=| to match your first example with the horizontal indicator for the median. I would be inclined to use the default circle for the outliers and therefore also for the median. Rich On Fri, Sep 28, 2012 at 7:13 AM, Sarah Goslee sarah.gos...@gmail.com wrote: I would guess that if you find the bit that says pch=| and change it to pch=1 it will solve your question, and that reading ?par will tell you why. Sarah On Thursday, September 27, 2012, Elaine Kuo wrote: Hello This is Elaine. I am using package lattice to generate boxplots. Using Richard's code, the display was almost perfect except the outlier shape. Based on the following code, the outliers are vertical lines. However, I want the outliers to be empty circles. Please kindly help how to modify the code to change the outlier shapes. Thank you. code package (lattice) dataN - data.frame(GE_distance=rnorm(260), Diet_B=factor(rep(1:13, each=20))) Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2, sienna2,red2,firebrick3,saddlebrown,coral4, chocolate4,darkblue,navy,grey38) levels(dataN$Diet_B) - Diet.colors bwplot(GE_distance ~ Diet_B, data=dataN, xlab=list(Diet of Breeding Ground, cex = 1.4), ylab = list( Distance between Centers of B and NB Range (1000 km), cex = 1.4), panel=panel.bwplot.intermediate.hh, col=Diet.colors, pch=rep(|,13), scales=list(x=list(rot=90)), par.settings=list(box.umbrella=list(lty=1))) [[alternative HTML version deleted]] __ R-help@r-project.org javascript:; 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. -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] Simple Question About Exporting Back to Excel
On Wed, Sep 26, 2012 at 3:11 PM, RCar ryan.carst...@utsouthwestern.eduwrote: All, Relatively new R user so this is probably an easy question to answer. I am able to generate a cluster for my dataset using hclust() then ploting the data with plot(). This results in an image with a dendrogram with my sample names along the bottom. Great! However, I now need a way to get that sample order from the image into excel. Why? What does the order of labels in a dendrogram mean ? But if you insist hc - hclust(dist(USArrests), ave) plot(hc) str(hc) hc$labels[hc$order] ?write.table i.e. sample 7 was on the far left, sample 19 was in position 2, sample 93 was in position 3, etc. As of now the only way for me to do this is to manually type the samples from the image into a worksheet. Very time consuming as I've got a couple hundred samples and several different dendrograms! Any thoughts? Thanks so much! -- View this message in context: http://r.789695.n4.nabble.com/Simple-Question-About-Exporting-Back-to-Excel-tp4644296.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. [[alternative HTML version deleted]] __ 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] Multiple lattice levelplots from matrices
You want array not list, as in levelplot(array(rnorm(400,rep(1:4,each=100)),c(10,10,4))) abind::abind is useful sometimes for binding preexisting matrices to arrays. Cheers On Sun, Aug 26, 2012 at 5:57 AM, Jens Peter Andersen / Region Nordjylland je...@rn.dk wrote: Dear R-users, My goal is to construct a levelplot (from the lattice package) with 4 or more individual plots sharing the same colorkey. While this appears to be relatively simple using functions, I haven't been able to find a solution using data matrices. An example of a working levelplot with just one matrix: d - replicate(10,rnorm(10)) levelplot(d) I have found partial solutions using print and split to show all 4 levelplots on the same screen, but these would require me to either turn off the colorkey, or show it on every plot. Neither solution is completely satisfactory. If I use the layout-option in levelplot, like so: levelplot(d, layout=c(2,2)) , I get the desired layout, with one large colorkey, main and xlab/ylab, but only one levelplot prints. I have been trying to construct a formula that yields the desired result, but I'm afraid my understanding of data frames, arrays and matrices is not deep enough to do so. If anyone knows of a working solution, I would be very grateful. What I imagine is something along the line of (not working code): d1 - replicate(10,rnorm(10)) d2 - replicate(10,rnorm(10)) d3 - replicate(10,rnorm(10)) d4 - replicate(10,rnorm(10)) d - list(d1,d2,d3,d4) di - c(1,2,3,4) levelplot(x ~ y | di, data = d, layout=c(2,2)) NB! Avoiding the matrices is not an option. Some of them are obtained from raw text files. Thank you in advance, -JP Jens Peter Andersen PhD student, MLIS Medical Library, Aalborg Hospital Aarhus University Hospital __ 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. [[alternative HTML version deleted]] __ 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] Turn categorical array into matrix with dummy variables
?model.matrix On Fri, Jul 27, 2012 at 11:32 AM, xuan zhao xuan.z...@sentrana.com wrote: Hi All, I want to turn a categorical array (array with factors) into a matrix with dummy variables. like array=c(a,a,b,b,b) should be turned into: a b 1 0 1 0 0 1 0 1 0 1 Do you know any way of doing this? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Turn-categorical-array-into-matrix-with-dummy-variables-tp4638134.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. [[alternative HTML version deleted]] __ 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] alternate tick labels and tick marks with lattice xyplot
Maybe I'm missing something too but from your example seems like you are looking for xyplot(rnorm(12) ~ 1:12 , type=l, scales=list(x=list(at=seq(2,12,2),labels=c(1, ' ', 3 , ' ' , 5 , ' ' ))), par.settings=list(axis.components=list(bottom=list(tck=c(0,1) See scales in ?xyplot and str(trellis.par.get()) for some settings in lattice HTH On Wed, Jul 18, 2012 at 12:02 PM, Leah Marian lmpr...@gmail.com wrote: Yes, I would be interested in both the ggplot2 and lattice ways of doing this. Unfortunately, I am not interested in creating a panel for each chromosome. Actually, I would like to create a Manhattan plot using xyplot. Thus I would need to alternate tick marks and tick labels. Thanks! On Mon, Jul 16, 2012 at 12:11 PM, John Kane jrkrid...@inbox.com wrote: I have not seen any response yet so I thought I would reply. No idea of how to do this in lattice but an approximation of it can be done in ggplot2. I am trying to learn ggplot2 and it was a handy exercise. I still have not figured out how to get the extra line on the x-axis, hence the lines in the graph body instead Example: ##++### library(ggplot2) data - structure(list(Chromosome = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3), BasePair = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4), Pvalue = c(0.819178665755317, 0.462827404495329, 0.44360001408495, 0.871020796708763, 0.404167180880904, 0.115009917411953, 0.51048326632008, 0.292681957129389, 0.839718346949667, 0.586992112919688, 0.29609977430664, 0.873988818377256), indice = 1:12, group = c(Group 1, Group 2, Group 1, Group 1, Group 1, Group 1, Group 2, Group 1, Group 2, Group 1, Group 2, Group 2)), .Names = c(Chromosome, BasePair, Pvalue, indice, group), row.names = c(NA, -12L), class = data.frame) library(ggplot2) p - ggplot(data, aes(indice, -log10(Pvalue))) + geom_line() + opts(legend.position = none) + scale_y_continuous(expression(paste(-log[10], p-value))) + scale_x_continuous(Chromosome, breaks=c(2.5, 6.5 ,10.5), labels=c(1, 2,3)) + geom_segment(aes(x = 4, y = 0.01, xend = 9, yend = 0.01, colour = group)) + opts(title = Results) + facet_grid(. ~ group) p ##===## John Kane Kingston ON Canada -Original Message- From: lmpr...@gmail.com Sent: Fri, 13 Jul 2012 15:33:43 -0400 To: r-help@r-project.org Subject: [R] alternate tick labels and tick marks with lattice xyplot Hi, I would like to use xyplot to create a figure. Unfortunately, I cannot find documentation in xyplot to specify alternating the x-axis tick labels with the x-axis tick marks. I can do this with the regular R plot function as follows. #A small version of my data looks like this data-data.frame(matrix(ncol=3,nrow=12)) data[,1]-rep(c(1,2,3),c(4,4,4)) data[,2]-rep(c(1,2,3,4),3) data[,3]-runif(12,0,1) names(data)-c(Chromosome, BasePair, Pvalue) #using R's plot function, I would place the the chromosome label between the #tick marks as follows: v1-c(4,8) v2-c(2,6,10) data$indice-seq(1:12) plot(data$indice, -log10(data$Pvalue), type=l, xaxt=n, main=Result, xlab=Chromosome, ylab=expression(paste(-log[10], p-value))) axis(1, v1,labels=FALSE ) axis(1, v2, seq(1:3), tick=FALSE, cex.axis=.6) Can this be done with lattice xyplot? -- Leah Preus Biostatistician Roswell Park Cancer Institute [[alternative HTML version deleted]] __ 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. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk and most webmails -- Leah Preus Biostatistician Roswell Park Cancer Institute __ 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. [[alternative HTML version deleted]] __ 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] plotting two histograms on one plot with hist function
On Tue, Jun 26, 2012 at 10:02 AM, John Kane jrkrid...@inbox.com wrote: Why not just plot the two histograms on the same scale in a 2 panel plot? I think OP request was for comparison. Two panels may do, but why not a barplot of the histograms in the same panel ? barplot( rbind( hist(rbeta(30,2,4),breaks=seq(0,1,.1),plot=F)$counts, hist(rbeta(30,6,8),breaks=seq(0,1,.1),plot=F)$counts), beside=T) see str(hist(yourdata)) or ?hist Cheers Ilai John Kane Kingston ON Canada -Original Message- From: mb...@sun.ac.za Sent: Tue, 26 Jun 2012 15:24:55 +0200 To: r-help@r-project.org Subject: [R] plotting two histograms on one plot with hist function I would like to plot two data sets (frequency (y-axis) of mean values for 0-1(x=axis)) on a single histogram for comparison. The hist() only allow the overlay of two histograms, and although barplot() allows beside=TRUE, it does not show frequency values (like hist) but rather all of the values. Is there any way that I can use the hist() to plot two data sets similar to the barplot(). Any help or advice will be appreciated! Kind regards, Marguerite E-pos vrywaringsklousule Hierdie e-pos mag vertroulike inligting bevat en mag regtens geprivilegeerd wees en is slegs bedoel vir die persoon aan wie dit geadresseer is. Indien u nie die bedoelde ontvanger is nie, word u hiermee in kennis gestel dat u hierdie dokument geensins mag gebruik, versprei of kopieer nie. Stel ook asseblief die sender onmiddellik per telefoon in kennis en vee die e-pos uit. Die Universiteit aanvaar nie aanspreeklikheid vir enige skade, verlies of uitgawe wat voortspruit uit hierdie e-pos en/of die oopmaak van enige l?ers aangeheg by hierdie e-pos nie. E-mail disclaimer This e-mail may contain confidential information and may...{{dropped:11}} __ 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. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk and most webmails __ 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. [[alternative HTML version deleted]] __ 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] aligning axis labels in a colorkey from levelplot
On Sat, Jun 16, 2012 at 2:11 AM, Stephen Eglen s.j.eg...@damtp.cam.ac.ukwrote: R does a great job with the fine details regarding plots. e.g in the following: library(lattice) y - -4:4/10 xyplot(y~1, las=1) No. las is a parameter in base graphics ?par. It was simply ignored here: xyplot(y~1,scales=list(rot=45), las=1) the numbers in the colorkey seem left-aligned, and because of the minus sign, the numbers now do not align on the decimal point. Likewise when the number of digits changes: levelplot(matrix(4:12,3,3)) The labels are aligned to the colored rect. You want them aligned differently, change it manually. See the colorkey details in ?levelplot (also can help with your next thread on positioning). One obvious way is to add white spaces: levelplot(matrix(seq(4,120,l=9),3,3)) # or levelplot(matrix(seq(4,120,l=9),3,3),colorkey=list(at=seq(0,120,20),labels=c(' 0',' 20',' 40',' 60',' 80','100','120'))) (If your mail client gobbled them, in the above labels, 0 has two white spaces before it, 20 has 1 white space, etc.) Cheers Thanks, Stephen __ 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. [[alternative HTML version deleted]] __ 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] how to add a vertical line for each panel in a lattice dotplot with log scale?
You say median for each panel but tapply gets medians for each variety (chartjunk IMHO). Regardless, *this case* has nothing to do with panel.abline. Add print(median.values) to your panel function would have hinted as to the missing piece. # medians for each panel: dotplot(variety ~ yield | site, data = barley, scales=list(x=list(log=TRUE)), layout = c(1,6), panel = function(x,y,...) { panel.dotplot(x,y,...) median.values - median(x) panel.abline(v=median.values, col.line=red) }) # medians for each variety dotplot(variety ~ yield | site, data = barley, scales=list(x=list(log=TRUE)), layout = c(1,6), panel = function(x,y,...) { panel.dotplot(x,y,...) median.values - tapply(x, y, median) panel.abline(v=median.values, col.line=red) } ) Cheers On Wed, Jun 6, 2012 at 6:10 AM, maxbre mbres...@arpa.veneto.it wrote: by considering this example from barley dataset #code start dotplot(variety ~ yield | site, data = barley, scales=list(x=list(log=TRUE)), layout = c(1,6), panel = function(...) { panel.dotplot(...) #median.values - tapply(x, y, median)# medians for each variety #panel.abline(v=median.values, col.line=red)# but this is not working! #panel.curve(...) # how to properly set this? } ) #code end I want to plot as a reference vertical line the medians for each panel Ive been reading in https://stat.ethz.ch/pipermail/r-help/2009-January/185384.html that its not possible with panel.abline() and its probably necessary to use panel.curve() instead; unfortunately I cant figure (manage) how, any help for this? thank you -- View this message in context: http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513.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. [[alternative HTML version deleted]] __ 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] error calling Winbugs using R2WinBugs to run a multi-level model
Untested because I don't have (use) winbugs and you didn't provide dat*. But consider a - 4 ; f - 6 list('a','f') list(a,f) list(a=a,f=f) My guess is you wanted sp.data to be a named list, not a list of names... HTH On Wed, Jun 6, 2012 at 4:12 AM, Saana Isojunno saana.isoju...@googlemail.com wrote: Dear all, I'm calling Winbugs (1.4.3) through R2WinBugs (2.1-18 coda_0.14-7) to fit a switching random walk model, but come up with an instant trap with the log only displaying 'check('. I will paste the trap with session info below; I'd be very grateful for any ideas. Couple of leads: 1. I presume the problem relates to the r package itself or the way I call bugs(), because I can use the same text files specifying the model and data directly in Winbugs and it runs fine (i.e syntax ok, compilation ok, updates slow but no traps). 2. The problem occurs in r only when I try to fit the model to multiple individuals, i.e. the data contains a matrix of step lengths (rows) and individuals (columns) instead of a vector for just one individual. I get the same error message regardless of the number of data rows in each column (I even tried just one). The model loops over the path of each animal, estimating a hidden movement state and their parameters. For 4 individuals with 100 data points each the data looks something like this: dat1 : num 100 dat2 : int 4 dat3 : num [1:4] 8 4 2 5 dat4 : num [1:100, 1:4] 1 1 1 1 1 2 2 2 2 2 ... dat5 : num [1:100, 1:4] 2 2 2 2 2 1 2 2 2 2 ... dat6 : num [1:100, 1:4] 16 34.3 33.5 27.9 14.9 ... dat7 : num [1:100, 1:4] 0.357 0.474 0.487 0.495 0.524 ... dat8: num [1:50, 1:4] 36.4 294.5 24.4 21.1 422.8 ... This is how I've called WinBugs in r: # write data to text file sp.data = list(dat1,dat2,dat3,dat4,dat5,dat6,dat7,dat8) bugs.data(sp.data, digits=5, data.file=dir1\\data1.txt) # test the model runs fit = bugs(data=paste(C:\\Users\\User1\\Documents\\dir1\\data1.txt,dataFile,sep=), inits=NULL, parameters.to.save=list('par1','par2','par3'), model.file=modelFile, debug=TRUE, n.chains=3, n.iter=20, n.burnin=3, n.thin=1, digits=4) ## The trap incompatible copy BugsScript.Action.Do [0436H] .a BugsScript.Action [025B6790H] .argNum INTEGER 0 .bugsCommands ARRAY 240 OF CHAR 7877X, 75A5X, 0B17X, 3701X ... .p ARRAY 3, 120 OF CHARElements .s BugsScanners.ScannerFields .scriptCommand ARRAY 240 OF CHAR #Bugs:check ... .vectorName BOOLEAN FALSE Services.Exec [0136H] .a Services.Action [025B6790H] .t POINTER [64E10170H] Services.IterateOverActions [02F4H] .p Services.Action [025B6790H] .t POINTER NIL .time LONGINT 4375656 Services.StdHook.Step [034DH] .h Services.StdHook[0248E380H] HostWindows.Idle [4A86H] .focus BOOLEAN FALSE .tick Controllers.TickMsg Fields .w HostWindows.Window NIL HostMenus.TimerTick [3422H] .lParam INTEGER 0 .opsControllers.PollOpsMsg Fields .wParam INTEGER 1 .wndINTEGER 1311298 Kernel.Try [3A61H] .a INTEGER 1311298 .b INTEGER 1 .c INTEGER 0 .h PROCEDURE HostMenus.TimerTick HostMenus.ApplWinHandler [3841H] .Proc PROCEDURE NIL .hitBOOLEAN FALSE .lParam INTEGER 0 .messageINTEGER 275 .resINTEGER 1664639202 .s ARRAY 256 OF SHORTCHAR ... .w INTEGER 1970768325 .wParam INTEGER 1 .wndINTEGER 1311298 system (pc=75778816H, fp=0027FB38H) system (pc=7577898DH, fp=0027FBB0H) system (pc=75778AB8H, fp=0027FC14H) system (pc=757790E2H, fp=0027FC24H) HostMenus.Loop [3BDEH] .done BOOLEAN FALSE .f SET {0..5} .n INTEGER 0 .resINTEGER 0 .w HostWindows.Window NIL Kernel.Start [2B8CH] .code PROCEDURE HostMenus.Loop ## my current R session specs: R version 2.15.0 (2012-03-30) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] R2WinBUGS_2.1-18 coda_0.14-7 lattice_0.20-6 loaded via a namespace (and not attached): [1] grid_2.15.0 tools_2.15.0 ## also tried these specs: R version 2.13.2 (2011-09-30) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3]
Re: [R] Separate Array Variable Content
Antony, I am now utterly confused. The conditions involve column names of X1. In your first post I assumed you just meant check for each row of x not columns. After Arun replied I realized that may have been a wrong assumption, but I just don't understand how you get, for example the last TRUE (for the 90). Also, you failed to ?dput again. X2 is a matrix? of what ? expressions ? characters ? any way it looks like a list or a column vector to me. To avoid loops, David's suggestion could maybe be expanded to work with ?do.call if is.list(conditions), also see ?outer for matrices, but again I don't really understand what you're after. Sorry. Ilai On Fri, Jun 1, 2012 at 12:53 AM, Akkara, Antony (GE Energy, Non-GE) antony.akk...@ge.com wrote: Hi iLai, ** ** What you showed below, almost same like I am also expecting. ** ** There is two matrix, 1) 1st - matrix contain values like this, ** ** ABC XYZ PQR ABC_CHECK XYZ_CHECK PQR_CHECK -- - 10 20 30 40 50 60 70 80 90 ** ** 2)2nd matrix have some conditions, need to check with 1st matrix columns. Like this, CHECK FOR CONDITION -- -** ** ABC_CHECKABC 10 XYZ 30 PQR 90 XYZ_CHECK ABC 9 XYZ 25 PQR 60 PQR_CHECK ABC 60 XYZ 79 PQR 100 ** ** ** ** Here I need to change the cell content that already created [*ABC_CHECK*, *XYZ_CHECK*, *PQR_CHECK*] So, Finally the result should get like this, ** ** ABC XYZ PQR ABC_CHECK XYZ_CHECK PQR_CHECK -- - 10 20 30 FALSETRUE FALSE 40 50 60 FALSEFALSEFALSE 70 80 90 FALSEFALSETRUE ** ** And can please tell me which is the best way to do this ?, Can we do this with-out loop ? And, Is it possible to put any other character instead of TRUE FALSE ?, like this Here For TRUE = T , FLASE = F ** ** ** ** ABC XYZ PQR ABC_CHECK XYZ_CHECK PQR_CHECK -- - 10 20 30 F T F 40 50 60 F F F 70 80 90 F F T ** ** ** ** Can I get an immediate reply ? ** ** - Thanks Antony. ** ** ** ** *From:* ila...@gmail.com [mailto:ila...@gmail.com] *On Behalf Of *ilai *Sent:* Wednesday, May 30, 2012 10:35 PM *To:* Akkara, Antony (GE Energy, Non-GE) *Cc:* r-help@r-project.org *Subject:* Re: [R] Separate Array Variable Content ** ** If you haven't done so you *must* read an Introduction to R. The only reason this is a problem is Myarray is a character string, not a function or expression to be evaluated. I think this will get you what you want though: # In the future use the output of ?dput to provide data to this list (MyMatrix - structure(c(10, 20, 30, 40, 50, 60, 70, 80, 90), .Dim = c(3L, 3L), .Dimnames = list(NULL, c(ABC, PQR, XYZ # DO NOT use rich font !!! in plain text it adds '*' to the bold names which is more than annoying... MyArray - c(ABC50,PQR50,ABC30 XYZ40) # finally the answer: sapply(MyArray,function(x) eval(parse(text=x),as.data.frame(MyMatrix))) HTH On Wed, May 30, 2012 at 12:44 AM, Rantony antony.akk...@ge.com wrote:*** * Hi, I am new in R, i have a matrix like this MyMatrix - *ABC PQRXYZ* 10 2030 40 5060 70 80
Re: [R] Separate Array Variable Content
If you haven't done so you *must* read an Introduction to R. The only reason this is a problem is Myarray is a character string, not a function or expression to be evaluated. I think this will get you what you want though: # In the future use the output of ?dput to provide data to this list (MyMatrix - structure(c(10, 20, 30, 40, 50, 60, 70, 80, 90), .Dim = c(3L, 3L), .Dimnames = list(NULL, c(ABC, PQR, XYZ # DO NOT use rich font !!! in plain text it adds '*' to the bold names which is more than annoying... MyArray - c(ABC50,PQR50,ABC30 XYZ40) # finally the answer: sapply(MyArray,function(x) eval(parse(text=x),as.data.frame(MyMatrix))) HTH On Wed, May 30, 2012 at 12:44 AM, Rantony antony.akk...@ge.com wrote: Hi, I am new in R, i have a matrix like this MyMatrix - *ABC PQRXYZ* 10 2030 40 5060 70 8090 And, i have an array containing some conditions like this, MyArray - c(*ABC*50,*PQR*50,*ABC*30 * XYZ*40) ABC50 PQR50 ABC30 XYZ40 My purpose what is, i need to check this conditions in *MyArray* with *MyMatrix* value for particular column How it is possible ? - Thanks Antony. -- View this message in context: http://r.789695.n4.nabble.com/Separate-Array-Variable-Content-tp4631800.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. [[alternative HTML version deleted]] __ 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] lattice: add a marginal histogram on top of the colorkey of a levelplot?
?plot.trellis. In general something like mlp- levelplot(... mhist- histogram(... plot(mlp,split=c(1,2,1,2),more=T) plot(mhist,split=c(1,1,1,2),more=F) You will need to do some work on the padding and layout widths to get the distances right (I assume the key is to be the x-axis of the histogram). Also, might be worth checking out ?c.trellis in package latticeExtra because I find sometimes easier to draw the key as a separate grob and use x.same=T. Up to you. Cheers On Tue, May 29, 2012 at 12:09 PM, Andy Bunn andy.b...@wwu.edu wrote: Lattice experts: Can you think of a way to produce a levelplot as below and then add a histogram of the z variable to the top margin of the plot that would sit on top of the color key? x - seq(pi/4, 5 * pi, length.out = 100) y - seq(pi/4, 5 * pi, length.out = 100) r - as.vector(sqrt(outer(x^2, y^2, +))) grid - expand.grid(x=x, y=y) grid$z - cos(r^2) * exp(-r/(pi^3)) my.levs - seq(-1,1,by=0.1) my.cols - grey(0:length(my.levs)/length(my.levs)) levelplot(z~x*y, grid, at=my.levs, scales=list(log=e), xlab=, ylab=,colorkey = list(space = 'top'),col.regions = my.cols) # is there a way to add a marginal histogram above the colorkey? histogram(~z, grid, breaks=my.levs,col=my.cols,xlab='',ylab='', scales = list(draw = FALSE), par.settings = list(axis.line = list(col = transparent))) __ 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. [[alternative HTML version deleted]] __ 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] glm(weights) and standard errors
I'm confused (I bet David is too). First and last models are the same, what do SE's have to do with anything ? naive - glm(extra ~ group, data=sleep) imputWrong - glm(extra ~ group, data=sleep10) imput - glm(extra ~ group, data=sleep10,weights=rep(0.1,nrow(sleep10))) lapply(list(naive,imputWrong,imput),anova) sapply(list(naive,imuptWrong,imput),function(x) vcov(x)[1,1]/vcov(x)[2,2]) # or another way to see it (adjust for the DF) coef(summary(naive))[2,2] - sqrt(198)/sqrt(18) * coef(summary(imput))[2,2] coef(summary(naive))[2,2] - sqrt(198)/sqrt(18) * coef(summary(imputWrong))[2,2] Are you sure you are interpreting Wood et al. correctly ? (I haven't read it, this is not rhetorical) On Wed, May 23, 2012 at 7:49 PM, Steve Taylor steve.tay...@aut.ac.nz wrote: Re: coef(summary(glm(extra ~ group, data=sleep[ rep(1:nrow(sleep), 10L), ] ))) Your (corrected) suggestion is the same as one of mine, and doesn't do what I'm looking for. -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Tuesday, 22 May 2012 3:37p To: Steve Taylor Cc: r-help@r-project.org Subject: Re: [R] glm(weights) and standard errors On May 21, 2012, at 10:58 PM, Steve Taylor wrote: Is there a way to tell glm() that rows in the data represent a certain number of observations other than one? Perhaps even fractional values? Using the weights argument has no effect on the standard errors. Compare the following; is there a way to get the first and last models to produce the same results? data(sleep) coef(summary(glm(extra ~ group, data=sleep))) coef(summary(glm(extra ~ group, data=sleep, weights=rep(10L,nrow(sleep) Here's a reasonably simple way to do it: coef(summary(glm(extra ~ group, data=sleep[ rep(10L,nrow(sleep)), ] ))) -- David. sleep10 = sleep[rep(1:nrow(sleep),10),] coef(summary(glm(extra ~ group, data=sleep10))) coef(summary(glm(extra ~ group, data=sleep10, weights=rep(0.1,nrow(sleep10) My reason for asking is so that I can fit a model to a stacked multiple imputation data set, as suggested by: Wood, A. M., White, I. R. and Royston, P. (2008), How should variable selection be performed with multiply imputed data?. Statist. Med., 27: 3227-3246. doi: 10.1002/sim.3177 Other suggestions would be most welcome. __ 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] Manually modifying an hclust dendrogram to remove singletons
Can't put my finger on it but something about your idea rubs me the wrong way. Maybe it's that the tree depends on the hierarchical clustering algorithm and the choice on how to trim it should be based on something more defensible than avoid singletons. In this example Hawaii is really different than New Hampshire, why would you want them clustered together ? But, it's your work, field of study, whatever. If you are going to do it anyway, one way would be to loop over cut heights: hc - hclust(dist(USArrests), ave) plot(hc) hr - range(hc$height) tol- diff(hr)/100# set tolerance level for(i in seq(1e-4+hr[1],hr[2],tol)){ hcc - rect.hclust(hc,h=i) if(all(sapply(hcc,length)1)) break } str(hcc) # or if you prefer dendrogram dend1- as.dendrogram(hc) for(i in seq(1e-4+hr[1],hr[2],tol)){ dend2 - cut(dend1,h=i) if(all(sapply(dend2$lower,function(x) attr(x,'members'))1)) break } dend2 Cheers On Thu, May 24, 2012 at 10:31 AM, r-help.20.tre...@spamgourmet.com wrote: Dear R-Help, I have a clustering problem with hclust that I hope someone can help me with. Consider the classic hclust example: hc - hclust(dist(USArrests), ave) plot(hc) I would like to cut the tree up in such a way so as to avoid small clusters, so that we get a minimum number of items in each cluster, and therefore avoid singletons. e.g. in this example, you can see that Hawaii is split off onto its own at quite a high level. I would like to avoid having a single item clustered on its own like this. How can I achieve this? I have tried manually modifying the tree using dendrapply but have not been able to produce a valid solution thus far.. Suggestions are welcome. Best wishes, Mark __ 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] Lattice: Add abline to Single Value qqmath() Plot
On Tue, May 15, 2012 at 4:19 PM, Rich Shepard rshep...@appl-ecosys.com wrote: On Tue, 15 May 2012, David L Carlson wrote: David, I have 130 plots to produce (30 chemicals un-transformed and three transformations). The R console insists that I retype each of the 6 lines (adding a prepanel.qqmathline line) each time. Makes more sense to put all the commands in a script that I can run within R using source('metals.R'). Apologies in advance if I misinterpret R console insists that I retype ... but actually makes more sense (than sourcing a script) to use the group argument (see the last example in ?qqmath) as in 4 groups in each of 30 panels, or allow.multiple=T, outer=T if you really want separate panels for each transformation. Also can use layout=c(1,1,120) if you need each in a separate page - or say c(3,2,20) for 20 pages of 6 panels each, etc. Regarding your script, there is a syntax error: However, R appears to not see that the first line does not terminate the command and the following lines are continuations. The source is, pdf('ag_norm.pdf') qqmath(~ Ag | factor(basin), data = surfchem.cast, main = 'Silver (Untransformed'), Right here the ' is on the wrong side of ) causing the error: Error in source(metals.R) : metals.R:4:83: unexpected ',' because the plot is done with ) with unexpected , following. You want ...main = ' Silver (Untransformed) ' , Personally I find using spaces whenever possible helps me avoid this type of syntax error (which is the most frustrating...) Cheers 3: pdf('ag_norm.pdf') 4: qqmath(~ Ag | factor(basin), data = surfchem.cast, main = 'Silver (Untransformed'), with a caret under the last ')'. What syntax error did I commit in the call to qqmath() above? Rich -- Richard B. Shepard, Ph.D. | Integrity - Credibility - Innovation Applied Ecosystem Services, Inc. | Helping Ensure Our Clients' Futures http://www.appl-ecosys.com Voice: 503-667-4517 Fax: 503-667-8863 __ 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] Lattice side by side boxplots with average
On Tue, May 8, 2012 at 9:32 AM, maxbre mbres...@arpa.veneto.it wrote: and then with the superposition of relative average values to the boxplots, i.e. something like: panel.points(…, mean.values, ..., pch = 17) Almost. You need to give panel.points the new x, and make sure the right mean.values go to the right place because the order of tapply output is not necessarily the same order as y, even though I never quite understood why myself... Bottom line, this should it: bwplot(yield ~ site, data = barley, groups=year, pch = |, box.width = 1/3, auto.key = list(points = FALSE, rectangles = TRUE, space = right), panel = panel.superpose, panel.groups = function(x, y, ..., group.number) { panel.bwplot(x + (group.number-1.5)/3, y, ...) mean.values - tapply(y, x, mean) panel.points(x + (group.number-1.5)/3, mean.values[x], pch=17) }) Cheers but for some reasons I’m not able to properly combine these code snippets in a successful way any help much appreciated, thank you -- View this message in context: http://r.789695.n4.nabble.com/Lattice-side-by-side-boxplots-with-average-tp4617831.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] error bars for a barchart
Hi, I think the issue is not respecting the groups but finding the x-location of the center of bars in panel.barchart(groups,...). Don't know about the memisc package, but doesn't look like it provides an easy solution. This is how I do it: http://www.mail-archive.com/r-help@r-project.org/msg162299.html Might need to modify some for your data. HTH On Tue, May 1, 2012 at 8:01 AM, Beatriz De Francisco beatriz.defranci...@sams.ac.uk wrote: Hi I have the following barchart to which I want to add error bars. library(lattice) barchart(Change~fTreat,groups=Process,change, auto.key=list(points=FALSE,rectangles=TRUE), panel=function(x, y,...){ panel.barchart(x,y,origin = 0,...); panel.abline(h=0,col=black,...); } ) I have tried using the panel.errbars from the memisc package which works great for xyplots, but when I add it to my code it does not respect the groups. library(memisc) barchart(cbind(Change,lower,upper)~fTreat,groups=Process,change, ylab=Pocertage change, ylim=-115:50, scales=list(alternating=FALSE, tick.number=7, tck=c(-1,0)), panel=function(x, y,groups,...){ panel.barchart(x,y=change$Change,groups=change$Process,origin = 0,...); panel.abline(h=0,col=black,...); panel.errbars(x,y,make.grid=none,ewidth=0.2,type=n,...) } ) Any ideas of how to add error bars to my plot either using the panel.errbars or any other function? The data: structure(list(Treat = structure(c(3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L), .Label = c(12-380, 12-750, 8-380, 8-750), class = factor), Process = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c(Resp, Cal), class = c(ordered, factor)), Change = c(-33.05, -34.74, 20.94, 18.06, 6.85, -28.57, -8.1, -78.72), upper = c(-13.22896628, -28.61149669, 31.29930461, 27.30173776, 39.73271282, 9.458372948, 13.11035572, -47.03745704), lower = c(-52.86120694, -40.87446411, 10.57421563, 8.822042178, -26.03144161, -66.60447035, -29.30563327, -110.3973761), fTreat = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c(8-380, 8-750, 12-380, 12-750), class = c(ordered, factor))), .Names = c(Treat, Process, Change, upper, lower, fTreat), row.names = c(NA, -8L), class = data.frame) Regards Beatriz de Francisco Mora PhD Student The Scottish Association for Marine Science Scottish Marine Institute Oban PA37 1QA Tel: 06131 559000 (switchboard) Fax: 01631559001 E. beatriz.defranci...@sams.ac.ukmailto:beatriz.defranci...@sams.ac.uk http://www.smi.ac.uk/beatriz-de-franciso The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail. [[alternative HTML version deleted]] __ 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] error bars for a barchart
Thank you for your example. I only skimmed it, but since both solutions use nlevels and box.ratio it is no surprise we end up at the same place (although I do think your g-median is nicer than my 3/4). Thing is, I wouldn't call either of these simple... would be nice if one could just query the new centers, but I don't know if there is a way without hacking panel.barchart itself ? Cheers On Tue, May 1, 2012 at 1:34 PM, Walmes Zeviani walmeszevi...@gmail.com wrote: I have a repoducibe example here http://ridiculas.wordpress.com/2011/11/23/media-e-desvio-padrao-de-muitas-variaveis-separado-por-grupos/ Sorry for it be in Portuguese. Walmes. == Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: wal...@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 == __ 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] Create new Vector based on two colums
On Wed, Apr 25, 2012 at 6:14 AM, Patrick Hausmann patrick.hausm...@covimo.de wrote: Hello, I am trying to get a new vector 'x1' based on the not NA-values in column 'a' and 'b'. I found a way but I am sure this is not the best solution. So any ideas on how to optimize this would be great! If by optimize you mean no loops, you could try (df- structure(list(a = structure(c(NA, 1L, 2L, 3L, 4L, NA, 6L, 6L ), .Label = c(a1, a2, b1, b2, b3, d1), class = c(ordered, factor)), b = structure(c(1L, NA, 2L, NA, 4L, 5L, 6L, 6L), .Label = c(a1, a2, b1, b2, b3, d1), class = c(ordered, factor))), .Names = c(a, b), row.names = c(NA, -8L), class = data.frame)) x0 - factor(paste(ifelse(is.na(df[,1]),'',df[,1]), ifelse(is.na(df[,2]),'',df[,2]), sep='')) df$x1 - as.numeric(x0) # only needed for a numeric vector as in your solution df HTH PS - In the future please avoid df and data as object names, as they mask R functions. m - factor(c(a1, a1, a2, b1, b2, b3, d1, d1), ordered = TRUE) df - data.frame( a= m, b = m) df[1,1] - NA df[4,2] - NA df[2,2] - NA df[6,1] - NA df w - !apply(df, 2, is.na) v - apply(w, 1, FUN=function(L) which(L == TRUE)[[1]]) for (i in 1:nrow(df) ) { g[i] - df[i, v[i]] } df$x1 - g Thanks for any help Patrick __ 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] Remove top/right border from lattice plots
You need to do a little more work to add the components you want back in. I think you want something like: xyplot( Sepal.Length ~ Petal.Length, auto.key=T, data=iris, par.settings = list(axis.line = list(col = 0)),scales=list(col=1,tck=c(1,0)), panel=function(...){ lims - current.panel.limits() panel.xyplot(...) panel.abline(h=lims$ylim[1],v=lims$xlim[1]) }) HTH On Tue, Apr 24, 2012 at 12:10 PM, Jon Zadra jr...@virginia.edu wrote: Hi, I've done my best to search for a solution to this, but had no luck. How can I create a lattice plot (I'm using xyplot() ) that does not have a border on the top and right side, but keeps the bottom/left axes? So far all I've found is this, which inserted into the xyplot call removes all 4 borders: / par.settings = list(axis.line = list(col = 0))/ xyplot( Sepal.Length ~ Petal.Length, auto.key=T, data=iris, par.settings = list(axis.line = list(col = 0))) Thanks in advance, - Jon / / -- Jon Zadra Department of Psychology University of Virginia P.O. Box 400400 Charlottesville VA 22904 (434) 982-4744 za...@virginia.edu [[alternative HTML version deleted]] __ 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] automating a script to read a file
On Tue, Apr 24, 2012 at 2:09 PM, steve_fried...@nps.gov wrote: library(latticeExtra) doubleYScale(hist(mydata, breaks=20, prob=T, xlim=c(-100, 2000), plot.spdf(x), use.style=FALSE) This does not work as doubleYScale expects histogram and densityplot, and I'd like to use the plot.spdf routine in its place. Maybe it doesn't work because ?hist is base graphics, not the same as ?histogram in lattice. You did not provide plot.spdf or any data, so this just a place to start type response. Cheers Any Suggestions would be greatly appreciated. I'm working with R 2.15.0 (2012-03-12) Platform i386-pc-mingw32/ie86 (32-bit) Thanks Steve Steve Friedman Ph. D. Ecologist / Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 Petr Savicky savi...@cs.cas.c z To Sent by: r-help@r-project.org r-help-bounces@r- cc project.org Subject Re: [R] automating a script to read 04/23/2012 04:42 a file PM On Mon, Apr 23, 2012 at 04:02:45PM -0400, steve_fried...@nps.gov wrote: Hi, The following script (which I did not develop) is used to calculate and plot a skewed normal curve. The script currently requires the user to input six parameters, rather than reading these directly from a file. I've been spinning wheels here, trying to figure out how to modify the script to automate it. I have four data sets, each in excess of 300 records that I need to process. My initial thoughts were to use the lapply and use a pdf graphic device to capture the plots to do this, but my R programming skills are too limited to determine how to best accomplish this. Hi. If you read the parameters from a file and put them to a matrix, then all the plots may be produced using a loop like the following. #some parameters p - matrix(1:18, nrow=3, ncol=6) for (i in 1:nrow(p)) { plot.spdf(p[i, 1], p[i, 2], p[i, 3], p[i, 4], p[i, 5], p[i, 6]) readline(press Enter to continue) } If you use pdf() for sending the graphics to a file, then remove the readline command. Hope this helps. Petr Savicky. __ 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-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] automating a script to read a file
On Tue, Apr 24, 2012 at 6:00 PM, Steve Friedman skfgla...@gmail.com wrote: The original post does contain the function plot.spdf and some sample data. That's great. And who's responsibility is it to make sure we have context for THIS post ? This is a mailing list, not a forum and MY mail client doesn't keep track of YOUR postings. BTW, you are the one seeking our help, so even if you think it was a picky request, a proper response would be to simply post your function+data set. Not send us looking for some original post. I thought I also made it clear that I understood that hist and histogram are not the same. No you didn't. But now IT IS clear you don't realize grid and base graphics don't mix. I am looking for a way to use the alternatives in a function similar to but not identical to doubleYScale. LatticeExtra functions expect any lattice plots, including local (user defined) panel/plot functions, if only you would have posted plot.spdf maybe you would have gotten a solution by now... If plot.spdf is actually a base graphics plotter and you just stumbled upon DoubleYscale somehow, ?par ?axis hist(...,add=T) are all available to you. Best Steve On Apr 24, 2012 7:45 PM, ilai ke...@math.montana.edu wrote: On Tue, Apr 24, 2012 at 2:09 PM, steve_fried...@nps.gov wrote: library(latticeExtra) doubleYScale(hist(mydata, breaks=20, prob=T, xlim=c(-100, 2000), plot.spdf(x), use.style=FALSE) This does not work as doubleYScale expects histogram and densityplot, and I'd like to use the plot.spdf routine in its place. Maybe it doesn't work because ?hist is base graphics, not the same as ?histogram in lattice. You did not provide plot.spdf or any data, so this just a place to start type response. Cheers Any Suggestions would be greatly appreciated. I'm working with R 2.15.0 (2012-03-12) Platform i386-pc-mingw32/ie86 (32-bit) Thanks Steve Steve Friedman Ph. D. Ecologist / Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 Petr Savicky savi...@cs.cas.c z To Sent by: r-help@r-project.org r-help-bounces@r- cc project.org Subject Re: [R] automating a script to read 04/23/2012 04:42 a file PM On Mon, Apr 23, 2012 at 04:02:45PM -0400, steve_fried...@nps.gov wrote: Hi, The following script (which I did not develop) is used to calculate and plot a skewed normal curve. The script currently requires the user to input six parameters, rather than reading these directly from a file. I've been spinning wheels here, trying to figure out how to modify the script to automate it. I have four data sets, each in excess of 300 records that I need to process. My initial thoughts were to use the lapply and use a pdf graphic device to capture the plots to do this, but my R programming skills are too limited to determine how to best accomplish this. Hi. If you read the parameters from a file and put them to a matrix, then all the plots may be produced using a loop like the following. #some parameters p - matrix(1:18, nrow=3, ncol=6) for (i in 1:nrow(p)) { plot.spdf(p[i, 1], p[i, 2], p[i, 3], p[i, 4], p[i, 5], p[i, 6]) readline(press Enter to continue) } If you use pdf() for sending the graphics to a file, then remove the readline command. Hope this helps. Petr Savicky. __ 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-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] Fwd: User defined panel functions in lattice
Duncan, First off, I admit it is not clear to me what you are trying to achieve and more importantly, why? by why I mean 1) I don't see the advantage of writing one general panel function for completely different situations (one/multiple smoothers, grouping levels etc.) 2) your intended result as I understand it seems rather cluttered, google chartjunk. 3) I am unfamiliar with locfit package, but are we reinventing the wheel here ? i.e. will modifying settings in xyplot(y ~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ? With your initial reproducible example (thank you) it was easy to eliminate the errors, but clearly the resulting plots are not what you intended (continue inline): On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay mac...@northnet.com.au wrote: snip 3. What I want to be able to add in the above is extra lines with different values of nn. I think I will have to modify panel.Locfit so that it goes through different values of nn in each of the panels and groups if I want different colours for extra lines with different nn values Yes you could. There are several options: add group.number to the arguments of panel.locfit and use it to make nn a vector, along the lines of panel.foo - function(x,y,group.number,theta,...){ smpar - theta[group.number] panel.loess(x,y,smpar,...) panel.xyplot(x,y,...) } xyplot(y~x,xx,group=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo) # or xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1), panel=panel.superpose,panel.groups=panel.foo) Here you will need to modify the Farm group to 6 levels - 3*two smoothers. You could make nn a list and loop over it inside the panel function. Looks like you tried something like that with specifying 2 panel.Locfit, one suggestion to your code: panel.Locfit(x,y,...) # default 0.7 panel.Locfit(x,y,nn=0.9) # i.e. remove the ... to avoid clashes Finally, use ?trellis.focus to plot the second smoother post-hoc. also the latticeExtra package has many useful tools to create layers of the same (or different) plot with different settings. 4 Produce an extra line for a fit for all the groups in 1/2+ panels. As for 3 but I do not know how to group all the x and y's for each of the panes using panel.groups Why does it matter ? seems you have failed to learn the lesson from the first post - the same functionality applies to 1 as to multiple panels. Does each panel have a different grouping structure ? use packet.number() for panels similar to group.number idea. I need to do this and then scale up for a panel function to include confidence bands than expand the xlim,ylim or scales in ?xyplot For the record making Farm and Padd factors. With 1 panel and groups = Farm works with the extra line the same colour for its group a similar situation for the three panels when conditioned by Farm and groups = Pad Like I said I am a little lost on this problem but I hope this helps giving some direction. Cheers xyplot(y ~x, xx, groups = Farm, par.settings = list(strip.background = list(col = transparent), superpose.line = list(col = c(black,grey), lwd = c(1,2,3), lty = c(2,1,3)), superpose.symbol = list(cex = c(0.8, 0.7,0.7), col = c(red,black,blue), pch = c(20,4,16)) ), auto.key=list(lines=T,points = T,rectangles=F), panel = panel.superpose, panel.groups=function(x,y, ...){ panel.xyplot(x,y,...) panel.Locfit(x,y,...) # default 0.7 panel.Locfit(x,y,nn=0.9,...) } ) ## xyplot Regards Duncan At 02:12 20/04/2012, you wrote: On Thu, Apr 19, 2012 at 2:30 AM, Duncan Mackay mac...@northnet.com.au wrote: Hi xyplot(y ~x|Farm,xx, groups = Padd, panel = panel.superpose, panel.groups=function(x,y, ...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) ## xyplot The above works nicely and also without par.setting giving lattice defaults. The par.setting is handy for a lot of graphs that I do. But when I tried a 1 panel plot I get the error message. xyplot(y ~x,xx, groups = Farm, auto.key=TRUE, panel = function(x,y, ...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) These two plots are NOT THE SAME. Did you want the same as the first but with groups being Farm and Padd ignored ? in that case you (again) need a
Re: [R] Fwd: User defined panel functions in lattice
Oops - that is reply all On Fri, Apr 20, 2012 at 5:29 PM, David Winsemius dwinsem...@comcast.net wrote: I'm a bit puzzled by this exchange. I know there is a 'panel.locfit', but you two are spelling it differently. Can you explain why you are doing so? Hi David, Thanks for stepping in. panel.Locfit is the OP's local function (or just a wrapper ?) which I believe is here http://www.mail-archive.com/r-help@r-project.org/msg167164.html Note the two errors OP encountered (solved down the thread) were caused by the way he called the function in xyplot, not by panel.Locfit itself, which I did not modify. I guess now the issue is how to generalize panel.Locfit somehow, but I am not sure how. I suspect the problem is not my understanding but that there really isn't any one specific problem here for the list to solve, though, again, I am known for misinterpreting OP requests... :) ?panel.locfit As I said, I am unfamiliar with the package - but this doesn't surprise me. Thank you for pointing it out, wish you've noticed the exchange sooner... Cheers ?panel.Locfit No documentation for ‘panel.Locfit’ in specified packages and libraries: you could try ‘??panel.Locfit’ ?panel.locfit {locfit} R Documentation Locfit panel function Description This panel function can be used to add locfit fits to plots generated by trellis. I am trying to construct a function/s to cover as many of the normal situations as possible. Usually I have to amend colours lines etc to distinguish the data. I want to cover a number of situations 1 Conditioned by panel no groups 2 Conditioned by panel and groups. 3 Multiple values for above - to show colleagues (EDA) 4 Conditioned by panel and groups + an overall fit for all the data within a panel 5 Several y values in a panel eg Y1+Y2 and outer = FALSE with a fit for each of Y1 and Y2 I am trying to cover as many of the above situations in 1 function before resulting to trellis.focus or overlaying. The graphs that I normally create are not simple, generally involving useOuterStrips which may have different y scales for panel rows (combindeLimits/manual) and different panel row heights. locfit is like loess but 2 arguments for smoothing; the degree of smoothing produced by the defaults is approximately that of loess but I normally need less smoothing (the same would be apply for loess). Most of the questions to Rhelp are for 1 with just a small number for 5 and they are not applicable here and understanding the requirements for passing arguments in these different situations I find difficult. I would like to reduce the number of panel functions to the minimum to cover the general situaltions because my graphs are usually not normal and then add to them for a particular situation. Regards Duncan At 01:38 21/04/2012, you wrote: Duncan, First off, I admit it is not clear to me what you are trying to achieve and more importantly, why? by why I mean 1) I don't see the advantage of writing one general panel function for completely different situations (one/multiple smoothers, grouping levels etc.) 2) your intended result as I understand it seems rather cluttered, google chartjunk. 3) I am unfamiliar with locfit package, but are we reinventing the wheel here ? i.e. will modifying settings in xyplot(y ~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ? With your initial reproducible example (thank you) it was easy to eliminate the errors, but clearly the resulting plots are not what you intended (continue inline): On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay mac...@northnet.com.au wrote: snip 3. What I want to be able to add in the above is extra lines with different values of nn. I think I will have to modify panel.Locfit so that it goes through different values of nn in each of the panels and groups if I want different colours for extra lines with different nn values Yes you could. There are several options: add group.number to the arguments of panel.locfit and use it to make nn a vector, along the lines of panel.foo - function(x,y,group.number,theta,...){ smpar - theta[group.number] panel.loess(x,y,smpar,...) panel.xyplot(x,y,...) } xyplot(y~x,xx,group=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo) # or xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1), panel=panel.superpose,panel.groups=panel.foo) Here you will need to modify the Farm group to 6 levels - 3*two smoothers. You could make nn a list and loop over it inside the panel function. Looks like you tried something like that with specifying 2 panel.Locfit, one suggestion to your code: panel.Locfit(x,y,...) # default 0.7 panel.Locfit(x,y,nn=0.9) # i.e. remove the ... to avoid clashes Finally, use ?trellis.focus to plot the second smoother post-hoc. also the latticeExtra package has many useful tools to create layers of the
Re: [R] Fwd: User defined panel functions in lattice
On Fri, Apr 20, 2012 at 8:15 PM, David Winsemius dwinsem...@comcast.net wrote: Another puzzle. In the original posting there was this segment: --- but gives an error message without par.settings if i want to add panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...) Error using packet 1 formal argument Iwd matched by multiple actual arguments --- On my mailer that formal argument starts with a capital I but the code seemed to be attempting a lowercase l. I could never see reason offered for defining a new panel.locfit, but I'm wondering if the sometimes similar representation of those two different letters could be causing an obscure conflict? If that is indeed what's happening, it will be the first time for me. My mailer shows upper case L too, I assume that this is correct and the OP's intention is exactly that - not redefine panel.locfit but create his own (if that is good use of his/our time is another matter altogether). Seems to me the source of this error was, as the error message suggested, simply the default formals: panel.Locfit - function(x,y, nn, h, col, col.line, lwd = lwd, lty = lty, ...){ ... } Which is why this solved it: xyplot(y ~x,xx, groups = Farm, auto.key=TRUE,lwd=1:3, panel = panel.superpose,panel.groups=function(x,y,nn,...){ panel.Locfit(x,y,nn=.9,...) panel.xyplot(x,y,...) } ) With my new found understanding of the OP's real intentions, maybe a call to trellis.par.get('superpose.line') inside panel.Locfit is the answer? Cheers -- David. Cheers ?panel.Locfit No documentation for ‘panel.Locfit’ in specified packages and libraries: you could try ‘??panel.Locfit’ ?panel.locfit {locfit} R Documentation Locfit panel function Description This panel function can be used to add locfit fits to plots generated by trellis. I am trying to construct a function/s to cover as many of the normal situations as possible. Usually I have to amend colours lines etc to distinguish the data. I want to cover a number of situations 1 Conditioned by panel no groups 2 Conditioned by panel and groups. 3 Multiple values for above - to show colleagues (EDA) 4 Conditioned by panel and groups + an overall fit for all the data within a panel 5 Several y values in a panel eg Y1+Y2 and outer = FALSE with a fit for each of Y1 and Y2 I am trying to cover as many of the above situations in 1 function before resulting to trellis.focus or overlaying. The graphs that I normally create are not simple, generally involving useOuterStrips which may have different y scales for panel rows (combindeLimits/manual) and different panel row heights. locfit is like loess but 2 arguments for smoothing; the degree of smoothing produced by the defaults is approximately that of loess but I normally need less smoothing (the same would be apply for loess). Most of the questions to Rhelp are for 1 with just a small number for 5 and they are not applicable here and understanding the requirements for passing arguments in these different situations I find difficult. I would like to reduce the number of panel functions to the minimum to cover the general situaltions because my graphs are usually not normal and then add to them for a particular situation. Regards Duncan At 01:38 21/04/2012, you wrote: Duncan, First off, I admit it is not clear to me what you are trying to achieve and more importantly, why? by why I mean 1) I don't see the advantage of writing one general panel function for completely different situations (one/multiple smoothers, grouping levels etc.) 2) your intended result as I understand it seems rather cluttered, google chartjunk. 3) I am unfamiliar with locfit package, but are we reinventing the wheel here ? i.e. will modifying settings in xyplot(y ~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ? With your initial reproducible example (thank you) it was easy to eliminate the errors, but clearly the resulting plots are not what you intended (continue inline): On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay mac...@northnet.com.au wrote: snip 3. What I want to be able to add in the above is extra lines with different values of nn. I think I will have to modify panel.Locfit so that it goes through different values of nn in each of the panels and groups if I want different colours for extra lines with different nn values Yes you could. There are several options: add group.number to the arguments of panel.locfit and use it to make nn a vector, along the lines of panel.foo - function(x,y,group.number,theta,...){ smpar - theta[group.number] panel.loess(x,y,smpar,...) panel.xyplot(x,y,...) } xyplot(y~x,xx,group=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo) # or xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1),
Re: [R] Displaying data in Trellis
On Thu, Apr 19, 2012 at 2:55 AM, ce41188 stevelavr...@hotmail.com wrote: Thank you for the reply. The more I look at this, the more confused I become. I was wondering if you could walk me through this a little more in detail, in particular the panel method function of doing things. It may be obvious to many, but I haven't really used Trellis before, so I'm still at the bottom of the learning curve. In that case I recommend getting a hold of @Book{, title = {Lattice: Multivariate Data Visualization with R}, author = {Deepayan Sarkar}, publisher = {Springer}, address = {New York}, year = {2008}, note = {ISBN 978-0-387-75968-5}, url = {http://lmdvr.r-forge.r-project.org}, } Or working through examples of help provided by Deepayan Sarkar or Felix Andrews in the archives. I think what confuses me the most is the whichpan variable - what does the 1+ do? For those not on nabble missing the context, it was something like mycols[1+(packet.num()==4)]. packet.number()==4 is logical, i.e. returning 0/1. There is no mycols[0]. Replace the 1 with any number to be in another place in the mycols vector. You got the rest, but I think you may have missed the main lesson that often, as in this case, there is a simple (better) solution. e.g. here there is no panel function needed to access the colors, you can get the same effect with xyplot(rnorm(60)~runif(60)|gl(6,10),groups=gl(6,10),col=c(1,1,1,2,1,1)) This is same as my first example in a cleaner (but less customizable) form. Cheers -- View this message in context: http://r.789695.n4.nabble.com/Displaying-data-in-Trellis-tp4567920p4570271.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] Fwd: User defined panel functions in lattice
On Thu, Apr 19, 2012 at 2:30 AM, Duncan Mackay mac...@northnet.com.au wrote: Hi xyplot(y ~x|Farm,xx, groups = Padd, panel = panel.superpose, panel.groups=function(x,y, ...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) ## xyplot The above works nicely and also without par.setting giving lattice defaults. The par.setting is handy for a lot of graphs that I do. But when I tried a 1 panel plot I get the error message. xyplot(y ~x,xx, groups = Farm, auto.key=TRUE, panel = function(x,y, ...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) These two plots are NOT THE SAME. Did you want the same as the first but with groups being Farm and Padd ignored ? in that case you (again) need a panel.groups: xyplot(y ~x,xx, groups = Farm, auto.key=TRUE, panel = panel.superpose,panel.groups=function(x,y,...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) If I want to plot another curve with different smoothing but gives an error message without par.settings if i want to add panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...) Error using packet 1 formal argument Iwd matched by multiple actual arguments It is all in the way you initially specified how to pass the arguments for panel.Locfit. This works without error: xyplot(y ~x,xx, groups = Farm, auto.key=TRUE,lwd=1:3, panel = panel.superpose,panel.groups=function(x,y,nn,...){ panel.Locfit(x,y,nn=.9,...) panel.xyplot(x,y,...) } ) HTH I also need to plot a smoothed line for all groups trying groups, subscripts and panel.groups as arguments without success Any solutions to solve the above will be gratefully received and faithfully applied. Duncan sessionInfo() R version 2.15.0 (2012-03-30) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252 LC_NUMERIC=C LC_TIME=English_Australia.1252 attached base packages: [1] datasets utils stats graphics grDevices grid methods base other attached packages: [1] locfit_1.5-7 R.oo_1.9.3 R.methodsS3_1.2.2 foreign_0.8-49 chron_2.3-42 MASS_7.3-17 latticeExtra_0.6-19 RColorBrewer_1.0-5 [9] lattice_0.20-6 loaded via a namespace (and not attached): [1] tools_2.15.0 Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email home: mac...@northnet.com.au __ 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] Displaying data in Trellis
On Wed, Apr 18, 2012 at 8:45 AM, slavrenz stevelavr...@hotmail.com wrote: I would like to display with the xyplot() function for several states. I will have a total of 6 plots, I need to plot the points of one of the states in a different color than all the rest, such that they can be more easily referenced in a presentation. Does anyone know what I can use for this. I'm guessing that I will have to write my own panel function, You guessed wrong... One way is xyplot(rnorm(60)~runif(60)|gl(6,10),groups=c(rep(1,30),rep(2,10),rep(1,20))) Or even as a panel function it is rather simple xyplot(rnorm(60)~runif(60)|gl(6,10), panel=function(x,y,...){ mycols - trellis.par.get('superpose.symbol')$col whichpan - 1+(packet.number()==4) panel.xyplot(x,y,col=mycols[whichpan],...) } ) Working through the examples in xyplot and applying a little brain you should have been able to come up with a way that best fits your situation. If for some reason you do get stuck in the future, please post a reproducible example. BTW, if this is for your own dissertation/presentation - why can't be changed ? shouldn't you be more worried about presenting a non suitable plot than it's colors ? Cheers View this message in context: http://r.789695.n4.nabble.com/Displaying-data-in-Trellis-tp4567920p4567920.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] how to plot separate lm ablines on the same xyplot by group
On Wed, Apr 18, 2012 at 2:07 PM, Louis Plough lplo...@usc.edu wrote: If you could lead me to an example with code, that would help me figure out how to do it for my function The states example in ?xyplot uses groups and subscripts in a panel function I read it, but I guess I don't quite understand which arguments to pass panel.groups to get different lm objects based on the two groups within Food. You are confused. panel.superpose != panel.groups. You probably wanted something like (and next time please provide data): x - rep(1:10,2) y - rnorm(20,rep(1:2,each=10)*x) g - gl(2,10) xyplot(y~x,groups=g, panel=panel.superpose, panel.groups=function(x,y,...){ tmp.lm-lm(y~x) panel.abline(tmp.lm) panel.text(2, coef(tmp.lm)%*%c(1,2), label=format(tmp.lm$coefficients[2], digits=4), pos=4) panel.xyplot(x,y,...) }) HTH On Wed, Apr 18, 2012 at 3:44 PM, Bert Gunter gunter.ber...@gene.comwrote: Please read ?panel.superpose again and pay attention to the panel.groups argument, where this can be specified. -- Bert On Wed, Apr 18, 2012 at 12:34 PM, Louis Plough lplo...@usc.edu wrote: Hi, I am trying to use xyplot to plot the relationship between size and day (y~x) by a food factor that has two levels, low and high. I have 3 reps per factor/day. I want the plots from each food treatment on the same axiss, so I used this code: xyplot(Size ~ Day, groups = Food, data = louis.data.means,col=1, pch=c(1,17), panel=function(x,y,groups,...){ panel.superpose(x,y,groups,...) tmp.lm-lm(y~x) panel.abline(tmp.lm) panel.text(2, 250, label=format(tmp.lm$coefficients[2], digits=4), pos=4) } ) This produces a graph of the two treatments (open circles for the low food vs triangles for the high food) on the same plot, but only one regression line (and slope) which seems to splits the difference between the two factors (treats them as the same data set). I would like to produce a separate regression line for the data from each of the two factors (high food vs low food). Is there a way to subset the lm by the factor food? Louis [[alternative HTML version deleted]] __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]] __ 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] Help with vectorization
Michael originally suggested ?outer. I think that was enough in this case (no need for mv or sapply): wlpk3 - outer(k3,wl,'+') ln.phiDIC - log(k1)+k2/wlpk3 phiDIC- t(exp(ln.phiDIC)) colnames(phiDIC)- stations str(phiDIC) Cheers On Thu, Apr 12, 2012 at 8:58 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Strange, that isn't the error I get: mouter(wl, k1, k2, k3, FUN = function(w, k1, k2, k3) k1 *exp(k2 / (w + k3))) Error in FUN(X, Y, ...) : argument k2 is missing, with no default Still, it's a problem with my mouter() function which was only tested on binary operators (and then only really to teach myself to use Recall()). This should work better: `mouter` - function(..., FUN){ dotArgs -as.list(do.call(expand.grid, list(..., KEEP.OUT.ATTRS= F))) names(dotArgs) - names(formals(FUN)) ans - do.call(FUN, dotArgs) dim(ans) - sapply(list(...), length) ans } This only works when the function can take all the elements at a time though; I'm sure some fooling around could combine them nicely...it seems to test right on your data, but I haven't checked it more generally. Michael On Thu, Apr 12, 2012 at 3:29 PM, Filoche pmassico...@hotmail.com wrote: Hi and thank you for your time. I got this error when trying your function. mouter(wl, k1, k2, k3, FUN = function(w, k1, k2, k3) k1 *exp(k2 / (w + k3))) Error in k3/(w + k3) : 'k3' is missing Regards, Phil -- View this message in context: http://r.789695.n4.nabble.com/Help-with-vectorization-tp4552638p4552833.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-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] Lattice densityplot with semitransparent filled regions
densityplot(~y|B, groups=A, data=dt, plot.points=rug, col=trellis.par.get(superpose.polygon)$col, alpha=.5, panel=panel.superpose, panel.groups=my.panel.densityplot) Worked for me (i.e. semi-transparent superpose.polygon colors). Is that not what you are seeing ? On Wed, Apr 11, 2012 at 12:05 PM, Walmes Zeviani walmeszevi...@gmail.com wrote: Hello, I'm doing some graphics for a paper and a need customize such with filled region above the density curve. My attempts I get something very near what I need, but I don't solve the problem of use semitransparent filled. Below a minimal reproducible code. Someone has any idea? require(lattice) # toy data... dt - expand.grid(A=1:2, B=1:3, y=1:50) dt$y - rnorm(nrow(dt), dt$B, dt$A) # regular plot... densityplot(~y|B, groups=A, data=dt, plot.points=rug) # the actual panel... panel.densityplot # so, I edit this... my.panel.densityplot - function (x, darg = list(n = 30), plot.points = jitter, ref = FALSE, groups = NULL, weights = NULL, jitter.amount = 0.01 * diff(current.panel.limits()$ylim), type = p, ..., identifier = density) { if (ref) { reference.line - trellis.par.get(reference.line) panel.abline(h = 0, col = reference.line$col, lty = reference.line$lty, lwd = reference.line$lwd, identifier = paste(identifier, abline)) } if (!is.null(groups)) { panel.superpose(x, darg = darg, plot.points = plot.points, ref = FALSE, groups = groups, weights = weights, panel.groups = panel.densityplot, jitter.amount = jitter.amount, # alterei para my.panel type = type, ...) } else { switch(as.character(plot.points), `TRUE` = panel.xyplot(x = x, y = rep(0, length(x)), type = type, ..., identifier = identifier), rug = panel.rug(x = x, start = 0, end = 0, x.units = c(npc, native), type = type, ..., identifier = paste(identifier, rug)), jitter = panel.xyplot(x = x, y = jitter(rep(0, length(x)), amount = jitter.amount), type = type, ..., identifier = identifier)) density.fun - function(x, weights, subscripts = TRUE, darg, ...) { do.call(density, c(list(x = x, weights = weights[subscripts]), darg)) } if (sum(!is.na(x)) 1) { h - density.fun(x = x, weights = weights, ..., darg = darg) lim - current.panel.limits()$xlim id - h$x min(lim) h$x max(lim) panel.lines(x = h$x[id], y = h$y[id], ..., identifier = identifier) ## line above was added panel.polygon(x=h$x[id], y = h$y[id], ..., identifier = identifier, alpha=0.2) } } } # my customized plot, I want semitransparent colors # and use the colors of trellis.par.set(superpose.polygon) to fill densityplot(~y|B, groups=A, data=dt, plot.points=rug, col=2:3, panel=panel.superpose, panel.groups=my.panel.densityplot) Thanks! Walmes. == Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: wal...@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 == [[alternative HTML version deleted]] __ 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)
On Wed, Apr 11, 2012 at 7:16 AM, David Winsemius dwinsem...@comcast.net 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='')) ans } ) Cheers scales= list(x=list(relation=sliced, log=10, cex=0.8, tick.number=5),
Re: [R] Gradients in bar charts XXXX
On Mon, Apr 9, 2012 at 12:40 PM, Jason Rodriguez jason.rodrig...@dca.ga.gov wrote: Hello, I have a graphics-related question: I was wondering if anyone knows of a way to create a bar chart that is colored with a three-part gradient that changes at fixed y-values. Each bar needs to fade green-to-yellow at Y=.10 and from yellow-to-red at Y=.20. Is there an option in a package somewhere that offers an easy way to do this? ?rainbow ?hsv In R an easy way is an ill-defined term. In the absence of actual data: bpd - matrix(c(1,seq(0,1,l=64),2,1,seq(0,1,l=64),5,1,seq(0,1,l=64),7),nc=3) mycols - c('green',rainbow(64,start=0,end=.4)[64:1],'red') barplot(bpd,col=mycols,border=NA) Easy enough ? Cheers Attached is a chart I macgyvered together in Excel using a combination of a simple bar chart, fit line, and some drawing tools. I want to avoid doing it this way in the future by finding a way to replicate it in R. Any ideas? Thanks, Jason Michael Rodriguez Data Analyst State Housing Trust Fund for the Homeless Georgia Department of Community Affairs Email: jason.rodrig...@dca.ga.gov __ 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] Drawing a line in xyplot
On Sat, Apr 7, 2012 at 8:29 PM, wcheckle wchec...@jhsph.edu wrote: Thank you David, the bwplot option does what I need: snip However, I am interested in also learning how to do it in xyplot as well. I wasn’t able to follow the last two set of instructions That was me. Sorry for any confusion. wcheckle, these were not instructions but ramblings on an earlier code which used the original data.frame inside the lattice panel function, which in my view is an added complication in the case of only 2-3 conditioning variables. You were not meant to try and follow (the alternative was given in the form of bwplot). Your original post had two plots - in base graphics you had one conditional variable (type) and median lines, and a second was lattice with 2 variables (attend|type) without median lines. You were offered 2 solutions - David's to reproduce the first plot in lattice, and the bwplot to add medians to the second. You could work through the examples in lattice and on-line to find there is a multitude of ways to add features to grid/lattice plots. An example with panel.segments might look (untested) something like: panel=function(x,y,...) { panel.xyplot(x,y,...) yy- tapply(y,x,median) panel.segments(x0, x1, y0= yy , y1= yy , col=red,lwd=4) } Hope that clarifies things, and again sorry everyone for any confusion that may have resulted. Best, Elai __ 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() does not plot legends with relation=free scales
On Sun, Apr 8, 2012 at 3:42 AM, Kaveh Vakili kaveh.vak...@ulb.ac.be wrote: Hi all, I have this problem with lattice that xyplot() won't draw some of my axis labels if the type (i.e. the relation argument) of scales is set as free. For example, in the plot below, I would want it to also show: 1. the labels E1,...E6 below the 10th panel (i.e. 3rd row, 2 col)just as it is now done below the 12th panel You are setting your scales manually, so you need to make sure you don't have typos. Change the line lbl[[9]] - lbl[[12]]-c(E1,E2,E3,E4,E5,E6) to lbl[[10]] - lbl[[12]]-c(E1,E2,E3,E4,E5,E6) 2. as well as the labels (2,4,6,8) on the top of panels 1 and 3 (by on top, i mean above the strips, as xyplot normally does by default but can't seem to be willing to do in the example below). Same thing, I see the y axis labels for 1,3 but nothing for the at or labels for x-axis for [[1,3]]. Note also you need the appropriate tck argument for placing 'top-right' PS: i had originally posted this question on stackoverlow but since i didn't get an answer there i've deleted it there and posting it here. My guess is you didn't get an answer before because this is a reproducible example (thank you) but very involved. In the future try to reduce your code to the minimum which produces the problem behavior, you will often find that in the process of doing so you answer your own question... Hope this helped Elai Happy Easter, B-structure(list(yval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), xval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, ! 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), gval = c(1, 3, 4, 4, 1, 5, 5, 4, 6, 4, 2, 6, 4, 3, 4, 4, 3, 5, 1, 5, 1, 5, 6, 6, 6, 1, 1, 1, 1, 5, 1, 3, 4, 5, 4, 3, 5, 1, 5, 4, 5, 6, 3, 4, 3, 6, 3, 1, 2, 1, 3, 2, 1, 3, 4, 5, 4, 6, 6, 6, 5, 2, 1, 4, 5, 5, 4, 1, 1, 1, 3, 2, 2, 6, 2, 3, 3, 4, 1, 3, 2, 1, 3, 6, 5, 2, 6, 4, 2, 2, 1, 1, 5, 2, 6, 6, 3, 1, 4, 3), type = structure(c(2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 3L, 2L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 2L, 3L, 2L, 3L, 3L, 2L, 1L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 1L, 2L, 3L, 2L, 1L, 1L, 1L, 2L, 3L, 2L, 3L, 3L, 1L, 3L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 2L), .Label = c(0, 1, 5), class = factor), cr = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L! , 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0.2, 0.3, 0.4), class = factor), p = structure(c(1L, 2L, 1L, 1L, 2L, 1L, 4L, 4L, 2L, 4L, 3L, 1L, 2L, 2L, 1L, 4L, 1L, 1L, 3L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 1L, 4L, 1L, 4L, 1L, 4L, 3L, 1L, 1L, 3L, 3L, 4L, 4L, 4L, 4L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 3L, 2L, 3L, 3L, 1L, 2L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 4L, 4L, 3L, 3L, 1L, 4L, 4L, 2L, 3L, 3L, 1L, 2L, 4L, 2L, 3L, 1L, 2L, 4L, 4L, 3L, 3L, 4L, 3L, 2L, 3L, 4L, 4L, 1L, 3L, 2L, 4L), .Label = c(4, 8, 12, 20), class = factor), grp = c(4, 2, 2, 2, 4, 2, 2, 4, 4, 4, 4, 5, 2, 4, 5, 2, 2, 4, 5, 5, 2, 4, 5, 4, 2, 4, 2, 2, 4, 5, 4, 5, 4, 2, 5, 4, 2, 4, 5, 2, 5, 4, 2, 4, 5, 5, 5, 4, 2, 4, 2, 2! , 5, 2, 4, 4, 4, 2, 5, 4, 4, 2, 5, 4, 5, 2, 2, 4, 2, 2, 4, 4, 4, 4, 4, 5, 2, 5, 2, 5, 4, 4, 4, 2, 2, 4, 2, 5, 4, 4, 4, 4, 4, 4, 4, 5, 2, 5, 2, 4)), .Names = c(yval, xval, gval, type, cr, p, grp), row.names = c(NA, -100L), class = data.frame) And the code: library(lattice) library(robustbase) library(latticeExtra) typis - c(A,B,C)
Re: [R] axis labels not showing
On Sun, Apr 8, 2012 at 11:40 AM, Vikram Chhatre crypticline...@gmail.com wrote: Hello - I want to generate stacked plots with par(mfrow)) function. However, my axis labels aren't showing. Your mar (2) are too narrow. You could increase back to the default or use the lines option in mtext to write labels closer to the plot or, well, a host of other things... Hope this helps My script is here: http://pastebin.com/yXXeMQgb The plot is here: http://www.crypticlineage.net/rdisc/strplot.pdf Thank you for your time. Vikram __ 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] filling the matrix row by row in the order from lower to larger elements
On Sun, Apr 8, 2012 at 8:26 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Sorry, I didn't have time to check the speed, indeed. However - isn't apply the same as a loop, just hidden? D. Yes ?apply is a loop but not the same as ?for, see Intro to R. As Bert Gunter pointed out the issue here was not speed but that your problem could have been vectorized to avoid loops all together (which would have the added benefit of speed). This was given to you in my first response which assumed a small number of columns in the matrix, but Rui gave an elegant expansion to use on any ncol(matrix). Using apply was suggested at some point by others, my comment was simply that you failed to meet even that adjustment. Cheers On Fri, Apr 6, 2012 at 6:59 PM, ilai ke...@math.montana.edu wrote: On Fri, Apr 6, 2012 at 4:02 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: This works great: Really ? surprising given it is the EXACT same for-loop as in your original problem with counter i replaced by k and reorder to matrix[!100]- 0 instead of matrix(0)[i]- 100 You didn't even attempt to implement Carl's suggestion to use apply family for looping (which I still think is completely unnecessary). The only logical conclusion is N=nrow(input) was not large enough to pose a problem in the first place. In the future please use some brain power before waisting ours. Cheers input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) result-input N-nrow(input) for (k in 1:N){ foo - which (input == k,arr.ind=T) result[k,foo[2]] -100 } result[result !=100]-0 Dimitri On Fri, Apr 6, 2012 at 5:14 PM, Carl Witthoft c...@witthoft.com wrote: I think the OP wants to fill values in an arbitrarily large matrix. Now, first of all, I'd like to know what his real problem is, since this seems like a very tedious and unproductive matrix to produce. But in the meantime, since he also left out important information, let's assume the input matrix is N rows by M columns, and that he wants therefore to end up with N instances of 100, not counting the original value of 100 that is one of his ranking values (a bad BAD move IMHO). Then either loop or lapply over an equation like (I've expanded things more than necessary for clarity result-inmatrix for (k in 1:N){ foo - which (inmatrix == k,arr.ind=T) result[k,foo[2]] -100 } I maybe missing something but this seems like an indexing problem which doesn't require a loop at all. Something like this maybe? (input-matrix(c(5,1,3,7,2,6,4,8),nc=2)) output - matrix(0,max(input),2) output[input[,1],1] - 100 output[input[,2],2] - 100 output Cheers On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski dimitri.liakhovitski at gmail.com wrote: Hello, everybody! I have a matrix input (see example below) - with all unique entries that are actually unique ranks (i.e., start with 1, no ties). I want to assign a value of 100 to the first row of the column that contains the minimum (i.e., value of 1). Then, I want to assign a value of 100 to the second row of the column that contains the value of 2, etc. The results I am looking for are in desired.results. My code (below) does what I need. But it's using a loop through all the rows of my matrix and searches for a matrix element every time. My actual matrix is very large. Is there a way to do it more efficiently? Thank you very much for the tips! Dimitri input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) (input) desired.result-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100))) (desired.result) result-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0))) for(i in 1:nrow(input)){ # i-1 mymin-i mycoords-which(input==mymin,arr.ind=TRUE) result[i,mycoords[2]]-100 input[mycoords]-max(input) } (result) -- Sent from my Cray XK6 Quidvis recte factum, quamvis humile, praeclarum. __ 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. -- Dimitri Liakhovitski marketfusionanalytics.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. -- Dimitri Liakhovitski marketfusionanalytics.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] Drawing a line in xyplot
On Sat, Apr 7, 2012 at 11:16 AM, David Winsemius dwinsem...@comcast.net wrote: xyplot(mortality ~ type, data=xdat, panel=function(x,y){ panel.xyplot(x,y, jitter.x=TRUE) panel.segments(x0=c(.9, 1.9, 2.9), x1=c(1.1,2.1,3.1), y0=tapply(xdat$mortality, xdat$type, median), y1=tapply(xdat$mortality, xdat$type, median), col=red, lwd=3 ) }) Actually the OP had formula = mortality ~ factor(attend)|type, (two conditioning factors). This approach will work but will require 1) replace type with attend in tapply 2) subset conditional on packet.number 3) loop over the segments for the two sets of x-coords An alternative will be bwplot(mortality ~ factor(attend)|type,data=xdat, pch=95,cex=5,col=2, par.settings=list( box.rectangle = list(col = 'transparent'), box.umbrella = list(col = 'transparent') ), panel=function(x,y,...){ panel.grid(lty=5) panel.bwplot(x,y,...) panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1) } ) Hope this helps thanks -- View this message in context: http://r.789695.n4.nabble.com/Drawing-a-line-in-xyplot-tp4538689p4539596.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. 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. __ 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] Changing grid defaults
You might want to check out package {tikzDevice} and it's documentation. In essence you turn your R plots to tikz-pgf so they can be naturally incorporated into a beamer presentation. Colors, bg, fonts etc. can now be controlled in your main latex doc. I find it much more convenient, and nicer when the plot annotations make use of the same latex font rather than e.g. plotmath. Note, for grid graphics you'll need to use print(yourplot) to the device. Cheers On Fri, Apr 6, 2012 at 8:43 AM, Brett Presnell presn...@stat.ufl.edu wrote: I'm trying to use the vcd package to produce mosaic plots for my class notes, written in Sweave and using the LaTeX's beamer document class. For projecting the notes in class, I use a dark background with light foreground colors. It's easy enough to change the defaults for R's standard graphics to match my color scheme (using the fg, col.axis, col.lab, col.main, and col.sub parameter settings), but I can't figure out how to do this with grid/strucplot/vcd. From my experiments, I think that I might eventually figure out how to change the colors of all the text in the mosaic plots to what I want using arguments like 'gp_args = list(gp_labels = gpar(col = yellow)' and 'gp_varnames = gpar(col = yellow)' (although I still haven't figured out how to changed the color of the text on the legends), but this is obviously not what I need. I have been reading all the documentation I can find, but I still haven't figured this out, so an answer accompanied by a reference to some line or the other in some piece of documentation would be greatly appreciated. __ 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] filling the matrix row by row in the order from lower to larger elements
I maybe missing something but this seems like an indexing problem which doesn't require a loop at all. Something like this maybe? (input-matrix(c(5,1,3,7,2,6,4,8),nc=2)) output - matrix(0,max(input),2) output[input[,1],1] - 100 output[input[,2],2] - 100 output Cheers On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello, everybody! I have a matrix input (see example below) - with all unique entries that are actually unique ranks (i.e., start with 1, no ties). I want to assign a value of 100 to the first row of the column that contains the minimum (i.e., value of 1). Then, I want to assign a value of 100 to the second row of the column that contains the value of 2, etc. The results I am looking for are in desired.results. My code (below) does what I need. But it's using a loop through all the rows of my matrix and searches for a matrix element every time. My actual matrix is very large. Is there a way to do it more efficiently? Thank you very much for the tips! Dimitri input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) (input) desired.result-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100))) (desired.result) result-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0))) for(i in 1:nrow(input)){ # i-1 mymin-i mycoords-which(input==mymin,arr.ind=TRUE) result[i,mycoords[2]]-100 input[mycoords]-max(input) } (result) -- Dimitri Liakhovitski __ 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] filling the matrix row by row in the order from lower to larger elements
On Fri, Apr 6, 2012 at 4:02 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: This works great: Really ? surprising given it is the EXACT same for-loop as in your original problem with counter i replaced by k and reorder to matrix[!100]- 0 instead of matrix(0)[i]- 100 You didn't even attempt to implement Carl's suggestion to use apply family for looping (which I still think is completely unnecessary). The only logical conclusion is N=nrow(input) was not large enough to pose a problem in the first place. In the future please use some brain power before waisting ours. Cheers input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) result-input N-nrow(input) for (k in 1:N){ foo - which (input == k,arr.ind=T) result[k,foo[2]] -100 } result[result !=100]-0 Dimitri On Fri, Apr 6, 2012 at 5:14 PM, Carl Witthoft c...@witthoft.com wrote: I think the OP wants to fill values in an arbitrarily large matrix. Now, first of all, I'd like to know what his real problem is, since this seems like a very tedious and unproductive matrix to produce. But in the meantime, since he also left out important information, let's assume the input matrix is N rows by M columns, and that he wants therefore to end up with N instances of 100, not counting the original value of 100 that is one of his ranking values (a bad BAD move IMHO). Then either loop or lapply over an equation like (I've expanded things more than necessary for clarity result-inmatrix for (k in 1:N){ foo - which (inmatrix == k,arr.ind=T) result[k,foo[2]] -100 } I maybe missing something but this seems like an indexing problem which doesn't require a loop at all. Something like this maybe? (input-matrix(c(5,1,3,7,2,6,4,8),nc=2)) output - matrix(0,max(input),2) output[input[,1],1] - 100 output[input[,2],2] - 100 output Cheers On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski dimitri.liakhovitski at gmail.com wrote: Hello, everybody! I have a matrix input (see example below) - with all unique entries that are actually unique ranks (i.e., start with 1, no ties). I want to assign a value of 100 to the first row of the column that contains the minimum (i.e., value of 1). Then, I want to assign a value of 100 to the second row of the column that contains the value of 2, etc. The results I am looking for are in desired.results. My code (below) does what I need. But it's using a loop through all the rows of my matrix and searches for a matrix element every time. My actual matrix is very large. Is there a way to do it more efficiently? Thank you very much for the tips! Dimitri input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) (input) desired.result-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100))) (desired.result) result-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0))) for(i in 1:nrow(input)){ # i-1 mymin-i mycoords-which(input==mymin,arr.ind=TRUE) result[i,mycoords[2]]-100 input[mycoords]-max(input) } (result) -- Sent from my Cray XK6 Quidvis recte factum, quamvis humile, praeclarum. __ 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. -- Dimitri Liakhovitski marketfusionanalytics.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] indexing data.frame columns
On Thu, Apr 5, 2012 at 1:40 PM, Peter Meilstrup peter.meilst...@gmail.com wrote: Consider the data.frame: df - data.frame(A = c(1,4,2,6,7,3,6), B= c(3,7,2,7,3,5,4), C = c(2,7,5,2,7,4,5), index = c(A,B,A,C,B,B,C)) I want to select the column specified in 'index' for every row of 'df', to get goal - c(1, 7, 2, 2, 3, 5, 5) This sounds a lot like the indexing-by-a-matrix you can do with arrays; df[cbind(1:nrow(df), df$index)] but this returns me values that are all characters where I want numbers. str(df[,-4][cbind(1:nrow(df),df$index)]) num [1:7] 1 7 2 2 3 5 5 (it seems that indexing by an array isn't well supported for data.frames.) No, it's just that the index column in df is a factor so as.matrix(df) return a matrix of characters What is a better way to perform this selection operation? Not that I know of Cheers Peter [[alternative HTML version deleted]] __ 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] A contour plot question - vis.gam () function in mgcv
On Tue, Apr 3, 2012 at 6:22 PM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2012-04-03 15:49, ilai wrote: Try to plot the points first followed by vis.gam(...,type='contour', color='bw', add=T) instead of vis.gam followed by points. HTH Or, if vis.gam gives you default scales that you wish to preserve, then just replot the contours over the points with vis.gam(., add = TRUE) Peter Ehlers I would say no. This works as a quick and dirty but as a general rule, in my view replot should be discouraged because of the reduced print quality of the visible elements from the original. Maybe a minor issue, but annoying to give a presentation and realize labels in the plot are all fuzzy when projected on the big screen (never happened to me of course, I'm talking about a friend...:). To preserve the scales in this case would be better to explicit set limits plot(...,pch=19,xlim,ylim) ; vis.gam(., add = TRUE) rather than vis.gam() points() vis.gam() Cheers On Tue, Apr 3, 2012 at 2:48 PM, Ravi Varadhanrvarad...@jhmi.edu wrote: Hi, Please see the attached contour plot (I am sorry about the big file). This was created using the vis.gam() function in mgcv package. However, my question is somewhat broader. In generating this figure, I first created the contours using vis.gam() and then I plotted the points. These point are plotted on top of the contours so that some of the contour lines are only partially visible. Is there a way to make the contour lines fully visible? I cannot reverse the order and plot the points first and then call vis.gam(). Or, can I? Are there other options? Thanks for any help or hints. Best, Ravi Ravi Varadhan, Ph.D. Assistant Professor The Center on Aging and Health Division of Geriatric Medicine Gerontology Johns Hopkins University rvarad...@jhmi.edumailto:rvarad...@jhmi.edu 410-502-2619 __ 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-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] image.plot adding x-axis labels. Please Help
On Wed, Apr 4, 2012 at 6:05 AM, David Winsemius dwinsem...@comcast.net wrote: On Apr 3, 2012, at 11:16 PM, David Lyon wrote: Sorry that didnt work for me, any ideas? You _could_ indicate which package the image.plot function comes from. You _could_ include dput on a sufficient segment of `data1` to offer a reproducible test case. You _could_ indicate in what fashion the axis() call didn't work. I used to look such matters up, add code and make guesses, but got tired of doing extra work that was really the responsibility of the questioner. -- David Thank you David, you're absolutely right. The critical point here is par settings of fields::image.plot not the axis(1,at=?...) as could be understood from the original partial question. I forgot to cc the list on my private communications with the OP. Future googlers, the same solution can be achieved with A- matrix(1:50,nr=10) par(mar=c(5.1,2.1,4.1,4.1)) image(t(A),axes=F,col='transparent') axis(1,at=seq(0,1,l=ncol(A)),labels=LETTERS[1:ncol(A)]) require(fields) image.plot(t(A),add=T,legend.mar=3.1) Cheers - Original Message - From: ilai ke...@math.montana.edu To: David Lyon david_ly...@yahoo.com Cc: r-help@r-project.org r-help@r-project.org Sent: Tuesday, April 3, 2012 10:43 PM Subject: Re: [R] image.plot adding x-axis labels. Please Help On Tue, Apr 3, 2012 at 7:25 PM, David Lyon david_ly...@yahoo.com wrote: if I had a data file like this: 1.42 1.29 -0.13 1.46 1.34 -0.12 1.45 1.32 -0.13 1.36 1.26 -0.10 1.33 1.29 -0.04 I want to create a image plot like this: data1-read.table(A) image.plot(t(data1), axes=FALSE, xlab=NA, ylab=NA) I cant get the labels for the x axis right can some kind person help me? axis(1,at=seq(0,1,l=ncol(data1)),labels=LETTERS[1:ncol(data1)]) axis(1.???.labels=c(A, B, C)) Many thanks in advance! __ 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. 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] cluster analysis with pairwise data
On Wed, Apr 4, 2012 at 10:12 AM, Petr Savicky savi...@cs.cas.cz wrote: On Wed, Apr 04, 2012 at 01:32:10PM +0200, paladini wrote: Var1 - c((1,2), (7,8), (4,7)) Var2 - c((1,5), (3,88), (12,4)) Var3 - c((4,2), (6,5), (4,4)) DF - data.frame(Var1, Var2, Var3, stringsAsFactors=FALSE) If you want to use a distance between pairs depending on the numbers (and not only equal/different pair), then the data should to be transformed to a numeric format. Or if the pairs have unique meaning ?daisy , also in the cluster package, comes in handy (in this case you'll want to keep Vi as factors in the call to DF). Cheers For example, as follows trans - function(x) { y - strsplit(gsub([()], , x), ,) unname(t(vapply(y, FUN=as.numeric, FUN.VALUE=c(0, 0 } DF - data.frame(Var1=trans(Var1), Var2=trans(Var2), Var2=trans(Var3)) DF Var1.1 Var1.2 Var2.1 Var2.2 Var2.1.1 Var2.2.1 1 1 2 1 5 4 2 2 7 8 3 88 6 5 3 4 7 12 4 4 4 Then, see library(help=cluster). Hope this helps. Petr Savicky. __ 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] A contour plot question - vis.gam () function in mgcv
Try to plot the points first followed by vis.gam(...,type='contour', color='bw', add=T) instead of vis.gam followed by points. HTH On Tue, Apr 3, 2012 at 2:48 PM, Ravi Varadhan rvarad...@jhmi.edu wrote: Hi, Please see the attached contour plot (I am sorry about the big file). This was created using the vis.gam() function in mgcv package. However, my question is somewhat broader. In generating this figure, I first created the contours using vis.gam() and then I plotted the points. These point are plotted on top of the contours so that some of the contour lines are only partially visible. Is there a way to make the contour lines fully visible? I cannot reverse the order and plot the points first and then call vis.gam(). Or, can I? Are there other options? Thanks for any help or hints. Best, Ravi Ravi Varadhan, Ph.D. Assistant Professor The Center on Aging and Health Division of Geriatric Medicine Gerontology Johns Hopkins University rvarad...@jhmi.edumailto:rvarad...@jhmi.edu 410-502-2619 __ 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] image.plot adding x-axis labels. Please Help
On Tue, Apr 3, 2012 at 7:25 PM, David Lyon david_ly...@yahoo.com wrote: if I had a data file like this: 1.42 1.29 -0.13 1.46 1.34 -0.12 1.45 1.32 -0.13 1.36 1.26 -0.10 1.33 1.29 -0.04 I want to create a image plot like this: data1-read.table(A) image.plot(t(data1), axes=FALSE, xlab=NA, ylab=NA) I cant get the labels for the x axis right can some kind person help me? axis(1,at=seq(0,1,l=ncol(data1)),labels=LETTERS[1:ncol(data1)]) axis(1.???.labels=c(A, B, C)) Many thanks in advance! __ 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] Filling empty List in a FOR LOOP
On Sun, Apr 1, 2012 at 9:59 AM, michaelyb cel81009...@gmail.com wrote: Basically I need to read the data from an external source using many R commands. The problem is that sometimes the source is empty, and I get a list with empty values, and I need to substitute them by NA. It is def. not hard, I just don't see how In the prvious post, the first example had values on the source, but the second example didn't And neither was reproducible as is this post. There is more than one way to get an empty list. I find R-list helpers are good but lacking in extrasensory perception skills. Frustrating, but if you insist on not following the posting guide, then you'll just have to figure it out for yourself. lapply(vector('list',2),function(ll) ifelse(is.null(ll),NA,ll)) # works lapply(list(,foo),function(ll) ifelse(is.null(ll),NA,ll)) # fail lapply(list(,foo),function(ll) ifelse(nchar(ll)1,NA,ll)) # works # ... # from your example 1 seems like you're expecting a matrix, so maybe you need nrow(ll) # etc. HTH -- View this message in context: http://r.789695.n4.nabble.com/Filling-empty-List-in-a-FOR-LOOP-tp4522694p4523731.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)
On Thu, Mar 29, 2012 at 3:04 AM, maxbre mbres...@arpa.veneto.it wrote: snip 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] How to create arbitrary number of loops in R
To cbind, you don't need a loop (M - matrix(1:50,nc=10)) c2way - combn(ncol(M),2) MM - M[,c2way] dim(MM) - c(nrow(M),nrow(c2way),ncol(c2way)) MM c3way - combn(ncol(M),3) MMM - M[,c3way] dim(MMM) - c(nrow(M),nrow(c3way),ncol(c3way)) MMM etc. etc. Than you can (untested for icc) loop your function as in apply(MMM,3,somefun) cheers On Thu, Mar 29, 2012 at 7:28 AM, Dai, Hongying, h...@cmh.edu wrote: Dear R users, I'm wondering how I can generate an arbitrary number of loops in R. For instance, I can generate two for loops to get ICC among any two-way combination among 10 variables. Here is the code n-10 for (i in 1:(n-1)) { for (j in (i+1):n) { icc(cbind(DATA[,i],DATA[,j])) } } If I need three-way combination, then a code with three for loops will be: n-10 for (i in 1:(n-2)) { for (j in (i+1):(n-1)) { for (k in (j+1):n) { icc(cbind(DATA[,i],DATA[,j],DATA[,k])) } } } But how can I write a code if I need all m=2, 3, 4,... loops for arbitrary m-way combinations? Thanks! Daisy Electronic mail from Children's Mercy Hospitals and Clinics. This communication is intended only for the use of the addressee. It may contain information that is privileged or confidential under applicable law. If you are not the intended recipient or the agent of the recipient, you are hereby notified that any dissemination, copy or disclosure of this communication is strictly prohibited. If you have received this communication in error, please immediately forward the message to Children's Mercy Hospital's Information Security Officer via return electronic mail at informationsecurityoffi...@cmh.edu and expunge this communication without making any copies. Thank you for your cooperation. [[alternative HTML version deleted]] __ 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] How to create arbitrary number of loops in R
On Thu, Mar 29, 2012 at 9:27 AM, ilai ke...@math.montana.edu wrote: Oops, sent to fast. A (maybe) clearer solution: f - function(x,m){ cmway - combn(ncol(x),m) xx - x[,cmway] dim(xx) - c(nrow(x),nrow(cmway),ncol(cmway)) xx } f(M,3) str(sapply(2:4,f,x=M)) And again lapply / apply , or even return icc(xx) in f Cheers To cbind, you don't need a loop (M - matrix(1:50,nc=10)) c2way - combn(ncol(M),2) MM - M[,c2way] dim(MM) - c(nrow(M),nrow(c2way),ncol(c2way)) MM c3way - combn(ncol(M),3) MMM - M[,c3way] dim(MMM) - c(nrow(M),nrow(c3way),ncol(c3way)) MMM etc. etc. Than you can (untested for icc) loop your function as in apply(MMM,3,somefun) cheers On Thu, Mar 29, 2012 at 7:28 AM, Dai, Hongying, h...@cmh.edu wrote: Dear R users, I'm wondering how I can generate an arbitrary number of loops in R. For instance, I can generate two for loops to get ICC among any two-way combination among 10 variables. Here is the code n-10 for (i in 1:(n-1)) { for (j in (i+1):n) { icc(cbind(DATA[,i],DATA[,j])) } } If I need three-way combination, then a code with three for loops will be: n-10 for (i in 1:(n-2)) { for (j in (i+1):(n-1)) { for (k in (j+1):n) { icc(cbind(DATA[,i],DATA[,j],DATA[,k])) } } } But how can I write a code if I need all m=2, 3, 4,... loops for arbitrary m-way combinations? Thanks! Daisy Electronic mail from Children's Mercy Hospitals and Clinics. This communication is intended only for the use of the addressee. It may contain information that is privileged or confidential under applicable law. If you are not the intended recipient or the agent of the recipient, you are hereby notified that any dissemination, copy or disclosure of this communication is strictly prohibited. If you have received this communication in error, please immediately forward the message to Children's Mercy Hospital's Information Security Officer via return electronic mail at informationsecurityoffi...@cmh.edu and expunge this communication without making any copies. Thank you for your cooperation. [[alternative HTML version deleted]] __ 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)
On Wed, Mar 28, 2012 at 4:21 AM, maxbre mbres...@arpa.veneto.it 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.
Re: [R] matrix(unlist(strsplit())) 'missing value' issue
On Wed, Mar 28, 2012 at 6:49 AM, Petr PIKAL petr.pi...@precheza.cz wrote: What problem? Nabble is not available to all and here is not much to cook from. Indeed. Also the OP actually provided their own solution, just 5 more minutes of googling to find ?sub. bankoffer.3 - factor(c('999','429000:notaccepted','48000:notaccepted')) bankoffer.3 - gsub('99','NA:NA',bankoffer.3) as.data.frame(matrix(unlist(strsplit(as.character(bankoffer.3),:)), ncol = 2, byrow = TRUE)) Cheers Nobody any solution for my problem?? -- View this message in context: http://r.789695.n4.nabble.com/matrix-unlist- strsplit-missing-value-issue-tp4509065p4511668.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-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] resampling for correlation and testing
On Wed, Mar 28, 2012 at 3:53 PM, Benton, Paul hpaul.bento...@imperial.ac.uk wrote: Hello all R-er, I'm trying to run a resampling method on some data. The current method I have takes 2+ days or a lot of memory . I was wondering if anyone has a better suggestion. Currently I take a matrix and get the correlation matrix from it. This will be called rho.A. Each element in this will be tested against the distribution from the resampled correlation B matrix. Some example code: A-matrix(rnorm(100), ncol=10) B-matrix(rnorm(100), ncol=10) rho.A-cor(A) { idx-sample(1:10, 10) idx # [1] 8 4 5 7 1 9 2 10 6 3 rho.B-cor(B[,idx]) } ## repeat this x time (currently 500) ## in essence we then have the following : rho.arrayB-array(runif((10*10)*500), dim=c(10,10,500)) Err... no we don't. sample(10,10) ; sample(10,10) ... only permutes the columns, so the 500 cor(B) have exactly the same values in different off diag positions. Using runif they are unique ## Then test if rho.A[1,1] come from the distribution of rho.B[1,1] pvalueMat[1,1]-wilcox.test(rho.array[1,1,] , rho.A[1,1])$p.value From what I know cor(A)[ i , i ] = cor(B)[ j , j ] = 1 for any choice of A,B,i and j I don't think Wilcox intended his test to be used in this way I would start with fixing these issues first so you don't wait 2 days for a vector of NaN's Cheers However, my array size would be 2300 x 2300 x 500 which R won't let me even make as an empty structure. Any suggestion are more than welcomed !! Cheers, Paul __ 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] resampling for correlation and testing
On Wed, Mar 28, 2012 at 8:03 PM, Benton, Paul hpaul.bento...@imperial.ac.uk wrote: On Mar 29, 2012, at 1:41 AM, ilai wrote: On Wed, Mar 28, 2012 at 3:53 PM, Benton, Paul hpaul.bento...@imperial.ac.uk wrote: Hello all R-er, snip ## Then test if rho.A[1,1] come from the distribution of rho.B[1,1] pvalueMat[1,1]-wilcox.test(rho.array[1,1,] , rho.A[1,1])$p.value From what I know cor(A)[ i , i ] = cor(B)[ j , j ] = 1 for any choice of A,B,i and j No, cor(a)[i, j] != cor(b)[i , j] Clearly. I was talking about the diagonal elements (which in a correlation matrix are 1's for all). I didn't look at your function yet (I'll try to find the time soon) so this may be a mute point, but I think here maybe the answer to your question. Correct me if I'm wrong (it's been known to happen from time to time :) but here is how I see it: For corr matrices A (n x n) and B (p x p) you only need to test each of lower.tri.A[i,j] where i != j vs. some populations of rho's which are resamples from the vector of p(p-1) lower.tri.B = you will be performing n(n-1)500 tests. Still maybe a daunting task for large n, but much more manageable than creating the full dim array of matrices, where the diagonal is meaningless and the other half is just a repeat. I know - you actually want 1000 resamples, not 500, and in your original you remove the diagonal, etc. etc. but as you yourself noted creating even an empty array of these dimensions was not feasible. Hope I'm not way off and this helps somewhat Elai If your concern is because they are coming from the same distribution then again this is example data. Even then I would imagine that the correlation would be different for small n. Either way resampling the columns will give different correlation values. Please try the code yourself. I don't think Wilcox intended his test to be used in this way…. Probably true …. care to suggest a different statistical test ? I would start with fixing these issues first so you don't wait 2 days for a vector of NaN's Actually I didn't get a vector or NaN's I got a matrix of pvalues. Which has proved useful. Now I want to make the function faster and was looking for a bit of help. Cheers However, my array size would be 2300 x 2300 x 500 which R won't let me even make as an empty structure. Any suggestion are more than welcomed !! Cheers, Paul __ 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] assigning vector or matrix sparsely (for use with mclapply)
It is (at least for me) really unclear what the problem is, or how it's related to mclapply. You say this works fine, except that what I want to get NA's in the return positions that were not recalculated. then, I can write newdata$y - ifelse ( is.na(olddata$y), mc.byselectrows( olddata, is.na(olddata$y), fun.calc.y ), olddata$y ) Why ??? Are you applying the function twice ? than why not simply v1.1 - mc.byselectrows( d, loc1, function(x) x[,2]^2 ) the second time ? If the problem is in keeping track of which rows got calculated, why not rename with the row.names omitted after mclapply (probably a good idea anyway): FUN.ON.ROWS - function(.index, ...) as.matrix(FUN(data.notdone[.index,], ...)) soln - mclapply( as.list(1:nrow(data.notdone)) , FUN.ON.ROWS, ... ) rv - do.call(rbind, soln) ## omits naming. if (ncol(rv)==1){ rv - as.vector(rv) ; names(rv) - row.names(data.notdone) } else rownames(rv) - row.names(data.notdone) rv } And finally, you don't even need row.names for c(v1,d[loc1,2]) Or am I missing something here ? BTW your code uses cat.stderr (which is local ? ) instead of cat, and has no call to multicore. Cheers On Mon, Mar 26, 2012 at 4:28 PM, ivo welch ivo.we...@gmail.com wrote: Dear R wizards--- I have a wrapper on mclapply() that makes it a little easier for me to do multiprocessing. (Posting this may make life easier for other googlers.) I pass a data frame, a vector that tells me what rows should be recomputed, and the function; and I get back a vector or matrix of answers. d - data.frame( id=1:6, val=11:16 ) loc - c(TRUE,TRUE,FALSE,TRUE,FALSE,TRUE) v1 - mc.byselectrows( d, loc, function(x) x[,2]^2 ) v2 - mc.byselectrows(d, loc, function(x) cbind(x[,2]^2,x[,2]^3)) mc.byselectrows - function(data.in, recalclist, FUN, ...) { data.notdone - data.in[recalclist,] cat.stderr([mc.byselectrows: , nrow(data.notdone), rows to be recomputed out of, nrow(data.in), ]\n) FUN.ON.ROWS - function(.index, ...) as.matrix(FUN(data.notdone[.index,], ...)) soln - mclapply( as.list(1:nrow(data.notdone)) , FUN.ON.ROWS, ... ) rv - do.call(rbind, soln) ## omits naming. if (ncol(rv)==1) rv - as.vector(rv) rv } this works fine, except that what I want to get NA's in the return positions that were not recalculated. then, I can write newdata$y - ifelse ( is.na(olddata$y), mc.byselectrows( olddata, is.na(olddata$y), fun.calc.y ), olddata$y ) I can do this very inelegantly, of course. I can merge recalclist into data.in and then write a loop that substitutes for the do.call to rbind. yikes. or I could do the recalclist contingency inside the FUN.ON.ROWS, but this is costly in terms of execution time. are there obvious solutions? advice appreciated. regards, /iaw Ivo Welch (ivo.we...@gmail.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] Updating a Markov Chain
On Sun, Mar 25, 2012 at 3:50 PM, stivi muhame...@wp.pl wrote: Hello, my question is if anyone has any good ideas how to create a Markov Chain from ordered data. So, I have some sort of time series, and if value1 happens as time1 and value2 happens at time2 I record this as an update to the probability transition matrix. The problem is that I cannot predefine the size of the matrix (as I don't know how many states(values) I will have in the end) You could create a iter x n matrix of NA's and fill it up with a loop. Or an empty list ll - list() for(i in 1:3) ll[[i]] - sample(10,i) ll Or, not very efficient, but you can also avoid predefining with something like trans.prob - .5 set.seed(1) for(i in 2:12){ # if(some conditions) or calcs trans.prob - c( trans.prob , rbeta(1,12,1,trans.prob[i-1]) ) } plot(trans.prob,type='l') and don't really know how to update the prob distribution in the rows. in a loop: trans.prob.matrix[i, ] - some.update.fun If anyone has any thoughts, i would be grateful for sharing. If you'd read the posting guide and contemplated some existential questions like is it OK if the question (even if it's not) sounds like homework ? and what's this obsession with providing minimal, reproducible code ? than maybe the smaRter than me on this list will be more inclined to share their thoughts ... Cheers Elai Stivi -- View this message in context: http://r.789695.n4.nabble.com/Updating-a-Markov-Chain-tp4504156p4504156.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] Remove wireframe outer box but keep ticks
See 'box.3d' in trellis.par.get() : wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=NA))) Note you can have some finer control: wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=c(1,2,NA,NA,3,NA,4,5,6))) ) Hope this helps On Fri, Mar 23, 2012 at 3:59 AM, Bigelow, Seth W -FS sbige...@fs.fed.us wrote: I would like to eliminate the outer box around a lattice wireframe graph, but the usual recommended solution, which is to assign a color of 'transparent' to the axis.line parameter, eliminates ticks if the 'arrows=F' command is used, as shown in the following example: test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + test[,2] test = cbind(test, z) names(test) = c(x, y, z) require(lattice) wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(axis.line = list(col = transparent)), ) Is there a way to eliminate the box but keep the ticks? Seth W. Bigelow, Ph.D. Research Ecologist USDA-FS Pacific Southwest Research Station Ph: (802)-379-3444 This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[alternative HTML version deleted]] __ 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] Remove wireframe outer box but keep ticks
On Fri, Mar 23, 2012 at 2:07 PM, Bigelow, Seth W -FS sbige...@fs.fed.us wrote: ilai/keren: Thanks for your response. It's not the 3d bounding box that I wish to eliminate, but the box that surrounds the whole figure and is drawn automatically (I call this the outer box, in contrast to the inner, 3d bounding box). Hmm... But than what you called 'the usual way' should work. Maybe you just overlooked resetting the scales list? Is this what you want? wireframe(z ~ x*y, data = test, scales=list(arrows=F,col=1), par.settings = list(axis.line = list(col = transparent))) The ticks attached to the bounding box are connected, in the software, to the outer box. I'm assembling a number of these graphs on one page, and the outer box makes the whole figure look clunky. Lattice is an incredible piece of software! but these small details can be difficult to nail down. --Seth -Original Message- From: ila...@gmail.com [mailto:ila...@gmail.com] On Behalf Of ilai Sent: Friday, March 23, 2012 11:10 AM To: Bigelow, Seth W -FS Cc: r-help@r-project.org Subject: Re: [R] Remove wireframe outer box but keep ticks See 'box.3d' in trellis.par.get() : wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=NA))) Note you can have some finer control: wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=c(1,2,NA,NA,3,NA,4,5,6))) ) Hope this helps On Fri, Mar 23, 2012 at 3:59 AM, Bigelow, Seth W -FS sbige...@fs.fed.us wrote: I would like to eliminate the outer box around a lattice wireframe graph, but the usual recommended solution, which is to assign a color of 'transparent' to the axis.line parameter, eliminates ticks if the 'arrows=F' command is used, as shown in the following example: test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + test[,2] test = cbind(test, z) names(test) = c(x, y, z) require(lattice) wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(axis.line = list(col = transparent)), ) Is there a way to eliminate the box but keep the ticks? Seth W. Bigelow, Ph.D. Research Ecologist USDA-FS Pacific Southwest Research Station Ph: (802)-379-3444 This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[alternative HTML version deleted]] __ 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] Dotplot: how to change size in the y lab ?
On Mon, Mar 19, 2012 at 7:56 AM, Jose Bustos Melo jbustosm...@yahoo.es wrote: Hi everyone, I'm trying to reduce the font size in the Y exe in this plot: dotplot( bank ~ MV2007 + MV2009 , data = d, horiz = T, par.settings = list( superpose.symbol = list( pch = 21, fill = c( lightblue, lightgreen), cex = 4, col = black ) ) , xlab = Market value ($Bn), key = k, panel = function(x, y, ...){ panel.dotplot( x, y, ... ) grid.text( unit( x, native) , unit( y, native) , label = x, gp = gpar( cex = .7 ) ) } ### add this , scales=list(y=list(cex=.5)) ) Cheers Thank you in advance! José [[alternative HTML version deleted]] __ 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] Adding mean values to boxplots
You want to assign your call to boxplot as an object that contains the plot information set.seed(1) b - matrix(rgamma(100,(1:4)/2,.5),nc=4) (bxp - boxplot(b)) Now you can use the info in bxp for placement, e.g.: text(1:length(bxp$names),bxp$stats[3,],round(bxp$stats[3,],2),pos=3) By the way, the line in the middle is the median, not the mean. points(apply(b,2,median),col=2,pch='x') points(colMeans(b),col=2) HTH On Thu, Mar 15, 2012 at 6:04 AM, Cleland tom.alb...@tribalgroup.com wrote: Hello there, I was wondering if anyone might be able to help me as I'm pretty new to R. I'm trying to create a boxplot from a data table returned from an sproc. I have the following code, which generates the plot as I'd like it: library(RODBC); conn - odbcConnect(datawarehouse); # connect to datawarehouse results - sqlQuery(conn, call sproc)); ylab - 'Percentage (%)' main = 'Productivity Overview - 6 mnths'; par(mai=c(1.5,1,1,0.2), las = 2, xpd=TRUE, cex.axis=0.8, cex.lab=0.8); col = c('forestgreen', 'forestgreen', 'forestgreen', 'chocolate', 'chocolate', 'chocolate', 'goldenrod', 'goldenrod', 'goldenrod'); b - results[,4:12] boxplot(b, col=col, ylab=ylab, main=main, boxwex=0.4); What i'd like to do is add the mean value, demarcated by the black line in the middle of each box, to the plot. The only way I've managed to add values previously is by specifying their exact value and location on the plot e.g. text(1.4,2.139,format(Mean (2.14),digits=2), cex=1); I need these values to be dynamic in the sense that they will be different each time the graph is generated (based on the parameters passed through the sproc) and will need to be in a different position each time (i.e. in-line with the mean for each box). I'm uncertain about a. whether this is possible in R and b. if it is possible, how best I could achieve it. If anyone has any advice it would be gratefully received. Thanks in advance. Tom -- View this message in context: http://r.789695.n4.nabble.com/Adding-mean-values-to-boxplots-tp4474700p4474700.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] coloring wireframe plot with independent/separate matrix of color values.
On Wed, Mar 14, 2012 at 9:47 PM, Alex Miller alexjcmil...@gmail.com wrote: Dear R Users, I am trying to plot a matrix (a Digital Elevation Model) using wireframe [lattice] and color that matrix based on a separate/independent matrix of the same resolution This makes no sense. the values in DEM are the z-coords of corners, not centroids of the facet. A matrix of colors of the same dimensions is not going to work as col.regions cloud(outer(1:3,1:3),par.box=list(col=NA),type='p',col=1:9) wireframe(outer(1:3,1:3)) # 1:9 makes no sense. I don't know of an easy way to drape color by something other than the default height. You could maybe modify the shade.colors.palette function so it returns the colors in your temp matrix. More details in ?panel.3dwire Best, (both have the same number of rows and columns) as the DEM. More specifically I would like to plot a DEM using wireframe and color each cell/tile based on interpolated surface temperature measurements. Within the wireframe function, the arguments color.regions, drape and at seemed most important to accomplish this. However, I have not been successful. Below is another explanation with some example data. ### #say we have a matrix DEM=matrix(1:100, ncol=10) #we also have a matrix of interpolated temperatures measurements (or any other kind of data with the same resolution as the DEM) interpTEMP = matrix(floor(runif(100, 1,10)),ncol=10) #I would normally go through and apply a function to use html color codes to coincide with interpTEMP but these values will prove my dilemma. #now I would like to plot my DEM and color each cell based on the matching cell of interpTEMP #N.B. that this obviously isn't the correct way of doing things as it doesn't work! wireframe(x=DEM, drape=TRUE, col.regions=as.vector(interpTEMP)) ### any ideas on how to combat this problem? Please let me know if I need to be more clear or provide additional information. Many blessings for your help! .alex [[alternative HTML version deleted]] __ 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] help with expression
On Wed, Mar 14, 2012 at 8:56 AM, Thomas Hoffmann hoffm...@giub.uni-bonn.de wrote: Hi all, I still fail to plot an axis title with the following expression: plot(0,xlab=expression('(SOC [' * kgm^{-2} * '])' * ^{-2})) the xlab should look like: (SOC [kgm^2])^0.25 with an out bracket and a superscript. Like this ? plot(0,xlab=expression(paste('(SOC[',kgm^-2,'])'^0.25,sep=''))) Thanks for your advice. Thomas [[alternative HTML version deleted]] __ 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] Needing a better solution to a lookup problem.
You could try doing it without a loop (.C or other): (rgnsnp - merge(region,snps)) (rgnsnp[with(rgnsnp,STOP=POS POS = START),]) Here is my test for merge+search on 100k/200k: fdf1 - data.frame(chr=1:10,p=runif(10),d=sample(10)) fdf2 - data.frame(chr=rep(1:10,2),s=runif(20),t=runif(20)) system.time(with(FDF - merge(fdf2,fdf1),FDF[s=p p = t,])) user system elapsed 2.560 0.152 2.905 Hope this helps Elai On Wed, Mar 14, 2012 at 1:27 PM, Davis, Brian brian.da...@uth.tmc.edu wrote: I have a solution (actually a few) to this problem, but none are computationally efficient enough to be useful. I'm hoping someone can enlighten me to a better solution. I have data frame of chromosome/position pairs (along with other data for the location). For each pair I need to determine if it is with in a given data frame of ranges. I need to keep only the pairs that are within any of the ranges for further processing. Example: snps-NULL snps$CHR-c(1,2,2,3,X) snps$POS-as.integer(c(295,640,670,100,1100)) snps$DAT-seq(1:length(snps$CHR)) snps-as.data.frame(snps, stringsAsFactors=FALSE) snps CHR POS DAT 1 1 295 1 2 2 640 2 3 2 670 3 4 3 100 4 5 X 1100 5 region-NULL region$CHR-c(1,1,2,2,2,X) region$START-as.integer(c(10,210,430,650,810,1090)) region$STOP-as.integer(c(100,350,630,675,850,)) region-as.data.frame(region, stringsAsFactors=FALSE) region CHR START STOP 1 1 10 100 2 1 210 350 3 2 430 630 4 2 650 675 5 2 810 850 6 X 1090 The result I need would look like Res CHR POS DAT 1 295 1 2 670 3 X 1100 5 I have a solution that works reasonably well on small sets, but my current data set is ~100K snp entries, and my regions table has ~200K entries. I have ~1500 files to go through I haven't found a good way to efficiently solve this problem. I've tried various versions of mapply/lapply, for loops, etc which get the answer for small sets but takes hours (per file) on my real data. Bioconductor seemed like the obvious place to look, but my GoogleFu must not be that great. I never found anything relevant. Any ideas or points to the right direction would be greatly appreciated. Brian Davis __ 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.