[R] how to put barchart and line chart in the same plot in ggplot2
dear userR: I am trying to plot two dependent variables in the same plot in ggplot2. because these two variables have very different magnitude, I have to use a second Y axis. I hope one variable to be line and the other to be barchart. The x axis is continuous. Yet since I have to make barchart, I guess I have to treat it as discrete or categorical. I have been google searching for the whole afternoon but do not have any clue. Can anyone give me a direction (not have to be a complete answer...)? many thanks -- View this message in context: http://r.789695.n4.nabble.com/how-to-put-barchart-and-line-chart-in-the-same-plot-in-ggplot2-tp4639194.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] statistical model with censored independent variable
hello: Does anyone know any R function which handles statisitcal model when the independent variable is censored? I know survival package does the analysis for censored dependnent variable. thanks -- View this message in context: http://r.789695.n4.nabble.com/statistical-model-with-censored-independent-variable-tp3592462p3592462.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.
Re: [R] how to add row index based a categorical column
thank you everyone. how can I not be aware of the existence of ave()? I try the following: tapply(data$value, data$level, rank). However, I have a very difficult time merging the resulting rank variable back to the original data frame. thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/how-to-add-row-index-based-a-categorical-column-tp3556126p3563627.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] how to add row index based a categorical column
hello, I have the following data manipulation issue. the following is the sample data: value level 4 A 5 A 2 A 10 B 9 B 34 B 100 C 34 C 101C. I hope to get the following result: value level rank 2 A 1 4 A 2 5 A 3 9 B 1 10 B 2 34 B 3 34 C 1 100C 2 101C. 3 as you may see, I need the data sorted and indexed within each level of level. what do I need to do calculate the rank variable? thanks, -- View this message in context: http://r.789695.n4.nabble.com/how-to-add-row-index-based-a-categorical-column-tp3556126p3556126.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.
Re: [R] a question on sqldf's handling of missing value and factor
Dear Gabor: I did not have time to look at this issue these few days. Now I saw your investigation. I am very grateful that you quickly identify the root cause of this. It seems that a little caution needs to be exercised when applying sqldf to text file with large number of blanks (I have no control over how the client files are produced). thank you again for such a good solution! -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-sqldf-s-handling-of-missing-value-and-factor-tp3331007p3381867.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.
Re: [R] a question on sqldf's handling of missing value and factor
I am sorry for posting the wrong source file. the correct source file is as follows: a b c aa 23 aaa 34.6 77.8 They are tab delimited but somehow could not be displayed correctly in browser. -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-sqldf-s-handling-of-missing-value-and-factor-tp3331007p3331667.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.
Re: [R] a question on sqldf's handling of missing value and factor
Dear Mr. Grothendieck : thank you so much for your attention. You are the real expert here. the following is a mock text file: a b c aa 23 aaa 34 77 note that both b and c column contain missing value (blank) I save it under my C drive and use both read.table and sqldf to import it to R and then use identical() function to compare the result. The following is the result: setwd(c:/) library(sqldf) test - file(test.txt) testx - sqldf(select * from test, + dbname = tempfile(), file.format = list(header = T, sep=\t, row.names = F)) testy- read.table(test.txt, header = T, sep=\t) identical(testx, testy) [1] FALSE testx abc 1 aa 23.0 2 aaa 34.6 0.0 3 77.8 testy abc 1 aa NA 23.0 2 aaa 34.6 NA 3 NA 77.8 class(testx$b) [1] factor class(testy$b) [1] numeric read.table seems to get it right while sqldf treats b as factor (if I add method=raw, b become character). what is more troubling is that column C has number 0 at the second row while in the original file it is missing. In my real world situation with a much larger text file, the problem is that many cells are empty when they all actually have values in the original text file. I would greatly appreciate your help if you can shed some light on this. thanks -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-sqldf-s-handling-of-missing-value-and-factor-tp3331007p3331662.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] a question on sqldf's handling of missing value and factor
Dear subscribers: I am using the following code to read a large number of big text files: library(sqldf) tempd - file() tempdx - sqldf(select * from tempd, dbname = tempfile(), file.format = list(header = T, sep=\t, row.names = F)) The problem is: all my numberical variable become factor (maybe because these columns all contain missing value). It would be quite cubersome to convert them to numeric variable using as.numeric one by one. Does anyone know how to re-set SQLDF so that it would automatically read the numeric column with missing row as real numeric instead of factor? many thanks -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-sqldf-s-handling-of-missing-value-and-factor-tp3331007p3331007.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.
Re: [R] why I could not reproduce the Mandelbrot plot demonstrated on R wiki
hi, peter: thank you for your attention. adding the line you suggested did display the static Mandelbrot plot with good resolution on R graphics device. However, the resulting gif file still come out ugly. the R wiki page I was referring to is the following: http://en.wikipedia.org/wiki/R_(programming_language) where the nice Mandelbrot plot and sample codes are provided. i would appreciate your help if you can provide further hint. thanks Peter Dalgaard-2 wrote: On 09/24/2010 10:41 PM, xin wei wrote: I am trying to reproduce the nice looking of Mandelbrot demonstrated by R wiki page by the following code: library(caTools)# external package providing write.gif function jet.colors = colorRampPalette(c(#7F, blue, #007FFF, cyan, #7FFF7F, yellow, #FF7F00, red, #7F)) m = 600 # define size C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), imag=rep(seq(-1.2,1.2, length.out=m), m ) ) C = matrix(C,m,m) # reshape as square matrix of complex numbers Z = 0 # initialize Z to zero X = array(0, c(m,m,20)) # initialize output 3D array for (k in 1:20) { # loop with 20 iterations Z = Z^2+C # the central difference equation X[,,k] = exp(-abs(Z)) # capture results } write.gif(X, Mandelbrot.gif, col=jet.colors, delay=100) Hmm, I couldn't be bothered with the caTools, but it looks fine for me with image(X[,,20],col=jet.colors(100)) Perhaps you need jet.colors(n) as well? however, the gif file created by this looks much worse than what is shown on R wiki page, see the comparison as follows (left one is what i created) http://r.789695.n4.nabble.com/file/n2591429/Picture1.png Save for the odd color scheme, the one on the left looks like a Mandelbrot set, the one on the right appears to be iteration 4. I couldn't find your original source for this on wiki.r-project.org? -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@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. -- View this message in context: http://r.789695.n4.nabble.com/why-I-could-not-reproduce-the-Mandelbrot-plot-demonstrated-on-R-wiki-tp2591429p2714024.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] why I could not reproduce the Mandelbrot plot demonstrated on R wiki
I am trying to reproduce the nice looking of Mandelbrot demonstrated by R wiki page by the following code: library(caTools)# external package providing write.gif function jet.colors = colorRampPalette(c(#7F, blue, #007FFF, cyan, #7FFF7F, yellow, #FF7F00, red, #7F)) m = 600 # define size C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), imag=rep(seq(-1.2,1.2, length.out=m), m ) ) C = matrix(C,m,m) # reshape as square matrix of complex numbers Z = 0 # initialize Z to zero X = array(0, c(m,m,20)) # initialize output 3D array for (k in 1:20) { # loop with 20 iterations Z = Z^2+C # the central difference equation X[,,k] = exp(-abs(Z)) # capture results } write.gif(X, Mandelbrot.gif, col=jet.colors, delay=100) however, the gif file created by this looks much worse than what is shown on R wiki page, see the comparison as follows (left one is what i created) http://r.789695.n4.nabble.com/file/n2591429/Picture1.png -- View this message in context: http://r.789695.n4.nabble.com/why-I-could-not-reproduce-the-Mandelbrot-plot-demonstrated-on-R-wiki-tp2591429p2591429.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.
Re: [R] how to generate a random data from a empirical distribition
hi, Frank: how can we make sure the randomly sampled data follow the same distribution as the original dataset? i assume each data point has the same prabability to be selected in a simple random sampling scheme. thanks -- View this message in context: http://r.789695.n4.nabble.com/how-to-generate-a-random-data-from-a-empirical-distribition-tp2302716p2305275.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.
Re: [R] how to generate a random data from a empirical distribition
hi, Dennis: points well taken. it seems to be important to investigate the nature of distribution. I may be too naive to assume a empirical probability distribution would be computed from a could of data points -- View this message in context: http://r.789695.n4.nabble.com/how-to-generate-a-random-data-from-a-empirical-distribition-tp2302716p2304329.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.
Re: [R] how to generate a random data from a empirical distribition
good point. It seems to be important to investigate the nature of distribution. I might be too naive to assume that a empirical probability distribution would be automatically generated from a cloud of data points. -- View this message in context: http://r.789695.n4.nabble.com/how-to-generate-a-random-data-from-a-empirical-distribition-tp2302716p2304332.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.
Re: [R] how to generate a random data from a empirical distribition
this is very insightful. sounds exactly like what I want to do. thanks. Frank. -- View this message in context: http://r.789695.n4.nabble.com/how-to-generate-a-random-data-from-a-empirical-distribition-tp2302716p2304346.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] how to generate a random data from a empirical distribition
hi, this is more a statistical question than a R question. but I do want to know how to implement this in R. I have 10,000 data points. Is there any way to generate a empirical probablity distribution from it (the problem is that I do not know what exactly this distribution follows, normal, beta?). My ultimate goal is to generate addition 20,000 data point from this empirical distribution created from the existing 10,000 data points. thank you all in advance. -- View this message in context: http://r.789695.n4.nabble.com/how-to-generate-a-random-data-from-a-empirical-distribition-tp2302716p2302716.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.
Re: [R] help with reshape is needed again!
thank you very much for such a thorough solution! -- View this message in context: http://r.789695.n4.nabble.com/help-with-reshape-is-needed-again-tp2260640p2260943.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 with reshape is needed again!
hi, folks: i need to transpose the following data: genetissuepatient1 patient2 patient3. - gene1 breast 10100 1 gene2 breast 20200 4 gene3 breast 3050 5 gene4 breast 40400 9 to the following format: patientID gene1 gene2 gene3gene4 --- 1 10 20 3040 2 100 200 50400 3 1 4 5 9 any suggestions how to use reshape or other function to achieve this? thanks -- View this message in context: http://r.789695.n4.nabble.com/help-with-reshape-is-needed-again-tp2260640p2260640.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 for reshape function
hi, everyone: i have a question on the reshape function. i have the following dataset : gene tissuepatient1 patient2 patient3. _ gene1 breast 10 20 50 gene2 breast 20 40 60 gene3 breast 100 200 300 which i hope to convert to the following format: gene patientID value gene1 - gene1 1 1010 gene1 2 2020 gene1 3 50100 gene2 1 2010 gene2 2 4020 gene2 3 60100 the column gene is required and column tissue is not needed. I use the following syntax to perform this task: tdata- reshape(data, varying=names(data)[-c(1,2)],direction=long, timevar =label,v.names=value,time=names(data)[-c(1,2)]); however, i lose the column gene in the resulting tranposed dataset. I did my best to go through the help doc for reshape. however, I am frustrated that the examples used in the help doc is kind o hard to follow to me. Can anyone help me modify the code to keep the column gene in the resulting table? Any constructive suggestion is welcome. thanks -- View this message in context: http://r.789695.n4.nabble.com/help-for-reshape-function-tp2259286p2259286.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.
Re: [R] help for reshape function
I am afraid that your solution is not solving the problem. it seems that timevar=gene just create the followings: GENESAMPLE value id 1.11 Kidney 3.69351 1 2.11 Kidney 5.42710 2 3.11 Kidney 5.26883 3 4.11 Kidney 2.88098 4 5.11 Kidney 4.68519 5 6.11 Kidney 5.92774 6 ] here the gene is just a empty column. I also lost the column that is supposed to store the header name of transposed variables in my target table. more suggests? thanks -- View this message in context: http://r.789695.n4.nabble.com/help-for-reshape-function-tp2259286p2259706.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] how to parse out string separated by special character
hi, everyone: i have a data frame with one single character column as followings: DS_xxx_yyy_24hr_zzz_1 DS_xxx_yyy_24hr_zzz_2 DS_xxx_yyy_24hr_zzz_3 DS_xxx_yyy_24hr_zzz_4 DS_xxx_yyy_24hr_zzz_1 DS_xxx_yyy_24hr_zzz_2 DS_xxx_yyy_24hr_zzz_3 DS_xxx_yyy_24hr_zzz_4 DS_xxx_yyy_24hr_zzz_1 i need to parse out the time part like the followings: name time DS_xxx_yyy_24hr_zzz_1 24hr DS_xxx_yyy_24hr_zzz_2 24hr DS_xxx_yyy_24hr_zzz_3 24hr DS_xxx_yyy_24hr_zzz_4 24hr DS_xxx_yyy_24hr_zzz_1 24hr DS_xxx_yyy_24hr_zzz_2 24hr DS_xxx_yyy_24hr_zzz_3 24hr DS_xxx_yyy_24hr_zzz_4 24hr DS_xxx_yyy_24hr_zzz_1 24hr what function should I look at? i have tried: strsplit(data, '_') and get a giant list which is not what i need. thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/how-to-parse-out-string-separated-by-special-character-tp2246301p2246301.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] what the problem could be if i am suddenly unable to add abline to the scatter plot?
I am doing very regular stuff like the following: attach(wtana) fm- lm(Body.Wt.on.SD1~Heart.Wt, data=wtana) #fm- lm(wtana$Body.Wt.on.SD1~wtana$Heart.Wt) lrf- loess(Body.Wt.on.SD1~Heart.Wt, wtana) #lrf- loess(wtana$Body.Wt.on.SD1~wtana$Heart.Wt) plot(Body.Wt.on.SD1,Heart.Wt) #plot(wtana$Body.Wt.on.SD1,wtana$Heart.Wt) #lines(spline(Heart.Wt,fitted(lrf)), col=2) abline(fm, col=4) however, the abline just refuse to to show up in the scatter cloud. Does anyone has clue? thanks -- View this message in context: http://r.789695.n4.nabble.com/what-the-problem-could-be-if-i-am-suddenly-unable-to-add-abline-to-the-scatter-plot-tp2196304p2196304.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.
Re: [R] how to make R plot under Linux
thank you for reply. I just type: hist(x) from SSH terminal, expecting a histogram to pop up like what i got under windows.instead I got the following error msg: Error in X11(d$display, d$width, d$height, d$pointsize, d$gamma, d$colortype, : unable to start device X11cairo In addition: Warning message: In function (display = , width, height, pointsize, gamma, bg, : unable to open connection to X11 display '' Would you give some clues what is going on? thanks -- View this message in context: http://n4.nabble.com/how-to-make-R-plot-under-Linux-tp1562060p1564632.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.
Re: [R] how to make R plot under Linux
hi, Kevin and K.Elo: thank you for the suggestion. Can you be more specific on these? (like how exactly get into x-switch or man ssh). I am totally ignorant about linux and SSH:( Memory limitation forces me to switch from windows to Linux cluster. Xin -- View this message in context: http://n4.nabble.com/how-to-make-R-plot-under-Linux-tp1562060p1564850.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.
Re: [R] how to make R plot under Linux
hi, Guys: thank you so much for all the suggestion. Now I seem to be able to set up x11 forwarding in PUTTY. however, I still could not get plot and I get the following error msg: Error in function (display = , width, height, pointsize, gamma, bg, : X11 I/O error while opening X11 connection to 'localhost:20.0' Is this error msg indication of lack of appropriate plotting package on the server or the server is not properly set up for X11 forwarding? thanks -- View this message in context: http://n4.nabble.com/how-to-make-R-plot-under-Linux-tp1562060p1565113.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.