For the following code below, the x-axis ticks are 1,2,3,4,5,6,7 when I was
expection them to be 1,2,8,9,10,11,12. Please help me figure out where is the
mistake.
library(lattice)
testdata <- as.data.frame(t(structure(c(
1,2005,9.24,6.18,634,
2,2005,8.65,6.05,96,
8,2004,6.81,6.51,16,
9,2004,9.0,7.29,8,
10,2004,8.84,6.18,524,
11,2004,8.54,6.35,579,
12,2004,9.97,6.3,614,
12,2005,8.75,5.84,32,
), .Dim=c(5,8))))
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), ]
png('lexstar_3241.png', width=600,
height=as.numeric(length(levels(testdata$year))*200), pointsize=8)
trellis.par.set(theme = col.whitebg())
with(testdata, print(barchart(as.numeric(mean) ~ month | year, data=testdata,
layout=c(1,length(levels(year))),
horizontal=FALSE,
scales=list(y=list(limits=c(1,max(as.numeric(mean))+max(as.numeric(stdDev))))),
main='Marble Burying - Level I',
xlab='Months',
ylab='Mean',
sd = as.numeric(as.character(stdDev)),
panel= function(x, y, ..., sd, subscripts) {
panel.barchart(x, y, ...);
sd <- sd[subscripts];
panel.segments(as.numeric(x), y - sd, as.numeric(x), y + sd, col =
'red', lwd = 2);
}
)))
dev.off()
Any help is greatly appreciated...
Thanks,
Sandeep
[[alternative HTML version deleted]]
Ghosh, Sandeep wrote on 5/5/2005 11:10 AM:> For the following code below, the x-axis ticks are 1,2,3,4,5,6,7 when I was expection them to be 1,2,8,9,10,11,12. Please help me figure out where is the mistake. > > > library(lattice) > > testdata <- as.data.frame(t(structure(c( > 1,2005,9.24,6.18,634, > 2,2005,8.65,6.05,96, > 8,2004,6.81,6.51,16, > 9,2004,9.0,7.29,8, > 10,2004,8.84,6.18,524, > 11,2004,8.54,6.35,579, > 12,2004,9.97,6.3,614, > 12,2005,8.75,5.84,32, > ), .Dim=c(5,8)))) > > 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), ] > > png('lexstar_3241.png', width=600, height=as.numeric(length(levels(testdata$year))*200), pointsize=8) > trellis.par.set(theme = col.whitebg()) > > with(testdata, print(barchart(as.numeric(mean) ~ month | year, data=testdata, > layout=c(1,length(levels(year))), > horizontal=FALSE, > scales=list(y=list(limits=c(1,max(as.numeric(mean))+max(as.numeric(stdDev))))), > main='Marble Burying - Level I', > xlab='Months', > ylab='Mean', > sd = as.numeric(as.character(stdDev)), > panel= function(x, y, ..., sd, subscripts) { > panel.barchart(x, y, ...); > sd <- sd[subscripts]; > panel.segments(as.numeric(x), y - sd, as.numeric(x), y + sd, col = 'red', lwd = 2); > } > ))) > > dev.off() > > Any help is greatly appreciated... > > Thanks, > Sandeep > > [[alternative HTML version deleted]]Hi Sandeep, First, you are overusing as.numeric and as.character. Is there a reason for this that the example doesn't demonstrate. Second, scales$y$limits is the same as setting ylim. The latter is more readable in my opinion. As to your actual question, you should supply a scales argument for the x-axis. Below is what I came up with: barchart(mean ~ month | year, data = testdata, layout = c(1, nlevels(testdata$year)), horizontal = FALSE, ylim = c(1, max(testdata$mean) + max(testdata$stdDev)), main = 'Marble Burying - Level I', xlab = 'Months', ylab = 'Mean', sd = testdata$stdDev, scales = list(x = list(at = 1:7, labels = unique(sort(testdata$month)))), panel = function(x, y, ..., sd, subscripts) { panel.barchart(x, y, ...) sd <- sd[subscripts] panel.segments(x, y - sd, x, y + sd, col = 'red', lwd = 2) }) HTH, --sundar
Hi Sundar,
Greatly appreicate your response, but I get this error on running the barchart
cmd
with(testdata, print(barchart(mean ~ month | year, data = testdata,
layout = c(1, nlevels(testdata$year)),
horizontal = FALSE,
ylim = c(1, max(testdata$mean) + max(testdata$stdDev)),
main = 'Marble Burying - Level I',
xlab = 'Months',
ylab = 'Mean',
sd = testdata$stdDev,
scales = list(x = list(at = 1:7, labels =
unique(sort(testdata$month)))),
panel = function(x, y, ..., sd, subscripts) {
panel.barchart(x, y, ...)
sd <- sd[subscripts]
panel.segments(x, y - sd, x, y + sd, col = 'red', lwd = 2)
})
))
Error in calculateGridLayout(x, rows.per.page, cols.per.page, number.of.cond, :
Invalid value for labels
-Sandeep
-----Original Message-----
From: Sundar Dorai-Raj [mailto:sundar.dorai-raj at pdf.com]
Sent: Thursday, May 05, 2005 1:44 PM
To: Ghosh, Sandeep
Cc: r-help at stat.math.ethz.ch; MSchwartz at medanalytics.com
Subject: Re: [R] Need some quick help with lattice - barchart
Ghosh, Sandeep wrote on 5/5/2005 11:10 AM:> For the following code below, the x-axis ticks are 1,2,3,4,5,6,7 when I was
expection them to be 1,2,8,9,10,11,12. Please help me figure out where is the
mistake.
>
>
> library(lattice)
>
> testdata <- as.data.frame(t(structure(c(
> 1,2005,9.24,6.18,634,
> 2,2005,8.65,6.05,96,
> 8,2004,6.81,6.51,16,
> 9,2004,9.0,7.29,8,
> 10,2004,8.84,6.18,524,
> 11,2004,8.54,6.35,579,
> 12,2004,9.97,6.3,614,
> 12,2005,8.75,5.84,32,
> ), .Dim=c(5,8))))
>
> 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), ]
>
> png('lexstar_3241.png', width=600,
height=as.numeric(length(levels(testdata$year))*200), pointsize=8)
> trellis.par.set(theme = col.whitebg())
>
> with(testdata, print(barchart(as.numeric(mean) ~ month | year,
data=testdata,
> layout=c(1,length(levels(year))),
> horizontal=FALSE,
>
scales=list(y=list(limits=c(1,max(as.numeric(mean))+max(as.numeric(stdDev))))),
> main='Marble Burying - Level I',
> xlab='Months',
> ylab='Mean',
> sd = as.numeric(as.character(stdDev)),
> panel= function(x, y, ..., sd, subscripts) {
> panel.barchart(x, y, ...);
> sd <- sd[subscripts];
> panel.segments(as.numeric(x), y - sd, as.numeric(x), y + sd, col =
'red', lwd = 2);
> }
> )))
>
> dev.off()
>
> Any help is greatly appreciated...
>
> Thanks,
> Sandeep
>
> [[alternative HTML version deleted]]
Hi Sandeep,
First, you are overusing as.numeric and as.character. Is there a reason
for this that the example doesn't demonstrate.
Second, scales$y$limits is the same as setting ylim. The latter is more
readable in my opinion.
As to your actual question, you should supply a scales argument for the
x-axis. Below is what I came up with:
barchart(mean ~ month | year, data = testdata,
layout = c(1, nlevels(testdata$year)),
horizontal = FALSE,
ylim = c(1, max(testdata$mean) + max(testdata$stdDev)),
main = 'Marble Burying - Level I',
xlab = 'Months',
ylab = 'Mean',
sd = testdata$stdDev,
scales = list(x = list(at = 1:7,
labels = unique(sort(testdata$month)))),
panel = function(x, y, ..., sd, subscripts) {
panel.barchart(x, y, ...)
sd <- sd[subscripts]
panel.segments(x, y - sd, x, y + sd, col = 'red', lwd = 2)
})
HTH,
--sundar
Deepayan Sarkar
2005-May-05 19:03 UTC
[R] Re: Need some quick help with lattice - barchart
On Thursday 05 May 2005 13:10, Ghosh, Sandeep wrote:> For the following code below, the x-axis ticks are 1,2,3,4,5,6,7 when I was > expection them to be 1,2,8,9,10,11,12. Please help me figure out where is > the mistake.[...]> colnames(testdata) <- c('month', 'year', 'mean','stdDev','miceCount') > testdata$month <- as.numeric(testdata$month)[...]> with(testdata, print(barchart(as.numeric(mean) ~ month | year, > data=testdata, layout=c(1,length(levels(year))), > horizontal=FALSE,[...] 'month' is numeric, so it's being coerced to be a shingle. Try using 'factor(month)' instead in the formula. Deepayan
It worked for me..Here are the commands..
library(lattice)
testdata <- as.data.frame(t(structure(c(
1,2005,9.24,6.18,634,
2,2005,8.65,6.05,96,
8,2004,6.81,6.51,16,
9,2004,9.0,7.29,8,
10,2004,8.84,6.18,524,
11,2004,8.54,6.35,579,
12,2004,9.97,6.3,614,
12,2005,8.75,5.84,32,
), .Dim=c(5,8))))
colnames(testdata) <- c('month', 'year',
'mean','stdDev','miceCount')
testdata$month <- factor(testdata$month)
testdata$year <- factor(testdata$year)
testdata <- testdata[do.call("order", testdata), ]
png('lexstar_3241.png', width=600,
height=as.numeric(length(levels(testdata$year))*200), pointsize=8)
trellis.par.set(theme = col.whitebg())
with(testdata, print(barchart(as.numeric(mean) ~ month | year, data=testdata,
layout=c(1,length(levels(year))),
horizontal=FALSE,
scales=list(y=list(limits=c(1,max(as.numeric(mean))+max(as.numeric(stdDev))))),
main='Marble Burying - Level I',
xlab='Months',
ylab='Mean',
sd = as.numeric(as.character(stdDev)),
panel= function(x, y, ..., sd, subscripts) {
panel.barchart(x, y, ...);
sd <- sd[subscripts];
panel.segments(as.numeric(x), y - sd, as.numeric(x), y + sd, col =
'red', lwd = 2);
}
)))
dev.off()
Thanks a lot Deepayan..
-Sandeep
-----Original Message-----
From: Sundar Dorai-Raj [mailto:sundar.dorai-raj at pdf.com]
Sent: Thursday, May 05, 2005 2:05 PM
To: Deepayan Sarkar
Cc: Ghosh, Sandeep; r-help at stat.math.ethz.ch
Subject: Re: [R] Re: Need some quick help with lattice - barchart
Deepayan Sarkar wrote on 5/5/2005 12:03 PM:> On Thursday 05 May 2005 13:10, Ghosh, Sandeep wrote:
>
>>For the following code below, the x-axis ticks are 1,2,3,4,5,6,7 when I
was
>>expection them to be 1,2,8,9,10,11,12. Please help me figure out where
is
>>the mistake.
>
> [...]
>
>>colnames(testdata) <- c('month', 'year',
'mean','stdDev','miceCount')
>>testdata$month <- as.numeric(testdata$month)
>
> [...]
>
>>with(testdata, print(barchart(as.numeric(mean) ~ month | year,
>>data=testdata, layout=c(1,length(levels(year))),
>> horizontal=FALSE,
>
> [...]
>
> 'month' is numeric, so it's being coerced to be a shingle. Try
using
> 'factor(month)' instead in the formula.
>
> Deepayan
>
Hi Deepayan,
That was my original thought too. But when I tried it I got:
Error in unit(x0, default.units, units.per.obs) :
'x' must be numeric
Changing horizontal to TRUE produces the plot, but I'm sure that's not
what Sandeep wants.
--sundar
Hi Deepayan,
Thanks a lot for your last Friday response. I have yet not got a chance to
implement the month names for x -axis ticks yet, but will be on it as soon as
some of the bugs reported by users have been resolved. In regard to that one of
the users pointed out a problem with appeared to happen whenever the mean data
getting plotted is less than 1.
Here's the r code generated by my prog
library(lattice)
testdata <- as.data.frame(t(structure(c(
1,2005,0.53,0.05858,159,
2,2005,0.52,0.05413,143,
3,2005,0.49,0.04986,160,
4,2005,0.5,0.05679,166,
5,2005,0.5,0.05938,32,
1,2004,0.54,0.05774,94,
2,2004,0.56,0.05748,101,
3,2004,0.54,0.0571,101,
4,2004,0.56,0.07045,96,
5,2004,0.55,0.0584,92,
6,2004,0.55,0.06136,96,
7,2004,0.55,0.06219,119,
8,2004,0.55,0.06302,124,
9,2004,0.55,0.06094,127,
10,2004,0.54,0.06482,137,
11,2004,0.54,0.06485,142,
12,2004,0.53,0.05624,157,
1,2003,0.58,0.07141,152,
2,2003,0.57,0.06181,87,
3,2003,0.54,0.05462,116,
4,2003,0.53,0.06139,124,
5,2003,0.52,0.05209,110,
6,2003,0.52,0.0596,125,
7,2003,0.54,0.06634,138,
8,2003,0.52,0.05226,84,
9,2003,0.52,0.05892,128,
10,2003,0.51,0.06095,109,
11,2003,0.53,0.06355,87,
12,2003,0.55,0.0591,117,
1,2002,0.58,0.05102,59,
2,2002,0.56,0.06422,61,
3,2002,0.55,0.06219,64,
4,2002,0.56,0.06965,65,
5,2002,0.56,0.0557,87,
6,2002,0.57,0.06578,73,
7,2002,0.57,0.06617,85,
8,2002,0.58,0.06153,76,
9,2002,0.58,0.06301,107,
10,2002,0.59,0.0747,117,
11,2002,0.59,0.0737,92,
12,2002,0.59,0.06888,100,
1,2001,0.51,0.07221,28,
2,2001,0.48,0.06705,59,
3,2001,0.51,0.06753,71,
4,2001,0.52,0.0738,37,
5,2001,0.49,0.07891,92,
6,2001,0.48,0.06521,66,
7,2001,0.49,0.05509,53,
8,2001,0.53,0.07104,61,
9,2001,0.53,0.06878,45,
10,2001,0.54,0.06661,38,
11,2001,0.51,0.06486,52,
12,2001,0.56,0.05969,59,
7,2000,0.51,0.07261,29,
8,2000,0.54,0.07678,25,
9,2000,0.53,0.07148,47,
10,2000,0.51,0.06535,54,
11,2000,0.44,0.09065,36,
12,2000,0.48,0.04639,4,
), .Dim=c(5,59))))
colnames(testdata) <- c('month', 'year',
'mean','stdDev','miceCount')
testdata$month <- factor(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')
with(testdata, print(barchart(as.numeric(mean) ~ month | year, data=testdata,
layout=c(1,length(levels(year))),
horizontal=FALSE,
scales=list(y=list(limits=c(1,max(as.numeric(mean))+max(as.numeric(stdDev))))),
main='DEXA | M | Total Body | BMC - Level I',
xlab='Months',
ylab='Mean',
sd = as.numeric(as.character(stdDev)),
panel= function(x, y, ..., sd, subscripts) {
panel.barchart(x, y, ...);
sd <- sd[subscripts];
panel.segments(as.numeric(x), y - sd, as.numeric(x), y + sd, col =
'red', lwd = 2);
}
)))
I'm having a feeling that the as.numeric conversions is probably the cause
of the problem.
Please advise at your earliest convinience.
-Sandeep
-----Original Message-----
From: Ghosh, Sandeep
Sent: Friday, May 06, 2005 11:16 AM
To: Deepayan Sarkar
Cc: 'Sundar Dorai-Raj'
Subject: RE: [R] Re: Need some quick help with lattice - barchart
Want to add a little icing to the cake. Instead of showing the tick to be mnth
numbers I want them to be month labels. For this I declare an array
monthLabels <-
c('Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec').
I know how to do but not sure how to implement in R syntax. How do I get the
current row handle in barchart.. subscripts seems to give the current row index
but is only available in panel function. what I nee is function that return
function(index)(
for(testdata)
list <- monthLabels [testdata$month[index]]
)
As always any help is greatly appreciated.
-Sandeep
-----Original Message-----
From: Sundar Dorai-Raj [mailto:sundar.dorai-raj at pdf.com]
Sent: Thursday, May 05, 2005 3:09 PM
To: Ghosh, Sandeep
Cc: Deepayan Sarkar
Subject: Re: [R] Re: Need some quick help with lattice - barchart
Sorry. I copied your original script incorrectly. Changing to factor
does indeed work.
--sundar
Ghosh, Sandeep wrote on 5/5/2005 12:22 PM:> It worked for me..Here are the commands..
>
> library(lattice)
>
> testdata <- as.data.frame(t(structure(c(
> 1,2005,9.24,6.18,634,
> 2,2005,8.65,6.05,96,
> 8,2004,6.81,6.51,16,
> 9,2004,9.0,7.29,8,
> 10,2004,8.84,6.18,524,
> 11,2004,8.54,6.35,579,
> 12,2004,9.97,6.3,614,
> 12,2005,8.75,5.84,32,
> ), .Dim=c(5,8))))
> colnames(testdata) <- c('month', 'year',
'mean','stdDev','miceCount')
> testdata$month <- factor(testdata$month)
> testdata$year <- factor(testdata$year)
> testdata <- testdata[do.call("order", testdata), ]
>
> png('lexstar_3241.png', width=600,
height=as.numeric(length(levels(testdata$year))*200), pointsize=8)
> trellis.par.set(theme = col.whitebg())
>
> with(testdata, print(barchart(as.numeric(mean) ~ month | year,
data=testdata,
> layout=c(1,length(levels(year))),
> horizontal=FALSE,
>
scales=list(y=list(limits=c(1,max(as.numeric(mean))+max(as.numeric(stdDev))))),
> main='Marble Burying - Level I',
> xlab='Months',
> ylab='Mean',
> sd = as.numeric(as.character(stdDev)),
> panel= function(x, y, ..., sd, subscripts) {
> panel.barchart(x, y, ...);
> sd <- sd[subscripts];
> panel.segments(as.numeric(x), y - sd, as.numeric(x), y + sd, col =
'red', lwd = 2);
> }
> )))
>
> dev.off()
>
> Thanks a lot Deepayan..
>
> -Sandeep
>
> -----Original Message-----
> From: Sundar Dorai-Raj [mailto:sundar.dorai-raj at pdf.com]
> Sent: Thursday, May 05, 2005 2:05 PM
> To: Deepayan Sarkar
> Cc: Ghosh, Sandeep; r-help at stat.math.ethz.ch
> Subject: Re: [R] Re: Need some quick help with lattice - barchart
>
>
>
> Deepayan Sarkar wrote on 5/5/2005 12:03 PM:
>
>>On Thursday 05 May 2005 13:10, Ghosh, Sandeep wrote:
>>
>>
>>>For the following code below, the x-axis ticks are 1,2,3,4,5,6,7
when I was
>>>expection them to be 1,2,8,9,10,11,12. Please help me figure out
where is
>>>the mistake.
>>
>>[...]
>>
>>
>>>colnames(testdata) <- c('month', 'year',
'mean','stdDev','miceCount')
>>>testdata$month <- as.numeric(testdata$month)
>>
>>[...]
>>
>>
>>>with(testdata, print(barchart(as.numeric(mean) ~ month | year,
>>>data=testdata, layout=c(1,length(levels(year))),
>>> horizontal=FALSE,
>>
>>[...]
>>
>>'month' is numeric, so it's being coerced to be a shingle.
Try using
>>'factor(month)' instead in the formula.
>>
>>Deepayan
>>
>
>
> Hi Deepayan,
>
> That was my original thought too. But when I tried it I got:
>
> Error in unit(x0, default.units, units.per.obs) :
> 'x' must be numeric
>
> Changing horizontal to TRUE produces the plot, but I'm sure that's
not
> what Sandeep wants.
>
> --sundar
>
> ______________________________________________
> R-help at 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
I figured the problem.. the y limit scales need to start from 0 instead of 1.
-----Original Message-----
From: Ghosh, Sandeep
Sent: Monday, May 09, 2005 4:39 PM
To: 'Deepayan Sarkar'
Cc: 'r-help at stat.math.ethz.ch'
Subject: RE: [R] Re: Need some quick help with lattice - barchart
Hi Deepayan,
Thanks a lot for your last Friday response. I have yet not got a chance to
implement the month names for x -axis ticks yet, but will be on it as soon as
some of the bugs reported by users have been resolved. In regard to that one of
the users pointed out a problem with appeared to happen whenever the mean data
getting plotted is less than 1.
Here's the r code generated by my prog
library(lattice)
testdata <- as.data.frame(t(structure(c(
1,2005,0.53,0.05858,159,
2,2005,0.52,0.05413,143,
3,2005,0.49,0.04986,160,
4,2005,0.5,0.05679,166,
5,2005,0.5,0.05938,32,
1,2004,0.54,0.05774,94,
2,2004,0.56,0.05748,101,
3,2004,0.54,0.0571,101,
4,2004,0.56,0.07045,96,
5,2004,0.55,0.0584,92,
6,2004,0.55,0.06136,96,
7,2004,0.55,0.06219,119,
8,2004,0.55,0.06302,124,
9,2004,0.55,0.06094,127,
10,2004,0.54,0.06482,137,
11,2004,0.54,0.06485,142,
12,2004,0.53,0.05624,157,
1,2003,0.58,0.07141,152,
2,2003,0.57,0.06181,87,
3,2003,0.54,0.05462,116,
4,2003,0.53,0.06139,124,
5,2003,0.52,0.05209,110,
6,2003,0.52,0.0596,125,
7,2003,0.54,0.06634,138,
8,2003,0.52,0.05226,84,
9,2003,0.52,0.05892,128,
10,2003,0.51,0.06095,109,
11,2003,0.53,0.06355,87,
12,2003,0.55,0.0591,117,
1,2002,0.58,0.05102,59,
2,2002,0.56,0.06422,61,
3,2002,0.55,0.06219,64,
4,2002,0.56,0.06965,65,
5,2002,0.56,0.0557,87,
6,2002,0.57,0.06578,73,
7,2002,0.57,0.06617,85,
8,2002,0.58,0.06153,76,
9,2002,0.58,0.06301,107,
10,2002,0.59,0.0747,117,
11,2002,0.59,0.0737,92,
12,2002,0.59,0.06888,100,
1,2001,0.51,0.07221,28,
2,2001,0.48,0.06705,59,
3,2001,0.51,0.06753,71,
4,2001,0.52,0.0738,37,
5,2001,0.49,0.07891,92,
6,2001,0.48,0.06521,66,
7,2001,0.49,0.05509,53,
8,2001,0.53,0.07104,61,
9,2001,0.53,0.06878,45,
10,2001,0.54,0.06661,38,
11,2001,0.51,0.06486,52,
12,2001,0.56,0.05969,59,
7,2000,0.51,0.07261,29,
8,2000,0.54,0.07678,25,
9,2000,0.53,0.07148,47,
10,2000,0.51,0.06535,54,
11,2000,0.44,0.09065,36,
12,2000,0.48,0.04639,4,
), .Dim=c(5,59))))
colnames(testdata) <- c('month', 'year',
'mean','stdDev','miceCount')
testdata$month <- factor(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')
with(testdata, print(barchart(as.numeric(mean) ~ month | year, data=testdata,
layout=c(1,length(levels(year))),
horizontal=FALSE,
scales=list(y=list(limits=c(1,max(as.numeric(mean))+max(as.numeric(stdDev))))),
main='DEXA | M | Total Body | BMC - Level I',
xlab='Months',
ylab='Mean',
sd = as.numeric(as.character(stdDev)),
panel= function(x, y, ..., sd, subscripts) {
panel.barchart(x, y, ...);
sd <- sd[subscripts];
panel.segments(as.numeric(x), y - sd, as.numeric(x), y + sd, col =
'red', lwd = 2);
}
)))
I'm having a feeling that the as.numeric conversions is probably the cause
of the problem.
Please advise at your earliest convinience.
-Sandeep
-----Original Message-----
From: Ghosh, Sandeep
Sent: Friday, May 06, 2005 11:16 AM
To: Deepayan Sarkar
Cc: 'Sundar Dorai-Raj'
Subject: RE: [R] Re: Need some quick help with lattice - barchart
Want to add a little icing to the cake. Instead of showing the tick to be mnth
numbers I want them to be month labels. For this I declare an array
monthLabels <-
c('Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec').
I know how to do but not sure how to implement in R syntax. How do I get the
current row handle in barchart.. subscripts seems to give the current row index
but is only available in panel function. what I nee is function that return
function(index)(
for(testdata)
list <- monthLabels [testdata$month[index]]
)
As always any help is greatly appreciated.
-Sandeep
-----Original Message-----
From: Sundar Dorai-Raj [mailto:sundar.dorai-raj at pdf.com]
Sent: Thursday, May 05, 2005 3:09 PM
To: Ghosh, Sandeep
Cc: Deepayan Sarkar
Subject: Re: [R] Re: Need some quick help with lattice - barchart
Sorry. I copied your original script incorrectly. Changing to factor
does indeed work.
--sundar
Ghosh, Sandeep wrote on 5/5/2005 12:22 PM:> It worked for me..Here are the commands..
>
> library(lattice)
>
> testdata <- as.data.frame(t(structure(c(
> 1,2005,9.24,6.18,634,
> 2,2005,8.65,6.05,96,
> 8,2004,6.81,6.51,16,
> 9,2004,9.0,7.29,8,
> 10,2004,8.84,6.18,524,
> 11,2004,8.54,6.35,579,
> 12,2004,9.97,6.3,614,
> 12,2005,8.75,5.84,32,
> ), .Dim=c(5,8))))
> colnames(testdata) <- c('month', 'year',
'mean','stdDev','miceCount')
> testdata$month <- factor(testdata$month)
> testdata$year <- factor(testdata$year)
> testdata <- testdata[do.call("order", testdata), ]
>
> png('lexstar_3241.png', width=600,
height=as.numeric(length(levels(testdata$year))*200), pointsize=8)
> trellis.par.set(theme = col.whitebg())
>
> with(testdata, print(barchart(as.numeric(mean) ~ month | year,
data=testdata,
> layout=c(1,length(levels(year))),
> horizontal=FALSE,
>
scales=list(y=list(limits=c(1,max(as.numeric(mean))+max(as.numeric(stdDev))))),
> main='Marble Burying - Level I',
> xlab='Months',
> ylab='Mean',
> sd = as.numeric(as.character(stdDev)),
> panel= function(x, y, ..., sd, subscripts) {
> panel.barchart(x, y, ...);
> sd <- sd[subscripts];
> panel.segments(as.numeric(x), y - sd, as.numeric(x), y + sd, col =
'red', lwd = 2);
> }
> )))
>
> dev.off()
>
> Thanks a lot Deepayan..
>
> -Sandeep
>
> -----Original Message-----
> From: Sundar Dorai-Raj [mailto:sundar.dorai-raj at pdf.com]
> Sent: Thursday, May 05, 2005 2:05 PM
> To: Deepayan Sarkar
> Cc: Ghosh, Sandeep; r-help at stat.math.ethz.ch
> Subject: Re: [R] Re: Need some quick help with lattice - barchart
>
>
>
> Deepayan Sarkar wrote on 5/5/2005 12:03 PM:
>
>>On Thursday 05 May 2005 13:10, Ghosh, Sandeep wrote:
>>
>>
>>>For the following code below, the x-axis ticks are 1,2,3,4,5,6,7
when I was
>>>expection them to be 1,2,8,9,10,11,12. Please help me figure out
where is
>>>the mistake.
>>
>>[...]
>>
>>
>>>colnames(testdata) <- c('month', 'year',
'mean','stdDev','miceCount')
>>>testdata$month <- as.numeric(testdata$month)
>>
>>[...]
>>
>>
>>>with(testdata, print(barchart(as.numeric(mean) ~ month | year,
>>>data=testdata, layout=c(1,length(levels(year))),
>>> horizontal=FALSE,
>>
>>[...]
>>
>>'month' is numeric, so it's being coerced to be a shingle.
Try using
>>'factor(month)' instead in the formula.
>>
>>Deepayan
>>
>
>
> Hi Deepayan,
>
> That was my original thought too. But when I tried it I got:
>
> Error in unit(x0, default.units, units.per.obs) :
> 'x' must be numeric
>
> Changing horizontal to TRUE produces the plot, but I'm sure that's
not
> what Sandeep wants.
>
> --sundar
>
> ______________________________________________
> R-help at 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