[R] using barchart in lattice package and conditioning

Steven McKinney smckinney at bccrc.ca
Thu Jun 5 05:23:05 CEST 2008


Hi Mark,

I get output, after a while,
and reams of it.  Very likely
not what you wanted.

Can you describe what you are trying to
see in barcharts for these data?  It's
not obvious to me from the code below.

Best

Steve McKinney 



-----Original Message-----
From: r-help-bounces at r-project.org on behalf of markleeds at verizon.net
Sent: Wed 6/4/2008 5:26 PM
To: r-help at r-project.org
Subject: [R] using barchart in lattice package and conditioning
 
I have the data structure below and I'm attempting to send it into 
barchart using the R code below it. I don't get an error but I don't get 
any output either. Deepyan's new Lattice book is amazing and there are 
some examples sort of similar to what i'm doing  but I couldn't see a 
way of using the formula interface to condition on what I wanted to 
condition on so I decided to use split instead.  I'm not sure if that's 
where my problem lies but if anyone has experience in using the barchart 
function in the lattice package and could take a look at what I'm trying 
to do,
it would really be appreciated. thanks.

p.s: my data set is already tallied by proportion so i don't need to use 
prop.table and i also have other additional columns in my data set.
these two issues are complicating matters for me also. i'm a lattice 
newbie.

stocks.all<-structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "AVT.NYSE", class = 
"factor"),
     buckets = structure(c(8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L, 8L,
     6L, 4L, 2L, 1L, 3L, 5L, 7L, 8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L,
     8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L), .Label = c("[0,0.25", "[-0.25,0]",
     "[0.25,0.50]", "[-0.5,-0.25]", "[0.5,0.75]", "[-0.75,-0.50]",
     "[0.75,1.0]", "[-1.0,-0.75]"), class = "factor"), neutral = 
c(0.345901639344262,
     0.360117302052786, 0.354304635761589, 0.354319180087848,
     0.365524402907580, 0.359455958549223, 0.340284360189573,
     0.369763205828780, 0.265100671140940, 0.250599520383693,
     0.264124293785311, 0.257874015748031, 0.252083333333333,
     0.260869565217391, 0.263257575757576, 0.341911764705882,
     0.197761194029851, 0.192307692307692, 0.137724550898204,
     0.184647302904564, 0.176991150442478, 0.173796791443850,
     0.217573221757322, 0.181818181818182, 0.151162790697674,
     0.163865546218487, 0.167346938775510, 0.159638554216867,
     0.169934640522876, 0.133047210300429, 0.122093023255814,
     0.223529411764706), negative = c(0.304918032786885, 
0.304985337243402,
     0.310596026490066, 0.287457296242069, 0.285565939771547,
     0.264248704663212, 0.297630331753555, 0.231329690346084,
     0.345637583892617, 0.34652278177458, 0.353107344632768, 
0.319881889763780,
     0.341666666666667, 0.329923273657289, 0.348484848484849,
     0.301470588235294, 0.365671641791045, 0.384615384615385,
     0.38622754491018, 0.369294605809129, 0.371681415929204, 
0.382352941176471,
     0.338912133891213, 0.340909090909091, 0.406976744186047,
     0.399159663865546, 0.355102040816327, 0.355421686746988,
     0.398692810457516, 0.450643776824034, 0.337209302325581,
     0.282352941176471), positive = c(0.349180327868852, 
0.334897360703812,
     0.335099337748344, 0.358223523670083, 0.348909657320872,
     0.376295336787565, 0.362085308056872, 0.398907103825137,
     0.389261744966443, 0.402877697841727, 0.382768361581921,
     0.422244094488189, 0.40625, 0.40920716112532, 0.388257575757576,
     0.356617647058824, 0.436567164179104, 0.423076923076923,
     0.476047904191617, 0.446058091286307, 0.451327433628319,
     0.443850267379679, 0.443514644351464, 0.477272727272727,
     0.441860465116279, 0.436974789915966, 0.477551020408163,
     0.484939759036145, 0.431372549019608, 0.416309012875536,
     0.540697674418605, 0.494117647058824), wt = structure(c(1L,
     1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
     3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
     4L), .Label = c("5.0", "10.0", "20.0", "30.0"), class = "factor")), 
.Names = c("group",
"buckets", "neutral", "negative", "positive", "wt"), row.names = c(NA,
32L), class = "data.frame")



# R CODE FOR BARCHART
#============================================================

temp<-split(stocks.all,list(stocks.all$group,stocks.all$wt))
print(temp)

lapply(temp, function(.df){
print(barchart(.df, stack = TRUE,  auto.key = list(columns = 3)))
})

______________________________________________
R-help at 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.



More information about the R-help mailing list