[R] Stacked Bar
Hi R Users! Thanks in advance. I am using R-2.5.1 on Windows XP. I am trying to do a stacked bar plot, but could not get through the following problem. The code is given below. 1. How can I provide 15 different colors for each method with 15 Rows? 2. How can I put the legend in a particular position (eg., in the top or bottom or right or left)? How can I put legend using a number of rows (eg., using two or three rows)? Once again thank you very much for your time. Regards, Debabrata (Deb) Statistician NSW Department of CommerceSydney, Australia. The Code: library(lattice) library(graphics) x - matrix(1:75, ncol= 5) dimnames(x)[[2]] - paste(Method, 1:5, sep=) dimnames(x)[[1]] - paste(Row, 1:15, sep=) # library: graphics barplot(x, beside=FALSE, col= 1:nrow(x), legend= rownames(x) ) # library: lattice barchart(Freq ~ Var2, data = as.data.frame.table(x), groups = Var1, stack = TRUE, auto.key = TRUE) - Park yourself in front of a world of choices in alternative vehicles. [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Stacked Bar
Jim, Thanks for such a quick response. It works well. Is it possible to fill the bars with patterns and colours? Regards, Deb Jim Lemon [EMAIL PROTECTED] wrote: Deb Midya wrote: Hi R Users! Thanks in advance. I am using R-2.5.1 on Windows XP. I am trying to do a stacked bar plot, but could not get through the following problem. The code is given below. 1. How can I provide 15 different colors for each method with 15 Rows? 2. How can I put the legend in a particular position (eg., in the top or bottom or right or left)? How can I put legend using a number of rows (eg., using two or three rows)? Hi Deb, As you have probably noticed, the integer coded colors repeat too quickly for the number of colors you want. You can use the rainbow() function to generate colors like this: barplot(x,beside=FALSE,col=rainbow(nrow(x))) or there are lots of other color generating functions in the grDevices or plotrix packages. Here's how to get your legend in an empty space for your plot. There is also an emptyspace() function in the plotrix package that tries to find the biggest empty space in a plot, although it probably wouldn't work in this case. legend(0,1000,rownames(x),fill=rainbow(nrow(x))) Jim - [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Calling R function in C
Hi R Users! Thanks in advance. I am using R-2.5.1 on Windows XP and I have installed all necessary tools such as perl and tools.exe. I am trying to use sample(1:100, 3, rep=F) in C. How can I use this R function in C? Once again thank you very much for your time. Regards, Debabrata (Deb) Statistician NSW Department of Commerce Sydney, Australia. - [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Calling C Code from R
Hi R Users, Thanks in advance. I am using R-2.5.1 on Windows XP. I am trying to call C code (testCX1.C) from R. testCX1.c calls another C code (funcC1.c) and returning a value to testCX1.c. I like to have this value in R. My steps are below: 1. R CMD SHLIB testCX1.c funcC1.c (at command propmt) 2. It creates testCX1.dll with warning (but testCX1.dll works): testCX1.c:38: warning: implicit declaration of function 'func' How to get rid off this error ? What is the best way to call funcC1.c from testCX1.c? I have provided the codes below: Once again thank you very much for the time you have given. Regards, Debabrata Midya (Deb) Statistician NSW Department of Commerce Sydney, Australia testCX1.C -- /* * testCX1.c * */ #include R.h #include Rdefines.h #include Rmath.h SEXP testC1(SEXP a) { int i, nr; double *xa, *xw, tmp; SEXP w; PROTECT(a = coerceVector(a, REALSXP)); nr = length(a); printf( Length : %d \n, nr); PROTECT(w = allocVector(REALSXP, 1)); xa = REAL(a); xw = REAL(w); tmp = 0.0; for (i = 0; i nr; i++) { tmp += xa[i]; } // tmp = 0.0; xw[0] = func(xa); UNPROTECT(2); return(w); } funcC1.c /* * funcC1.c * */ #include R.h #include Rdefines.h #include Rmath.h SEXP func(SEXP a) { int i, nr = 3; double *xa, *xw, tmp; SEXP w; PROTECT(a = coerceVector(a, REALSXP)); PROTECT(w = allocVector(REALSXP, 1)); xa = REAL(a); xw = REAL(w); tmp = 0.0; for (i = 0; i nr; i++) { tmp += xa[i] * xa[i]; } xw[0] = tmp; UNPROTECT(2); return(w); } R script --- dyn.load(testCX1.dll) xL - 1:5 xL - as.double(as.vector(t(xL))) .Call(testC1,xL) [1] 55 - [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calling C Code from R
Gabor, Thank you very much for such a quick response. As I am new to this area, will you please explain where can I put SEXP func(SEXP a); in my program. Once again, thank you very much for your quick response. Regards, Deb Gabor Csardi [EMAIL PROTECTED] wrote: On Wed, Jul 04, 2007 at 04:39:18AM -0700, Deb Midya wrote: Hi R Users, Thanks in advance. I am using R-2.5.1 on Windows XP. I am trying to call C code (testCX1.C) from R. testCX1.c calls another C code (funcC1.c) and returning a value to testCX1.c. I like to have this value in R. My steps are below: 1. R CMD SHLIB testCX1.c funcC1.c (at command propmt) 2. It creates testCX1.dll with warning (but testCX1.dll works): testCX1.c:38: warning: implicit declaration of function 'func' How to get rid off this error ? By adding the prototype of 'func' to testCX1.c: SEXP func(SEXP a); Probably it is simplest to collect all prototypes in a single header file and include that from all .c files. What is the best way to call funcC1.c from testCX1.c? See .C and .Call and in particular the 'Writing R Extensions' manual, 5 System and foreign language interfaces. Gabor [...] -- Csardi Gabor MTA RMKI, ELTE TTK - Boardwalk for $500? In 2007? Ha! [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Difference between two time series
Hi R Users! Thanks in advance. I am using R 2.4.1 on windows XP. I have a series of (x[i,t], y[i,t]), say i = 1, 2, .., n and t = t1, t2, .., tT. The n is large in number. The series y[i,t] is constructed from x[i,t] using moving average of order o (say o = 30 days). I am trying to extract m (m n) series where: The difference between x[i,t] and y[i,t] (ie, x[i,t] - y[i,t]) is in increasing order over the last d days (say d= 30 days). Is there any package in R can do this? Any further advice is highly appreciated. Once again, thank you very much for the time you have given. Regards, Deb - TV dinner still cooling? Check out Tonight's Picks on Yahoo! TV. [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Fwd: Re: Calling C code from R
Hi! Thanks in advance. Thanks to all of you who have responded to me on above. This is one of the responses I received on above. I have installed perl (with path C:\Perl\bin\;) an MinGW (with path C:\MinGW\bin; C:\MinGW;). At the Command Prompt (C:\R-2.4.0\bin) I have typed: C:\R-2.4.0\binRcmd SHLIB useC1.c (No error and useC1.dll file has not been created) C:\R-2.4.0\binR CMD SHLIB useC1.c (No error and useC1.dll file has not been created) May I request you where I am going wrong. Regards, Deb Statistician NSW Department of Commerce Sydney Australia. Note: forwarded message attached. - Need Mail bonding? ---BeginMessage--- X-Originating-IP: [129.132.145.15] Authentication-Results: mta305.mail.mud.yahoo.com from=stat.math.ethz.ch; domainkeys=neutral (no sig) Received: from 129.132.145.15 (EHLO hypatia.math.ethz.ch) (129.132.145.15) by mta305.mail.mud.yahoo.com with SMTP; Thu, 01 Feb 2007 09:06:15 -0800 Received: from hypatia.math.ethz.ch (hypatia [129.132.145.15]) by hypatia.math.ethz.ch (8.13.6/8.13.6) with ESMTP id l11Bhc1w009865; Thu, 1 Feb 2007 12:44:51 +0100 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on hypatia.math.ethz.ch X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=AWL, SPF_HELO_PASS autolearn=no version=3.1.7 Received: from talk.nabble.com (www.nabble.com [72.21.53.35]) by hypatia.math.ethz.ch (8.13.6/8.13.6) with ESMTP id l11BLmS8001133 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for r-help@stat.math.ethz.ch; Thu, 1 Feb 2007 12:21:49 +0100 Received: from [72.21.53.38] (helo=jubjub.nabble.com) by talk.nabble.com with esmtp (Exim 4.50) id 1HCa0h-0007kZ-Th for r-help@stat.math.ethz.ch; Thu, 01 Feb 2007 03:21:47 -0800 Date: Thu, 1 Feb 2007 03:21:47 -0800 (PST) From: Vladimir Eremeev [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch In-Reply-To: [EMAIL PROTECTED] MIME-Version: 1.0 X-Nabble-From: [EMAIL PROTECTED] References: [EMAIL PROTECTED] X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch Subject: Re: [R] Calling C code from R X-BeenThere: r-help@stat.math.ethz.ch X-Mailman-Version: 2.1.9 Precedence: list List-Id: Main R Mailing List: Primary help r-help.stat.math.ethz.ch List-Unsubscribe: https://stat.ethz.ch/mailman/listinfo/r-help, mailto:[EMAIL PROTECTED] List-Archive: https://stat.ethz.ch/pipermail/r-help List-Post: mailto:r-help@stat.math.ethz.ch List-Help: mailto:[EMAIL PROTECTED] List-Subscribe: https://stat.ethz.ch/mailman/listinfo/r-help, mailto:[EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: [EMAIL PROTECTED] Errors-To: [EMAIL PROTECTED] Content-Length: 762 You need to install perl and MinGW, at least. If you have them installed, then you need to properly set PATH environment variable and, probably, restart your command line session. See chapter 5 of the manual Writing R extensions (installed in R_HOME/doc/manual) and these two links http://www.murdoch-sutherland.com/Rtools/ http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/ Also, it would be great to upgrade R to 2.4.1 Deb Midya wrote: I am using R-2.4.0 on Windows XP. I am trying to create dll file. My C code: /* useC1.c */ void useC(int *i) { i[6] = 100; } I have tried to create useC1.dll. C:\R-2.4.0\binR CMD SHLIB useC1.c 'perl' is not recognized as an internal or external command, operable program or batch file. Then I have tried: C:\R-2.4.0\binRcmd SHLIB useC1.c 'perl' is not recognized as an internal or external command, operable program or batch file. -- View this message in context: http://www.nabble.com/-R--Calling-C-code-from-R-tf3154058.html#a8746593 Sent from the R help mailing list archive at Nabble.com. __ 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 and provide commented, minimal, self-contained, reproducible code. ---End Message--- __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Calling C code from R
Hi! Thanks in advance. I am using R-2.4.0 on Windows XP. I am trying to create dll file. My C code: /* useC1.c */ void useC(int *i) { i[6] = 100; } I have tried to create useC1.dll. C:\R-2.4.0\binR CMD SHLIB useC1.c 'perl' is not recognized as an internal or external command, operable program or batch file. Then I have tried: C:\R-2.4.0\binRcmd SHLIB useC1.c 'perl' is not recognized as an internal or external command, operable program or batch file. I am looking forward for your reply. Regards, Deb Statistician NSW Department of Commerce Sydney Australia. - [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.