Hi

I think the following will help:

#Load some packages
library(lattice)
library(reshape)

#Sample data
dataset.frame
<- data.frame(id=c("a","b","c","a","c","b","a"),colour=c("blue","green","red","red","red","green","green"))

# calculate the counts
dataset.table <- table(dataset.frame)
#and reshape the table
dataset.melt <-
melt(dataset.table,measure.vars=levels(dataset.frame$colour), id.vars="id")
#now plot
barchart(colour~value|id,dataset.melt)
#for extra effect add some colours
barchart(colour~value|id,dataset.melt,col=levels(dataset.melt$colour))


Schalk


On Mon, Oct 12, 2009 at 2:52 AM, kaixin maleA <kaixinmalea@gmail.com> wrote:

> Dear all,
>
>
>
> I have a question about loading the data to barchart plot. I know this
> could
> be a very easy question, but I just can not get my head around.
>
>
>
> What I need to do is to create a trellis plots barchart style (horizontal
> bar), with levels of one variable (ie. variable “colour” in my example) as
> ylab and frequency as xlab on each trellis plot. The trellis plots is
> separated based on levels of another variable ie variable “id” in my
> example. .
>
>
>
> For example,
>
>
> library(lattice)
>
> dataset.frame <-
>
> data.frame(id=c("a","b","c","a","c","b","a"),colour=c("blue","green","red","red","red","green","green")))
>
> barchart(dataset.frame$colour|dataset.frame$id,stack=FALSE)
>
>
>
> *it comes error message like this:*
>
>
>
> Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
>
>  invalid 'times' value
>
> In addition: Warning message:
>
> In Ops.factor(dataset.frame$colour, dataset.frame$id) :
>
>  | not meaningful for factors
>
>
>
>
>
> *Then, I try to create a table rather than data frame. E.g.*
>
>
>
> dataset.table <-
>
> table(data.frame(id=c("a","b","c","a","c","b","a"),colour=c("blue","green","red","red","red","green","green")))
>
>
>
> barchart(dataset.table$colour|dataset.table$id,stack=FALSE)
>
>
>
> *it also comes with error message:*
>
> Error in dataset.table$colour | dataset.table$id :
>
>  operations are possible only for numeric or logical types
>
> In addition: Warning messages:
>
> 1: In dataset.table$colour :
>
>  $ operator is invalid for atomic vectors, returning NULL
>
> 2: In dataset.table$id :
>
>  $ operator is invalid for atomic vectors, returning NULL
>
>
>
> *I have no problem creating a single barchart but not trellis barchart.
> please guide me on this.*
>
> *
> *
>
> *Thanks a lot.*
>
>
> **
>
> *Rene
> *
>
>
>
> **
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>

	[[alternative HTML version deleted]]


