Hi, as a bloody R beginner I failed to solve the probably simple problem to create a barplot of the following data read from a file Year A B C 2000 4 3 0 2001 2 1 3 2002 1 2 5 The Barplot should look like 5 | C 4 | A C 3 | AB C C 2 | AB A C BC 1 | AB ABC ABC +------------------ 2000 2001 2002 (well, something like that - the colors are encoded as letters in this ASCII-graphics - assume the coloring / shading as usual). My problem is that if I read the table using data <- read.table(file='data.dat', sep = '\t', fill=TRUE, header=TRUE ) everything looks is read as expected if I try data but I have no idea how to separate the Matrix (A B C) to specify the height parameter of barplot as a matrix and the names.arg parameter for the inscription. Whatever I tried I get 'height' must be a vector or a matrix and I have no idea to do this right. So I think I'm just facing a data conversion problem and have to turn data[['Year']] into a vector and the remaining table into a matrix. I guess this is a really simple question - but I failed to find a solution. Kind regards Andreas. -- http://fam-tille.de
> data <- data.frame(Year=c(2000,2001,2002),A=c(4,2,1), B=c(3,1,2), C=c(0,3,5))> data.mat <- as.matrix(data)[,2:4] > rownames(data.mat) <- data$Year > data.mat <- t(data.mat) > barplot(data.mat,beside=TRUE)-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Andreas Tille Sent: Friday, July 25, 2008 8:14 AM To: r-help at r-project.org Subject: [R] Matrix barplot Hi, as a bloody R beginner I failed to solve the probably simple problem to create a barplot of the following data read from a file Year A B C 2000 4 3 0 2001 2 1 3 2002 1 2 5 The Barplot should look like 5 | C 4 | A C 3 | AB C C 2 | AB A C BC 1 | AB ABC ABC +------------------ 2000 2001 2002 (well, something like that - the colors are encoded as letters in this ASCII-graphics - assume the coloring / shading as usual). My problem is that if I read the table using data <- read.table(file='data.dat', sep = '\t', fill=TRUE, header=TRUE ) everything looks is read as expected if I try data but I have no idea how to separate the Matrix (A B C) to specify the height parameter of barplot as a matrix and the names.arg parameter for the inscription. Whatever I tried I get 'height' must be a vector or a matrix and I have no idea to do this right. So I think I'm just facing a data conversion problem and have to turn data[['Year']] into a vector and the remaining table into a matrix. I guess this is a really simple question - but I failed to find a solution. Kind regards Andreas. -- http://fam-tille.de ______________________________________________ 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. P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S. News & World Report (2007). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}}
On Fri, 2008-07-25 at 14:13 +0200, Andreas Tille wrote:> Hi, > > as a bloody R beginner I failed to solve the probably simple problem > to create a barplot of the following data read from a file > > Year A B C > 2000 4 3 0 > 2001 2 1 3 > 2002 1 2 5 > > The Barplot should look like > > 5 | C > 4 | A C > 3 | AB C C > 2 | AB A C BC > 1 | AB ABC ABC > +------------------ > 2000 2001 2002 > > (well, something like that - the colors are encoded as letters in this > ASCII-graphics - assume the coloring / shading as usual). >Hi Andreas, Try this (assume your data frame is named "atdat"): library(plotrix) # barp groups data in columns, not rows, so transpose barp(t(atdat[,2:4]),names.arg=atdat[,1],col=2:4) Jim
On Fri, 25 Jul 2008, Nutter, Benjamin wrote:>> data <- data.frame(Year=c(2000,2001,2002), > A=c(4,2,1), > B=c(3,1,2), > C=c(0,3,5)) > >> data.mat <- as.matrix(data)[,2:4] >> rownames(data.mat) <- data$Year >> data.mat <- t(data.mat) >> barplot(data.mat,beside=TRUE)Thanks a lot Andreas. -- http://fam-tille.de
As a beginner also try downloading the rattle GUI , with all dependecies =true , or R Cmdr GUI.. these are both packages go to rattle.togaware.com for the rattle instructions and installations .its very very user friendly even though the purists think its infra dig.(kidding- Friday humour) Regards, Ajay Ohri www.decisionstats.com On Fri, Jul 25, 2008 at 5:43 PM, Andreas Tille <tillea@rki.de> wrote:> Hi, > > as a bloody R beginner I failed to solve the probably simple problem > to create a barplot of the following data read from a file > > Year A B C > 2000 4 3 0 > 2001 2 1 3 > 2002 1 2 5 > > The Barplot should look like > > 5 | C > 4 | A C > 3 | AB C C > 2 | AB A C BC > 1 | AB ABC ABC > +------------------ > 2000 2001 2002 > > (well, something like that - the colors are encoded as letters in this > ASCII-graphics - assume the coloring / shading as usual). > > My problem is that if I read the table using > > data <- read.table(file='data.dat', sep = '\t', fill=TRUE, header=TRUE ) > > everything looks is read as expected if I try > > data > > but I have no idea how to separate the Matrix (A B C) to specify the > height parameter of barplot as a matrix and the names.arg parameter > for the inscription. Whatever I tried I get > > 'height' must be a vector or a matrix > > and I have no idea to do this right. So I think I'm just facing a > data conversion problem and have to turn data[['Year']] into a vector > and the remaining table into a matrix. > > I guess this is a really simple question - but I failed to find a > solution. > > Kind regards > > Andreas. > > -- > http://fam-tille.de > > ______________________________________________ > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]