RE: [R] Need help with R date handling and barchart with errorbars

From: Ghosh, Sandeep <sghosh_at_lexgen.com>
Date: Fri 29 Apr 2005 - 07:00:09 EST


Hi,

I'm having problems getting the resulting R image generated as an png file when trying to feed the R cmds through a java prog to R. I was facing the same problem once before and Deepayan had suggested to use "print" along with the chart cmd like print(barchart(...)), but the print cmd was not needed when running the r cmds directly inside R Console. Below is the r code that is generated by my java prog. and using JGR (http://stats.math.uni-augsburg.de/JGR/) fed to R.

testdata <- as.data.frame(t(structure(c(

4,2001,8.7,4.62,83,
4,2002,10.2,3.6,153,
4,2003,10.2,3.82,239,
4,2004,9.4,3.34,344,
5,2001,10.7,5.8,168,
5,2002,11.2,3.79,179,
5,2003,10.2,4.16,245,
5,2004,9.7,3.52,433,
6,2001,10.0,4.24,115,
6,2002,10.5,4.04,171,
6,2003,10.2,3.92,242,
6,2004,9.5,3.72,442,
7,2000,5.13,1.25,6,
7,2001,9.2,5.03,146,
7,2002,10.2,4.45,170,
7,2003,10.6,3.92,240,
7,2004,8.8,3.43,482,
8,2000,7.2,1.34,20,
8,2001,9.2,4.29,109,
8,2002,9.9,4.25,180,
8,2003,10.0,3.83,231,
8,2004,8.6,3.4,505,
9,2000,7.23,2.44,226,
9,2001,9.1,4.17,63,
9,2002,9.4,4.08,223,
9,2003,10.6,3.54,238,
9,2004,9.7,3.69,578,
10,2000,6.13,0.69,68,
10,2001,7.6,4.19,111,
10,2002,9.3,3.81,233,
10,2003,10.7,3.59,214,
10,2004,9.6,3.41,596,
11,2000,6.33,2.14,80,
11,2001,8.2,4.62,91,
11,2002,9.9,3.99,187,
11,2003,10.4,3.6,245,
11,2004,9.5,3.63,579,
12,2000,8.0,3.55,36,
12,2001,10.0,4.56,106,
12,2002,10.4,4.29,191,

12,2003,9.7,3.34,246,
12,2004,9.3,3.4,650,
1,2001,8.7,4.15,86,
1,2002,10.0,4.2,157,
1,2003,8.8,4.18,217,
1,2004,9.1,3.7,206,
1,2005,9.5,3.62,634,
2,2001,9.2,5.34,127,
2,2002,11.1,3.42,126,
2,2003,9.7,3.89,227,
2,2004,9.0,3.59,171,
2,2005,9.2,4.09,95,
3,2001,8.8,3.77,124,
3,2002,10.1,4.38,113,
3,2003,10.3,3.83,235,

3,2004,8.7,3.28,392,
), .Dim=c(5,56))));
colnames(testdata) <- c('month', 'year', 'mean','stdDev','miceCount'); testdata$month <- as.numeric(testdata$month); testdata$year <- factor(testdata$year);
testdata <- testdata[do.call("order", testdata), ]; trellis.par.set(theme = col.whitebg());

monthLabel <- c( 'Jan','Feb','Mar','Apr','May','Jun', 'Jul','Aug','Sep','Oct','Nov','Dec' );

png('391.png', width=600, height=as.numeric(length(levels(testdata$year))*400), pointsize=8); print(with(testdata,

     barchart(as.numeric(mean) ~ month | year, data=testdata,
	      layout=c(1,length(levels(testdata$year))),
	      horizontal=FALSE,
	      scales=list(x=list(labels=monthLabel)),
              origin = 0,
              sd = as.numeric(as.character(stdDev)),
              count = as.numeric(as.character(miceCount)),
              panel = function(x, y, ..., sd, count, subscripts) {
                  panel.barchart(x, y, ...)
                  sd <- sd[subscripts]
                  count <- count[subscripts]
                  panel.segments(as.numeric(x),
                                 y - sd/sqrt(count),
                                 as.numeric(x),
                                 y + sd/sqrt(count),
				 col = 'red', lwd = 2)
	      })));

dev.off();

As always, any help is greatly appreciated

-----Original Message-----
From: Deepayan Sarkar [mailto:deepayan@stat.wisc.edu] Sent: Friday, April 22, 2005 6:19 PM
To: Ghosh, Sandeep
Subject: Re: [R] Need help with R date handling and barchart with errorbars

On Friday 22 April 2005 14:27, you wrote:
> Hi Deepayan,
>
> Thanks so much for the response. Please bear with me as I'm very new
> to R. Just for a little background, the data to plot is
> going to come to me from a java ArrayList where each row will be like
> the rows I have in my sample data. Instead of writing to a file and
> then loading it into R (to save time) we want to skip the step and
> somehow directly load the data into a R dataframe. The easiest way I
> found was, the approach of converting the whole ArrayList into a csv
> format and then using templates create the dataframe code as below
> and load it into R.

That may well be the best way (I'm not familiar with R-Java interfaces).

Deepayan



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 Received on Fri Apr 29 07:07:05 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:28 EST