Deb,
Others have answered your question, I just want to give you something
else to think about.
Stacked bar plots may not be the best tool to use for this situation,
they are ok for comparing the bottom and top groups, but all the other
groups don't line up in a stacked bar plot making those comparisons
harder. The fact that you want 15 different colors means that this is
even more likely the case. You also need to be careful that your colors
are different enough from each other that they can be easily
distinguished (even when a bar or 2 between them is so small as to not
appear).
You may want to consider dotplots as an alternative, you can use symbols
(possibly numbers or initial letters) in place of or along with the
colors. You can also format the dotplot so that the most interesting
comparisons are the easiest to make. See the dotplot function in the
lattice package and the dotchart2 function in the Hmisc package.
If you send us more detail on what you are trying to show (maybe even
some simulated data in the same form as your real data), then we can
give additional suggestions on how to display the data.
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Deb Midya
> Sent: Tuesday, August 21, 2007 5:29 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Stacked Bar
>
> Hi R Users!
>
> Thanks in advance.
>
> I am using R-2.5.1 on Windows XP.
>
> I am trying to do a stacked bar plot, but could not get
> through the following problem. The code is given below.
>
> 1. How can I provide 15 different colors for each method
> with 15 Rows?
>
> 2. How can I put the legend in a particular position (eg.,
> in the top or bottom or right or left)? How can I put legend
> using a number of rows (eg., using two or three rows)?
>
> Once again thank you very much for your time.
>
> Regards,
>
> Debabrata (Deb)
> Statistician
> NSW Department of CommerceSydney, Australia.
>
> The Code:
>
> library(lattice)
> library(graphics)
>
> x <- matrix(1:75, ncol= 5)
> dimnames(x)[[2]] <- paste("Method", 1:5, sep="")
> dimnames(x)[[1]] <- paste("Row", 1:15, sep="")
>
> # library: graphics
>
> barplot(x,
> beside=FALSE,
> col= 1:nrow(x),
> legend= rownames(x)
> )
>
> # library: lattice
>
> barchart(Freq ~ Var2,
> data = as.data.frame.table(x),
> groups = Var1, stack = TRUE,
> auto.key = TRUE)
>
>
>
> ---------------------------------
> Park yourself in front of a world of choices in alternative vehicles.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>