Re: [R] simple generation of artificial data with defined features
Hi, to add voter.id and election.year to your data frame you could try: el.dt.exp$voter.id=seq(1:nrow(el.dt.exp)) el.dt.exp$election.year=2005 Cheers, Christoph Meyer *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/index.php?id=7885 *** Saturday, August 23, 2008, 1:25:05 PM, you wrote: Dear Mr. Christos Hatzis, thank you so much for your answer which is in my eyes just brilliant! I followed it step by step (great and detailed explanation) and nearly everything is fine. - Except a problem in the very end, I haven't found a solution for until now. (Despite playing arround quite a lot...) Please let me explain: election.2005 - c(16194,13136,3494,3838,4648,4118) #cut of last 3 digits, cause my laptop can't handle millions of rows... attr(election.2005, class) - table attr(election.2005, dim) - c(1,6) attr(election.2005, dimnames) - list(c(votes), c(spd, cdu, csu, gruene, fdp, pds)) head(election.2005) spd cdu csu gruene fdp pds votes 16194 13136 3494 3838 4648 4118 el.dt - as.data.frame(election.2005) el.dt.exp - el.dt[rep(1:nrow(el.dt), el.dt$Freq), -ncol(el.dt)] dim(el.dt.exp) [1] 45428 2 head(el.dt.exp) Var1 Var2 1 votes spd 1.1 votes spd 1.2 votes spd 1.3 votes spd 1.4 votes spd 1.5 votes spd My problem now is, that I would need either an autoincrementing identifier instead of votes in Var1 or the possibility to access the numbering by a column name (i.e. Var0). In addition I need a 3rd Variable for the year oft the election (2005, which is the same for all, but needed later on). So this is what it should look like: voter.id party election.year 1 1spd2005 1.1 2 spd 2005 1.2 3spd 2005 1.3 4spd2005 1.4 5spd2005 1.5 6spd2005 ... __ 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 customizing y-axis scaling
Hi Henning, have a look at the scales argument in the xyplot documentation. You could try adding the following to your code: scales=list(y=list(relation=free)) Cheers, Christoph Thursday, July 10, 2008, 4:35:28 PM, you wrote: Dear list, using the packages Hmisc and lattice i produced some nice xYplots. However, since the data range of the conditioning variable is very big, i need to define more than one y-scale for the plot (in some panels you just see a flat line of data points very close to the x-axis), e.g. different y-axis scales for the different rows of the plot. Is there a way to do so? Thanks, Henning *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/index.php?id=7885 __ 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] Superscript/Subscript in main title
Hi Tariq, try: plot(x,y,main=expression(Emission of CO[2]* with time)) Cheers, Christoph Wednesday, June 4, 2008, 10:31:08 PM, you wrote: I have been trying to figure out how to get superscript/subscript in the main title for a plot. I have tried various approaches and suggestions but none of them work. I am trying to get the following as the main title of my plot: Emission of CO2 with time (but note that 2 is subscript.) I have tried plot(main=Emission of Cexpression(O[2]) with time) and I get error message. I have also tried plot(main=Emission of Cquote(O[2]) with time) I have also tried plot(main) mtext(Emission of Cexpression(O[2]) with time) I keep getting errors. I have searched the archives but none of the threads seem to touch upon this. I would appreciate any suggestion. Regards, Tariq [[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. *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/nawi/nawi-bio3.html __ 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 text to strip in xYplot
Hi John, a solution to your problem would be using strip.custom like this: ... with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), data=dat,type=l, method=bands, scales=list(y=list(relation=free),x=list(alternating=c(1,1,1))), ylim=list(c(0,1200),c(0,1)), strip=strip.custom(factor.levels=c(expression(Anls km^2),expression(Plants km^2) Best wishes, Christoph Wednesday, April 9, 2008, 2:39:09 PM, you wrote: Hello again, I have been trying to add an expression to the strips in xYplot to no avail. For example, in the code below, the text in the strips for each panel is Anls and Plts. However, I would like it to add Anls km^2 and Plants km^2 with the exponents raised. I tried resetting the name of my groups in the dataframe before plotting, but the dataframe only recognized the entire expression (e.g. expression(paste(Anls, km^2,sep= )) and not Anls km2 - which should not have surprised me. Any ideas? Thanks for any help you can provide. John x1=rseq(1,30,0.5) y1=x1^2 y2=10*(x1^2) ycomb=c(y1,y2) y.up=ycomb+0.1*ycomb y.low=ycomb-0.1*ycomb grp=rep(c(Anls,Plts),each=length(x1))) dat=as.data.frame(cbind(ycomb, y.up, y.low, rep(x1,2)),stringsAsFactors=F) colnames(dat)=c(ycomb,y.up,y.low,x1) with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), data=dat,type=l, method=bands, scales=list(y=list(relation=free), x=list(alternating=c(1,1,1))),ylim=list(c(0,1200),c(0,1 __ 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. *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/nawi/nawi-bio3.html __ 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] Separate y-limits in xYplot panels II
Hi John, I think even with scales=list(y=list(relation=free) you have to specify the y-limits for each panel, i.e. add something like ylim=list(c(0,1200),c(0,1)) to your code. Best regards, Christoph Wednesday, April 9, 2008, 12:37:43 AM, you wrote: Hello, I have been trying to use xYplot in Hmisc to graph plots, allowing each panel to have a y-axis dependent on the data in the panel. Following the advice from the R-Help list, message: [R] separate y-limits in xYplot panels on Wed, 30 May 2007 08:12:06 -0700 (PDT), I used scales=list(y=list(relation=free). However, it does not seem to work. Please see below code, where the scale of the y-axis of the 2 panels stays the same despite the scales function. Does anyone know how to get around this? Thanks, John x1=seq(1,30,0.5) y1=x1^2 y2=10*(x1^2) ycomb=c(y1,y2) y.up=ycomb+0.1*ycomb y.low=ycomb-0.1*ycomb grp=rep(c(1,2),each=length(x1)) dat=as.data.frame(cbind(ycomb, y.up, y.low, grp, rep(x1,2))) colnames(dat)=c(ycomb,y.up,y.low,grp,x1) with(dat, xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), data=dat,type=l, method=bands, scales=list(y=list(relation=free), x=list(alternating=c(1,1,1) __ 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. *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/nawi/nawi-bio3.html *** ==End of original message text=== *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/nawi/nawi-bio3.html __ 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] Overlay plots from different data sets using the Lattice package
Hi all, I'm a newbie to lattice graphics. I think I have a very similar problem trying to overlay plots from different data sets. I tried a number of different things but don't seem to get it to work. I am using xYplot from library Hmisc to produce a lattice plot with Median plus error bands plotted as lines for each panel. This works fine. Now I want to add specific points to each panel, however, the data for those points are in a different data frame. I tried something along the lines of Deepayan's example, combining the two data sets using make.groups, but that doesn't seem to work. My code: data=read.table(all species.txt,header=T) data.nonrandom=read.table(all species_non-random.txt,header=T) combined=make.groups(data,data.nonrandom) xYplot(Cbind(Median,Lower,Upper)~species.pool|data.set.location, data=combined,subset=response.variable==sr,groups=which,method=bands,col=black,type=l, panel.groups=function(x,y,group.number,...) { if(group.number==1) panel.lines(x,y,...) else panel.points(x,y,...) }) This gives me the 3 lines per panel that I want (Median plus error bands) but what I want to add as points is instead also shown as a line with the group labels (data and data.nonrandom) next to it. Any ideas what I am doing wrong? Any help and suggestions would be much appreciated! Many thanks in advance. Best regards, Christoph Deepayan Sarkar wrote: On 1/14/08, Erin Steiner [EMAIL PROTECTED] wrote: #After spending the entire day working on this question, I have decided to reach out for support: #I am trying to overlay a densityplot from one data set over a histogram of another, if I were to plot the two individually, they would look like: # data frame construction data.frame.A - data.frame(rnorm(12*8), c(rep(one, 4), rep(two, 4), rep(three, 4)), c(red, orange, yellow, green)) names(data.frame.A) - c(vals, factor.1, factor.2) data.frame.B - data.frame(rnorm(12*15), c(rep(one, 4), rep(two, 4), rep(three, 4)), c(red, orange, yellow, green)) names(data.frame.B) - names(data.frame.A) The first step would be to combine the two data sources: df.comb - make.groups(data.frame.A, data.frame.B) I would then just overlay two density plots: densityplot(~vals | factor.1 * factor.2, df.comb, groups = which, plot.points=FALSE, auto.key = TRUE) but you could do a histogram and a densityplot too: histogram(~vals | factor.1 * factor.2, df.comb, type = density, groups = which, panel = panel.superpose, panel.groups = function(x, group.number, col, ...) { if (group.number == 1) panel.histogram(x, ...) else panel.densityplot(x, ..., plot.points = FALSE) }) -Deepayan __ 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. -- View this message in context: http://www.nabble.com/Overlay-plots-from-different-data-sets-using-the-Lattice-package-tp14824421p16418703.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.