How do you do a bar chart of 2 vectors? I have one vector which has 10 numbers, and another which has 10 names. The numbers are the frequency of the corresponding name, but when I do a bar chart it says that there is no height. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Bar-Chart-tp3399924p3399924.html Sent from the R help mailing list archive at Nabble.com.
Hi, It's difficult to know what is going wrong from what you say below (please include some reproducible code in the future as indicated in the posting guide). If you want to produce a bar chart of the numbers with the corresponding names as labels for these numbers, you can do something like this: x <- rnorm(10) y <- letters[1:10] # use the first 10 letters of the alphabet as the labels barplot(x, names.arg = y) HTH, Francisco On Wed, Mar 23, 2011 at 4:26 PM, blutack <x-jess-h-x@hotmail.co.uk> wrote:> How do you do a bar chart of 2 vectors? > I have one vector which has 10 numbers, and another which has 10 names. > The numbers are the frequency of the corresponding name, but when I do a > bar > chart it says that there is no height. Thanks. > > -- > View this message in context: > http://r.789695.n4.nabble.com/Bar-Chart-tp3399924p3399924.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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]]
On Mar 23, 2011, at 12:26 PM, blutack wrote:> How do you do a bar chart of 2 vectors? > I have one vector which has 10 numbers, and another which has 10 > names. > The numbers are the frequency of the corresponding name, but when I doHow did you "do" a barchart? Code please.> a bar > chart it says that there is no height. Thanks.-- David Winsemius, MD West Hartford, CT
> How do you do a bar chart of 2 vectors? > I have one vector which has 10 numbers, and another which has 10 names. > The numbers are the frequency of the corresponding name, but when I do a bar > chart it says that there is no height. Thanks.The first thing we'd need to know is HOW you tried to create the bar chart. R usually offer quite a lot different ways to tackle a problem so knowing what exactly you did helps a lot in helping. That said, I'll assume you tried the barplot() command which would work e.g. like this: v1 <- 1:3 v2 <- c('A', 'B', 'B') barplot(v1, names.arg=v2) If v1 is a named vector things are even easier: names(v1) <- v2 barplot(v1) As I said, there are a bunch of other ways - e.g. using the lattice function barchart() which works a bit differently. cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/
On 03/24/2011 03:26 AM, blutack wrote:> How do you do a bar chart of 2 vectors? > I have one vector which has 10 numbers, and another which has 10 names. > The numbers are the frequency of the corresponding name, but when I do a bar > chart it says that there is no height. Thanks. >Hi blutack (any relation to Bluto?), My guess is that you want the frequencies as the heights of the bars and the names as the labels of the bars: heights<-sample(10:30,10) bar_names<-c("Oliver","Petroushka","Queequag","Rumplestiltskin", "Sinbad","Tycho","Uranus","Vesalius","Wojtec","Xavier") barplot(heights,names.arg=bar_names) Whoops! Lost some of the labels: library(plotrix) barp(heights,names.arg=bar_names,staxx=TRUE) Jim