Re: [R] Subsetting across a frame for plotting
Fra: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] På vegne av Liaw, Andy >You might save yourself some headaches by turning it into a matrix instead, >since all the columns are either integer or numeric: >tonedata <- data.matrix(tonedata) >Data frames are really lists, so even when you get a one-row subset, it's >still a one-row data frame. You can use unlist() to turn >that into a vector. >Andy Great, Andy, thanks! unlist was what I was looking for. Morten __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Subsetting across a frame for plotting
I have a huge frame holding holding model results for a number of locations and time series: > str(tonedata) `data.frame': 434 obs. of 339 variables: $ VALUE : int 101 104 105 106 111 118 119 121 122 123 ... $ COUNT : int 2443 184 1539 1016 132 1208 1580 654 864 560 ... $ AREA: num 6.11e+08 4.60e+07 3.85e+08 2.54e+08 3.30e+07 ... $ D1_1958 : num 470 446 452 457 407 ... $ D2_1958 : num 480 455 461 467 416 ... $ D3_1958 : num 493 469 475 480 429 ... $ D4_1958 : num 542 517 522 526 475 ... $ D5_1958 : num 585 560 565 568 517 ... I would like to be able to take all values, except the three first (value, count, area) and be able to plot them. I have managed to make a subset that looks like what I want, by doing tonedata[11,4:339], but that data set is not a vector that can be plottet, it is treated like a set of single values. I tried to use as.vector on the set, bot to no help. I am probably overlooking somehing quite simple, (not to mention not really understanding R's data model..) so help would be appreciated. -- Morten Sickel Norwegian Radiation Protection Authority __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] plot
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] wrote: >Can anyone tell me how to plot on the same graph two different functions >(of x) using two differnt y scales (axes 2 and 4)? The only way I've found is to use the grid library and push.viewport(). ((...) means substitute with whatever appropriate, use help()) library(grid) grid.newpage() push.viewport(viewport(yscale=c(0,500),w=.75,h=.75,xscale=c(0:100))) grid.poins(...) # Plots data point with an y-scale of 0-500 grid.xaxis(...) grid.yaxis(...) # Draws the left y-axis push.viewport(viewport(yscale=c(0,10),xscale=c(0:100))) grid.poins(...) # Plots data point with an y-scale of 0-10 grid,yaxis(main=FALSE,...) # Draws the right y-axis Morten -- Morten Sickel Norwegian Radiation Protection Authority http://www.nrpa.no __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Moving average
Sorry, a neccesary addition: filter in library ts. Morten __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Moving average
Wayne Jones wrote: >Does anyone know if R has the functionality to calculate a simple moving >average. I cant seem to find it in the help menu. does filter() do what you need? Morten __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] log axis assignment
From: Jeremy Z Butler [mailto:[EMAIL PROTECTED] > Surely I should be able to set the > ylog option to T using another object (logaxis). > >for (n in colnames(raw)) >{ >if(n=="pH"){logaxis<-"T"} else {logaxis<-"F"} >plot(full.age,raw[,n],type="n",ylog=logaxis) >... >} What (probably) will work is: if(n=="pH"){logaxis<-"Y"} else {logaxis<-""} plot(full.age,raw[,n],type="n",log=logaxis) The plot-argument log takes which axis that shuld be logaritmic. Morten __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Why does 'exists' need a quoted argument?
Kevin Wright wrote: /snip/ >Can someone explain why 'get' and 'exists' require quoted object names? >Would it make sense (more consistency) to have these functions check to see if the >first argument is a string, and if not, then 'substitute' it? Intuitively, >'exists' is checking to see if an object exists, not to see if a character string >exists. Evidently my intuition is wrong. Well, if you read the ?exists you'll see that it "Search for an R object of the given name on the search path". Even though I am absolutely no R developer, I would guess that it would be not impossible to write a function that does as you thinks, but, its functionality would be worse than for the current exists, consider for example: sql<-Big_ugly_slow_query sql2<-some_more_parameters for (i in c("Foo","Bar","Baz")) if (!exists(i)){ assign(i,sqlquery(handle,paste(sql1,i,sql2) } } i.e. if the object doesn't exist, I have to initialize it, if it does exist, I just keep on using it, I know that the object i exists, so I don't care about that. On the other hand, if it was automatically substituting what was found to be a string, it would not be possible to if (!exists("String")){String<-"Default value"} So, no, I think some useful functionality would be thrown out if exist did not require a string. Morten Sickel __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Bug in recording (Windows graphical device)
I was making a lot of similiar plots, so I made a script for making each of them and a driver program that repeatly called the script with the right parameters. The plot is made by: barplot(Releases[[i]],col='gray',names.arg=as.character(Releases$Year), ylim=c(0,max),ylab=unit) box() grid(col='black',nx=NA,ny=NULL) rect(-0.5,max*0.98,-0.2+strwidth(Nuc)*1.2,max*0.92,col='white',border='white ') text(strwidth(Nuc)/2-0.2,max*0.95,Nuc,cex=1.2) My first attempt was to use the recording function in the device and just call it using for (i in c(1,2,5,7,8,9,10,12,14,15,16,18,19,20,23,24,25)){ source('Barplot-prog.R')} } Which messed up the grid drawed on the plot, the lines were extended all the way through the margins. Saving each plot to a file, otoh, works, it also makes the recorded plots correct. After this has occured the first time, I have to close and reopen the graphics device to make it work correctly again. I can send data and complete scripts if someone needs them to investigate the problem. Morten __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Overlaying a moving average curve on top of a barplot
Jose Santos Alegria wrote: >I'm using standard barplot (Windows version 1.6.2 of R) to represent a certain weekly >metric "v" and I would like to properly overlay on top of it its moving average "mean.8" >(window of 8 weeks). I must be doing something wrong since the moving average (using >"lines") doesn't overlay properly, i.e., both x-scales do not match! Have you considered using "filter"? I made a somehov similiar plot this way: (prec being a data frame with 'columns' date with dates of measurements and prec, precipitation at the actual date) plot(prec) lines(prec$date,filter(prec$value,c(0.25,0.25,0.25,0.25))) Points showing actual measurements and a four periods moving average as a line. Hope this helps. Morten -- Morten Sickel Norwegian Radiation Protection Authority http://www.nrpa.no __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Varying texts in expression(paste())
Gunter Bart wrote: > You need substitute(). Look at the examples in plotmath(). > x<-3;y<-'foo' > plot(c(0,1),c(0,1),type='n') > text(.5,.5,substitute(paste('Releases of ',x^99,' ',y,' > TBq/year'),list(x=x,y=y))) > Hope this helps ... Thanks a lot, it helped indeed! Morten __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Varying texts in expression(paste())
Hi, I am using R a lot to make plots relating to radioactivity, I am often using expression() to label the plots with nuclide names written with superscripts, e.g. expression(paste("Releases of ", { }^{99},Tc," (TBq/year)"))->ywtext But, is there any simple way to change the number and name of the nuclide through a variable? I tried nuccode=expression({ }^{99},Tc) expression(paste("Releases of ", as.expression(nuccode) ," (TBq/year)"))->ywtext But, obiously, since as.expression does not return a chr, it was used literally in the text on the figure, i.e. "Releases of as.expression(nuccode) (TBq/year)" which definiately was not what I wanted... should I use some other wrapper function on the expression, or are there some other ways of making superscripts in figure texts? regards Morten -- Morten Sickel Norwegian Radiation Protection Authority http://www.nrpa.no __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Plot using different symbols depending on value.
I am making a plot from R indicating an average, min and max value for a number of sample types. as horizontal lines with the sample types on the y-axis. (see http://home.newmedia.no/sickel/R.html for the plot and code) In some cases, the min value is the detection limit, and I would like to indicate that bu using a <, rather than the usual | I use for indicating the value. I am plotting each of the values using: points(low[s],s+offset,col=i/3,pch='I') Is it some kind of inline if, iif(cond,true,false), function in R? I have looked for it but not found it. Regards Moretn __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Plotting w/multiple y-axes?
Per Bak wrote: >How do I plot using multiple(2) y-axes? >I have two series that use the same x-data, but have very different scales. I don't know, it that is the only, or even the best way to do it, but I plot with multiple Y-axes using the grid package. The problem I have found is that you have to start using a completely new syntax for plotting Morten example: # ywtext and yrtext are initialized to the text to be plotted at # the 1st and 2nd Y axes grid.newpage() #1st series, scale 0 - 500: push.viewport(viewport(yscale=c(0,500),w=.75,h=.75,xscale=xscale)) grid.points(unit(hillesoy$date,"native"), unit(hillesoy$value,"native"),size=unit(3,"mm"),gp=gp.sw) grid.xaxis(at=c(1990:2003),gp=gp.axis) grid.yaxis(main=FALSE,gp=gp.axis) grid.text(ywtext,x=unit(2004.8,"native"),rot=270, gp=gp.text) #2nd series, scale 0-250 push.viewport(viewport(yscale=c(0,250),xscale=xscale)) grid.lines(unit(sellafield$year,"native"), unit(sellafield$amount,"native"),gp=gp.sella) grid.yaxis(at=c(0,50,100,150,200,250),main=TRUE,gp=gp.axis) grid.text(yrtext,x=unit(1988.3,"native"),rot=270, __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help