i am working with two sets of likert scale type (4 distinct values) data: dataA <- rep(1:4, c(3,2,2,4)) dataB <- rep(1:4, c(5,4,3,2)) i can now (bar)plot both of these separately and compare the distributions. plot(table(dataA), type='h') plot(table(dataB), type='h') is there a way to plot both of them in one plot, so that the bars for value "1" (dataA: 3, dataB: 5) would appear side by side, followed by the bars for value 2 etc.? thanks! best - P
Titus von der Malsburg
2009-Jun-09 14:39 UTC
[R] is it possible to combine multiple barplots?
You can use barchart in package lattice. Here's a rough sketch: library(lattice) dataA <- rep(1:4, c(3,2,2,4)) dataB <- rep(1:4, c(5,4,3,2)) da <- data.frame(table(dataA)) db <- data.frame(table(dataB)) da$cond <- "a" db$cond <- "b" colnames(da)[1] <- "data" colnames(db)[1] <- "data" d <- rbind(da, db) barchart(Freq~data|cond, d) Titus On Tue, Jun 09, 2009 at 04:23:32PM +0200, Philipp Schmidt wrote:> i am working with two sets of likert scale type (4 distinct values) data: > > dataA <- rep(1:4, c(3,2,2,4)) > dataB <- rep(1:4, c(5,4,3,2)) > > i can now (bar)plot both of these separately and compare the distributions. > > plot(table(dataA), type='h') > plot(table(dataB), type='h') > > is there a way to plot both of them in one plot, so that the bars for > value "1" (dataA: 3, dataB: 5) would appear side by side, followed by > the bars for value 2 etc.? > > thanks! > > best - P > > ______________________________________________ > 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.
philipp schmidt-3 wrote:> > i am working with two sets of likert scale type (4 distinct values) data: > > dataA <- rep(1:4, c(3,2,2,4)) > dataB <- rep(1:4, c(5,4,3,2)) > > i can now (bar)plot both of these separately and compare the > distributions. > > plot(table(dataA), type='h') > plot(table(dataB), type='h') > > is there a way to plot both of them in one plot, so that the bars for > value "1" (dataA: 3, dataB: 5) would appear side by side, followed by > the bars for value 2 etc.? > >barplot(rbind(table(dataA),table(dataB)),beside=TRUE) or see plotrix::multhist -- View this message in context: http://www.nabble.com/is-it-possible-to-combine-multiple-barplots--tp23943970p23966848.html Sent from the R help mailing list archive at Nabble.com.