Hi, basically I am trying to create a grouped bar graph with each group a different color and a bar in each group to have shading lines. Basically combine the 2 graphs created below. Thanks, Josh data(HairEyeColor) a <- as.table( apply(HairEyeColor, c(1,2), sum) ) a1<-a[1:2,] par(mfcol=c(1,2), bg="white") barplot(a1, type="n", col=c(2,2,4,4,6,6,3,3), beside = TRUE, ) barplot(a1, col=1, density=c(0,7,0,7,0,7,0,7), beside = TRUE, ) http://www.nabble.com/file/p18033630/graph.JPG graph.JPG -- View this message in context: http://www.nabble.com/Combine-colors-and-shading-lines-tp18033630p18033630.html Sent from the R help mailing list archive at Nabble.com.
Josh, Check into "add=TRUE" :-) All you need to do is insert "add=TRUE" to the second chart to superimpose it on the first chart. You might also consider making the second bar a different shade of color rather than using shadding lines, then it would only be one plot. data(HairEyeColor) a <- as.table( apply(HairEyeColor, c(1,2), sum) ) a1<-a[1:2,] barplot(a1, type="n", col=c("red","red","blue","blue","purple","purple","green","green"), beside = TRUE ) barplot(a1, col=1, density=c(0,7,0,7,0,7,0,7), beside = TRUE, add=TRUE ) Josh Roofchop wrote:> > Hi, basically I am trying to create a grouped bar graph with each group a > different color and a bar in each group to have shading lines. Basically > combine the 2 graphs created below. > Thanks, > Josh > > data(HairEyeColor) > a <- as.table( apply(HairEyeColor, c(1,2), sum) ) > a1<-a[1:2,] > > par(mfcol=c(1,2), bg="white") > > barplot(a1, > type="n", > col=c(2,2,4,4,6,6,3,3), > beside = TRUE, ) > > barplot(a1, > col=1, > density=c(0,7,0,7,0,7,0,7), > beside = TRUE, ) > > http://www.nabble.com/file/p18033630/graph.JPG graph.JPG >-- View this message in context: http://www.nabble.com/Combine-colors-and-shading-lines-tp18033630p18035111.html Sent from the R help mailing list archive at Nabble.com.
I tried the "add=TRUE" but get "Warning messages: 1: parameter "add" could not be set in high-level plot() function" Josh HBaize wrote:> > > Josh, > Check into "add=TRUE" :-) > > All you need to do is insert "add=TRUE" to the second > chart to superimpose it on the first chart. You might also > consider making the second bar a different shade of color > rather than using shadding lines, then it would only be one > plot. > > data(HairEyeColor) > a <- as.table( apply(HairEyeColor, c(1,2), sum) ) > a1<-a[1:2,] > > barplot(a1, > type="n", > > col=c("red","red","blue","blue","purple","purple","green","green"), > beside = TRUE ) > > barplot(a1, > col=1, > density=c(0,7,0,7,0,7,0,7), > beside = TRUE, add=TRUE ) > > > > Josh Roofchop wrote: >> >> Hi, basically I am trying to create a grouped bar graph with each group a >> different color and a bar in each group to have shading lines. Basically >> combine the 2 graphs created below. >> Thanks, >> Josh >> >> data(HairEyeColor) >> a <- as.table( apply(HairEyeColor, c(1,2), sum) ) >> a1<-a[1:2,] >> >> par(mfcol=c(1,2), bg="white") >> >> barplot(a1, >> type="n", >> col=c(2,2,4,4,6,6,3,3), >> beside = TRUE, ) >> >> barplot(a1, >> col=1, >> density=c(0,7,0,7,0,7,0,7), >> beside = TRUE, ) >> >> http://www.nabble.com/file/p18033630/graph.JPG graph.JPG >> > >-- View this message in context: http://www.nabble.com/Combine-colors-and-shading-lines-tp18033630p18036266.html Sent from the R help mailing list archive at Nabble.com.
You can play around with something like this to control the plots and to add color to them: data(HairEyeColor) a <- as.table( apply(HairEyeColor, c(1,2), sum) ) a1<-a[1:2,] library(lattice) library(reshape) x <- melt(a1) p1 <- barchart(value ~ Eye, group=Hair, data=x) p2 <- barchart(value ~ Hair, group=Eye, data=x) print(p1, split=c(1,1,1,2), more=TRUE) print(p2, split=c(1,2,1,2)) On Fri, Jun 20, 2008 at 12:55 PM, Josh Roofchop <josh at roofchop.com> wrote:> > Hi, basically I am trying to create a grouped bar graph with each group a > different color and a bar in each group to have shading lines. Basically > combine the 2 graphs created below. > Thanks, > Josh > > data(HairEyeColor) > a <- as.table( apply(HairEyeColor, c(1,2), sum) ) > a1<-a[1:2,] > > par(mfcol=c(1,2), bg="white") > > barplot(a1, > type="n", > col=c(2,2,4,4,6,6,3,3), > beside = TRUE, ) > > barplot(a1, > col=1, > density=c(0,7,0,7,0,7,0,7), > beside = TRUE, ) > > http://www.nabble.com/file/p18033630/graph.JPG graph.JPG > -- > View this message in context: http://www.nabble.com/Combine-colors-and-shading-lines-tp18033630p18033630.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?