G'day, I am new user to R, and have been thrown in the deep end with a something my company want me to write. my code is as follows: kenttemp=read.csv("mnowak.11.1.csv") rows=nrow(kenttemp)-5 kent=kenttemp[1:rows,] #have to remove the last 5 lines of the graph as they interfere with rest of data max(kent[,16],na.rm=TRUE)->ymax ymax=ymax+200 #This is to get vertical scale to fit more accurately Ann=kent$Ann kent=as.matrix(kent) barplot(Ann,main="Annual Monthly Rainfail Data", xlab="Year",ylab="Rainfall (mm)",ylim=c(0,ymax),col="blue",space=0,names.arg=c(kent[,2]), cex.names=0.8) All the code works fine, and does as I want it to, however I need to create 2 things. Firstly, I need to somehow make it so that when the script is run (I realise that there are no functions or anything yet, but that is still beyond my 2 day old knowledge of this program, and that will come as soon as I figure it out), it will ask the user for the name of the csv file it wants to open, and then prompt for what the user wants to save it as. Secondly, I need to create a running mean on the data. The data is to be rainfaill or temp over an extended period, which will vary depending on the files used. The data will generally range over a >30 year period, and I need to create an 11 year running mean. If anyone is able to at least point me in the right direction so I know -what- to look for at least, since I am blindly fumbling my way through. Cheers. -- View this message in context: http://n4.nabble.com/prompts-and-running-means-tp1475403p1475403.html Sent from the R help mailing list archive at Nabble.com.
RagingJim wrote:> > > ... it will ask the user for the name of the csv file it wants to open, > and then prompt for what the user wants to save it as. >http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/FileOpenSave.html RagingJim wrote:> > > Secondly, I need to create a running mean on the data. >See rollmean in package zoo, and several postings mainly from Gabor Grothendiek in http://r-project.markmail.org/search/?q=rollmean Dieter -- View this message in context: http://n4.nabble.com/prompts-and-running-means-tp1475403p1475471.html Sent from the R help mailing list archive at Nabble.com.
Thanks mate, will get the zoo package ASAP. I have been working on the file open/save part, and it works as planned except for one bit. When I save it, it does not save as the relevant file type. This is again my code: require(tcltk) fileName<-tclvalue(tkgetSaveFile(filetypes="{{PNG Files} {.png}} ")) png(fileName) barplot(Ann,main="Annual Rainfail Data", xlab="Year",ylab="Rainfall (mm)",ylim=c(0,ymax),col="blue",space=0,names.arg=c(kent[,2]), cex.names=0.8) legend("topleft",c("This picture"),bty="n") dev.off() When I go to save it, the corrent save window pops up, and it has the png file format selected, yet when I type in a name and save, it is saved without a file type. What am I doing wrong? Thanks again for your help -- View this message in context: http://n4.nabble.com/prompts-and-running-means-tp1475403p1476654.html Sent from the R help mailing list archive at Nabble.com.
Perhaps the One R Tip a Day might be helpful. The first part of this example saves a png file. http://onertipaday.blogspot.com/2009/01/statistical-visualizations-part-2.html Good luck, Jim RagingJim wrote:> Thanks mate, will get the zoo package ASAP. I have been working on the file > open/save part, and it works as planned except for one bit. When I save it, > it does not save as the relevant file type. > > This is again my code: > > require(tcltk) > fileName<-tclvalue(tkgetSaveFile(filetypes="{{PNG Files} {.png}} ")) > png(fileName) > barplot(Ann,main="Annual Rainfail Data", xlab="Year",ylab="Rainfall > (mm)",ylim=c(0,ymax),col="blue",space=0,names.arg=c(kent[,2]), > cex.names=0.8) > legend("topleft",c("This picture"),bty="n") > dev.off() > > When I go to save it, the corrent save window pops up, and it has the png > file format selected, yet when I type in a name and save, it is saved > without a file type. What am I doing wrong? > > Thanks again for your help >
Thanks Jim, however if I change "png(fileName)" to "png("picture.png")" then this: "require(tcltk) fileName<-tclvalue(tkgetSaveFile(filetypes="{{PNG Files} {.png}} ")) " becomes obsolete. Assuming of course that is what you were referring to. Otherwise I completely missed your point. Cheers. -- View this message in context: http://n4.nabble.com/prompts-and-running-means-tp1475403p1476792.html Sent from the R help mailing list archive at Nabble.com.
ok, solved it. Hoowever (there is always a however), I would like to centre the line plot of the rolling mean onto the centre of each bar in my bar plot. Currently, the lines aligns itself with the RHS of bars. I have tried this http://n4.nabble.com/Barplot-plot-same-scale-td1009254.html#a1009269 but it does not work. It draws the line on, but the line is stretched, and does not fit my rainfall data at all as it extends outside the RHS of the barplot. kent2<-zoo(kent) kent2<-rollapply(kent,11,mean,align=c("center")) mp<-barplot(c(kent2)) #kent 2 is the matrix of the rolling mean data barplot(Ann,main=title, xlab="Year",ylab="Rainfall (mm)", ylim=c(0,ymax),col="blue",space=0) lines(c(kent2),lwd=2) # I have drawn it twice just to see the difference lines(mp,c(kent2),lwd=2,col="red") -- View this message in context: http://n4.nabble.com/prompts-and-running-means-tp1475403p1478096.html Sent from the R help mailing list archive at Nabble.com.
Ok, took me a while, but I figured it out. Because my running mean had less years than my standard rainfall graph, when I overlaid the running mean onto the rainfall it was trying to stretch out. So I just plotted both onto the same graph., like so: barplot(Ann,main=title, xlab="Year",ylab="Rainfall (mm)", ylim=c(0,ymax),col="blue",space=0) cp<-barplot(new[,2],space=0,col=NA,border=NA,names.arg=NA,add=T) lines(cp,c(new[,2]),lwd=2) #"new" is the graph I made using the running mean rainfall data tabulated with the full year set. -- View this message in context: http://n4.nabble.com/prompts-and-running-means-tp1475403p1561105.html Sent from the R help mailing list archive at Nabble.com.