All, I have a question regarding colors in bar plots. I want to stack a total of 18 cost values in each bar. Basically, it is six cost types and each cost type has three components- direct, indirect, and induced costs. I would like to use both solid color bars and bars with the slanted lines (using the density parameter). The colors would distinguish cost types and the lines would distinguish direct/indirect/induced. I want the cost types (i.e. colors) to be stacked together for each cost type. In other words, I don't want all of the solid bars at the bottom and all of the slanted lines at the top. So far, I have made a bar plot with all solid colors and then tried to overwrite that bar plot by calling barplot() again and putting the white slanted lines across the bars. However, I can't get this method to work while still grouping the cost types together. Thanks in advance for any help you can provide. David Winkel Applied Biology and Aerosol Technology Battelle Memorial Institute 505 King Ave. Columbus, Ohio 43201 614.424.3513 [[alternative HTML version deleted]]
> I have a question regarding colors in bar plots. I want to stack a > total of 18 cost values in each bar. Basically, it is six cost types and > each cost type has three components- direct, indirect, and induced > costs. I would like to use both solid color bars and bars with the > slanted lines (using the density parameter). The colors would > distinguish cost types and the lines would distinguish > direct/indirect/induced. I want the cost types (i.e. colors) to be > stacked together for each cost type. In other words, I don't want all > of the solid bars at the bottom and all of the slanted lines at the top.What are you trying to achieve with such a plot? A stacked bar chart only allows easy comparisons of cumulative totals (eg. cost 1, or cost 1 + 2, or cost 1 + 2 + 3) and it will be very difficult to compare individual cost types or components within a type. You might want to think about a series of line plots instead. Hadley -- http://had.co.nz/
Winkel, David wrote:> All, > > > > I have a question regarding colors in bar plots. I want to stack a > total of 18 cost values in each bar. Basically, it is six cost types and > each cost type has three components- direct, indirect, and induced > costs. I would like to use both solid color bars and bars with the > slanted lines (using the density parameter). The colors would > distinguish cost types and the lines would distinguish > direct/indirect/induced. I want the cost types (i.e. colors) to be > stacked together for each cost type. In other words, I don't want all > of the solid bars at the bottom and all of the slanted lines at the top. > > > So far, I have made a bar plot with all solid colors and then tried to > overwrite that bar plot by calling barplot() again and putting the white > slanted lines across the bars. However, I can't get this method to work > while still grouping the cost types together. > >Hi David, This is a real challenge: heights<-matrix(sample(10:70,54),ncol=3) bar.colors<-rep(rep(2:7,each=3),3) bar.densities<-rep(10,54) bar.angles<-matrix(rep(rep(c(45,90,135),6),3),ncol=3) barplot(heights,col=bar.colors) barplot(heights,angle=bar.angles,add=TRUE,density=bar.densities) Jim
I think you're going to find that barchart with that many values in a bar is going to be pretty well uninterpretable. Jim Lemon gives the desired barchart but it is very difficult to read. Stealing his code to create the same matrix I'd suggest may be looking at a dotchart. I'm not sure if this is even close to an optimal solution but I do think it's a bit better than a barchart approach =====================================================heights<-matrix(sample(10:70,54),ncol=3) bar.colors<-rep(rep(2:7,each=3),3) cost.types <- c("Direct", "Indirec", "Induced") colnames(heights) <- c("A", "B", "C") rownames(heights) <- c(rep(cost.types, 6)) dotchart(heights, col=bar.colors, pch=16, cex=.6) ======================================================--- "Winkel, David" <WinkelD at BATTELLE.ORG> wrote:> All, > > > > I have a question regarding colors in bar plots. I > want to stack a > total of 18 cost values in each bar. Basically, it > is six cost types and > each cost type has three components- direct, > indirect, and induced > costs. I would like to use both solid color bars > and bars with the > slanted lines (using the density parameter). The > colors would > distinguish cost types and the lines would > distinguish > direct/indirect/induced. I want the cost types > (i.e. colors) to be > stacked together for each cost type. In other > words, I don't want all > of the solid bars at the bottom and all of the > slanted lines at the top. > > > So far, I have made a bar plot with all solid colors > and then tried to > overwrite that bar plot by calling barplot() again > and putting the white > slanted lines across the bars. However, I can't get > this method to work > while still grouping the cost types together. > > > > Thanks in advance for any help you can provide. > > > > David Winkel > > Applied Biology and Aerosol Technology > > Battelle Memorial Institute > > 505 King Ave. > > Columbus, Ohio 43201 > > 614.424.3513 > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Reasonably Related Threads
- slanted ends of horizontal lines for certain line widths
- slanted stacked bar graphs?
- R and GNUPLOT
- Changing ComputerModern in postscript(...): A first attempt at contributing....
- file.c:655 ast_openstream_full: File /tmp/winkel-gesloten.alaw does not exist in any format