[R] duplicate data
Hello, I have a long list of x-, y- and z-data and try to generate a heatmap. Obviously there are several data with identical x- and y-values. I get the following error message: Error in interp.old(x, y, z, xo = xo, yo = yo, ncp = 0, extrap = extrap, : duplicate data points: need to set 'duplicate = ..' Unfortunately there seems no help screen on "duplicate". I'd prefer to average the z-values in case there are identical x/y-values. Is that possible? If necessary for an answer I'll copy the short script below. Thanks for helping! Richard % #RM¨u 5.2.2013, r.muel...@oeko-sorpe.de require(akima) # Das Paket akima wird ben¨otigt, um # nicht vorhandene Punkte zu interpolieren# und einen sch¨onen Farbgradienten hinzukriegen sorpe <- read.csv("bis_130204-korr.csv") pdf("sorpe.pdf")# Es wird nicht auf den Bildschirm gezeichnet, # sondern ein PDF-Dokument erstellt. zr <- range(290,220)# Hier wird der Bereich f¨ur die z-Werte# festgelegt: plot(ylim = c(7.9, 8), # Der Bereich der Achsen wird definiert xlim = c(51.30, 51.4), x ~ y, # Es soll ein x-y-Diagramm werden sorpe, # Aufruf der x-, y-, z-Tabelle pch = NA) # Die Punkte f¨ur die x-y-Wertepaare sollen unsichtbar sein (’NA’) sorpe.li <- interp(sorpe$x, sorpe$y, sorpe$z) # Hier werden die fehlenden Punkte interpoliert image(sorpe.li, # In das Diagramm wird ein Rasterbild aus den interpolierten Werten gezeichnet zlim = zr, # Der vorher definierte Wertebereich wird aufgerufen col = rev(rainbow( # Ein in R vordefiniertes Farbmodell wird verwendet 30, start = 0, end = 8/12)), # mit 30 Farbabstufungen, die den z-Werten zugeordnet werden. add = TRUE) # Das Bild wird ¨uber das bereits Vorhandene# gezeichnet contour(sorpe.li, # Isohypsen werden eingezeichnet add = TRUE) points(sorpe, # Die urspr¨unglichen Messpunkte werden pch = 1) # eingezeichnet, und zwar als Kreise -- Richard Müller . Am Spring 9 . D-58802 Balve http://www.oeko-sorpe.de - http://www.phytoplankton.info - http://independent.academia.edu/Richard __ 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] carpet plots
Hi all, I wonder why there is so little software for carpet plots (german: Rasterdiagramm) (Three dimensional plot (x, y, z), the 3rd dimension (z) symbolized by colourgradients). Besides from one or the other non free software I only found an OpenOffice macro, a combination of Gnuplot and Excel (an Excel macro calling gnuplot) (http://www.johannes-hopf.de/2009/12/carpet-plot-version-1-3/9 and Quikgrid (http://www.galiander.ca/quikgrid/) which I use for bathymetric maps. Though I use one or two R scripts I have no deeper knowledge. Because I think "That's a thing R can do!", I suppose, there are scripts for this purpose. Perhaps one of you knows such a script. I would be very grateful if you could point me to some information on this subject. Richard -- Richard Müller . Am Spring 9 . D-58802 Balve www.oeko-sorpe.de __ 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] Using data stored in a file for a heatmap
Hi all, I just try to get familiar with levelplot() for generating heatmaps. I have x, y, z-data stored in a file: e.g.: "file.csv": 0 0 0.1 0 1 0.5 0 2 0.4 1 0 0.3 1 1 0.4 1 2 0.6 ... I can use scan() for generating the matrix for R: inp <- scan("file.csv", list(0, 0, 0)) How can I feed inp into levelplot()? Thanks a lot for your help Richard -- Richard Müller . Am Spring 9 . D-58802 Balve www.oeko-sorpe.de __ 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] Colour gradients and colour fill between points
Hello, Can somebody help me on a colour question? I have a levelplot made with the following syntax: library(lattice) inp <- read.csv("hoenne1", header = TRUE) levelplot(z~x*y, data = inp, region = TRUE, pretty = TRUE, col.regions = terrain.colours) The file "hoenne1" contains the data. I'll give a short example: x,y,z 0,0,1 0,1,1 0,2,1 1,0,2 1,2,2 0,2,2 1,2,3 2,2,2 You see that data point 1,1 is missing. My script therefore produces an "empty" field. I want the following: the colours should be distributed as interpolating gradients. The empty hole in the middle should get the colour for z = 2 because that's the result when interpolating. Also the rest of the graph should be produced by interpolating, i.e. between 0,0 and 0,1 (z=1 resp. z=2) should be the colour for z = 1.5, so that a really smooth gradient is achieved. Is that possible? Thanks for helping, Richard -- Richard Müller . Am Spring 9 . D-58802 Balve www.oeko-sorpe.de __ 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] Origin of coordinate system
Dear R-community, In graphical representations of findings concerning bodies of standing water (lakes e.g.) in x-y-plots you often make use of a somewhat different definition of coordinates in a cartesian system: the origin is top-left, the x-axis (depth of the water body) from top to bottom and the f(x)-axis from left to right, so you can project the graphical representation of data in your imagination into the lake. I wasn't able to find out if this is possible in R-plots of x-y-data. I can treat the values, which are the x-values as y-values and vice versa. In simple plots that gives what I want (with the direction of the vertical axis from top to down with e.g. ylim = c(60,0). But I am not content with this. y is f(x) and not the other way round! I think, when I start with error bars or similar, I will get in trouble. Therefore my simple question: can I define a coordinate system with (0,0) in the upper left and the x- and y-axis as I described? Thanks for your answers - Richard -- Richard Müller . Am Spring 9 . D-58802 Balve www.oeko-sorpe.de __ 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] Origin of coordinate system
Thank you for your answer. That's the workaround I use - but that's not what I intended: the resulting graph looks correct. I used this approach a hundred times. But the ugly thing remains: the x-values (independent variables) are treated as y-values, and the y-values (dependent variables, f(x)) as if they were x-values.But what if I have several f(x) values for one x-value, and want to create an error bar or similar? Therefore my question: How can I plot x-values from top to bottom an y-values from left to right _without_ "masquerading" them as y resp. x? Richard 2012/8/23 S Ellison : > See ?par etc > > Setting ylim sets the bottom and top of the plot respectively, so > plot(1:10, ylim=c(11,0), xlim=c(0,11), ylab='depth') -- Richard Müller . Am Spring 9 . D-58802 Balve www.oeko-sorpe.de __ 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] Thanks for helping - back to the community?
DeaR R-fellows, I got a lot of help from you concerning the generation of heat maps, so I was able to write and work with a script for this purpose at last. Some visitors of our Ecological Station asked about the generation of the graphs and so I decided to write down a small description. Is it adviseable to publish the link to the article in an R-wiki (which?) so I can give back a little to the community? The article is in german: "Grafikausgabe mit "R" - zwei Beispiele aus der Praxis der Ökologischen Station" (www.phytoplankton.info/download/r-grafik.pdf) -- Richard Müller . Am Spring 9 . D-58802 Balve www.oeko-sorpe.de __ 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] Return Value of TCl/Tk window in R
Hello, I have the TCl/Tk command "tkmessageBox(titel="",message="x",icon="question",type="okcancel")" in my R script. Now I want to perform some operation in relation to the user's choice, something like "if (okpressed) xxx else yyy" What values does this command give and how are they used? Thank you, Richard -- Richard Müller - Am Spring 9 - D-58802 Balve-Eisborn www.oeko-sorpe.de __ 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] tcltk again
Hello, the admonition of Prof. Ripley to search the documentation to solve my problem helped, today I read a lot more on Tcl/Tk than before ;-) But now I'm stuck again. With the help of my script some functions are plotted on the display, then I ask if the user wants to save it as pdf. In windows I use winDialog and it works. But I can't succeed in Linux. In short: X11() ... res <-tkmessageBox(title="Beenden?", message="Vor dem Beenden als PDF speichern?", icon="question", type="okcancel") if (tclvalue(res) == "ok") ... - So far every thing is OK. Now I want a box the user should fill in the choosen filename (with a default) and then pdf(filename) ... I experimented with tkgetSaveFile(). But in the moment the user gives the filename the file is not yet generated! And I can't generate it in advance, because the filename is not yet specified. So I looked for a dialog box. [Some boxes are called "dialog boxes" though they only talk _to_ the user (besides the user's "yes" or "no")]. Just a simple box with a text field the user can type in and the value of this field given back. One option was the "modal dialog", but I was not able to pick the essentials out of it. I did not want to press several buttons until the necessary window appears. Also the "editable text window" was not really a solution. Perhaps a small hint again? Richard -- Richard Müller - Am Spring 9 - D-58802 Balve-Eisborn www.oeko-sorpe.de __ 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] tcltk again
> > ... > > I experimented with tkgetSaveFile(). But in the moment the user > > gives the > > filename the file is not yet generated! And I can't generate it in > > advance, > > because the filename is not yet specified. > > I don't see why this is a problem. In tkgetSaveFile(), the user can > just navigate to the correct directory and then type a filename in. > Then that would be returned. The following worked over here: > > x<-tkgetSaveFile() > #.. go to right directory and type in filename > tclvalue(x) Thank you, Charilaos, for your posting. I wrote the following: -- require(tcltk) #Tcl/Tk - Texteingabe Datei <- tkgetSaveFile(initialdir="temp/",defaultextension=".pdf", initialfile="Haupt_Chl_ Phaeo.pdf") fileName <- tclvalue(Datei) pdf(fileName) # graphical device driver with filename ...(code for the graphics)... --- As expected, I get an empty pdf-file. Specifying the pdf-device-driver results in automatically saving the generated pdf. The tkGetSave-function isn't helpful in this case. I must have the possibility to input a filename and then give this filename as an argument to the device-driver. Richard -- Richard Müller - Am Spring 9 - D-58802 Balve-Eisborn www.oeko-sorpe.de __ 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] tcltk again
Oops, I just sent the wrong mail. It should be the following one. Please delete my mail from 30.Dez. 17:51 Sorry, but I don't really understand the recommended method using the tk-Box "tkGetSaveFile". I wrote the following code: X11() # some code to generate a plot on the screen omitted res <-tkmessageBox(title="Finish?", message="save as PDF?", icon="question", type="okcancel") if (tclvalue(res) == "ok") Datei <- tkgetSaveFile(initialdir="temp/",defaultextension=".pdf", initialfile="Haupt_Chl_Phaeo.pdf") dev.copy(pdf, tclvalue(Datei)) else graphics.off() graphics.off() In the moment I'm saving I dont have the pdf generated yet. If I put it the other way round: dev.copy(pdf, tclvalue(Datei)) if (tclvalue(res) == "ok") Datei <- tkgetSaveFile(initialdir="temp/",defaultextension=".pdf", initialfile="Haupt_Chl_Phaeo.pdf") I don't have the filename specified when it is needed. (But today I could finish the Windows versions at last, using WinDialog ;-) Greetings Richard -- Richard Müller - Am Spring 9 - D-58802 Balve-Eisborn www.oeko-sorpe.de __ 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] tcltk again (solved)
> I wrote the following code: > X11() > # some code to generate a plot on the screen omitted > > res <-tkmessageBox(title="Finish?", > message="save as PDF?", > icon="question", type="okcancel") > > if (tclvalue(res) == "ok") > Datei <- tkgetSaveFile(initialdir="temp/",defaultextension=".pdf", > initialfile="Haupt_Chl_Phaeo.pdf") > dev.copy(pdf, tclvalue(Datei)) > else graphics.off() > graphics.off() > > In the moment I'm saving I dont have the pdf generated yet. That's wrong. It works perfectly. Thanks to all contributors. Happy New Year! Greetings Richard -- Richard Müller - Am Spring 9 - D-58802 Balve-Eisborn www.oeko-sorpe.de __ 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] passing args from the command line
Happy New Year to all! I want to run a script from a directory on a central server on different machines, linux and windows. To determine which machine is calling the script I want to pass an argument with the call (e.g. for choosing the display device, for writing path names etc.) I tried the following: R CMD BATCH --args gui=4 /home/script.R script.out (linux) resp. Rcmd BATCH --args gui=1 Z:/script.R script.out (windows) The script started with args(commandArgs(TRUE)) # thanks to James Forester for his R-concerning blog script.out says: Error in commandArgs(TRUE): unused argument(s) (linux) windows says: input file --args cannot be opened Something must be going wrong (but different things on Win and Linux) (but what?) Richard -- Richard Müller - Am Spring 9 - D-58802 Balve-Eisborn www.oeko-sorpe.de __ 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 ignore or omit somethings while reading the data table
Am Mittwoch, 2. Januar 2008 14:14 schrieb mrafi: > hello respected ppl... > am a engg. student...i was trying to use R in statistical calculations > now the problem is..i imported a huge tsv file onto R...it has a column csv? > which gives cost...and it has "$" with each numerical value in this > column...it is something like this..$.05,$.1,$.075...and so on.. > R is reading it as "character vector"... > i tried using all the arguments but could only change it to a "factor" > i want to read it as numericals...and perform further operations.. > i know it is a stupid problem but can any1 help me get outta this... > thank you all...!!! I'd like to have it simple... open your csv-file in a text editor, with "find/replace" replace your "$" by "" -- Richard Müller - Am Spring 9 - D-58802 Balve-Eisborn www.oeko-sorpe.de __ 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.