Dear R-helpers,
I will like to know if there is a way to generate a stacked column
graph using both patterns and colors to fill the bars. I have many
categories for the number of color available in R, so I will like R to
start with solid colors and then use patterns an colors. I have been
using barplot and some code that I found in the archives, but I am
still having bars with the exact same color and patterns even though
they belong to different categories. How many different colors are
available in R?? I know it is a silly question but I have looked
everywhere and I can not find it. I have also tried to add the legend,
with the difficulty that overlaps with the plot. Does anybody know how
to adjust the size of the graph and the legend so they can fit in the
same page??? Below is how part of the data looks and the code I have
been using. Any suggestions are welcome
thanks
Hector
>barplot(t(Control.cfo.norm.mat),beside=F,space=.3,legend.text=colnames(
Control.cfo.norm.mat),col=(0:100),las=3,
density=rep(c(85,55,-1),5),angle=rep(c(45,90,180),5))
>Control.cfo.norm.mat
X36 X40 X58 X60 X62
X66
26Y 0.000000000 0.000000000 0.000000000 0.005409866 0.084265542
0.03218412
C-50 0.000000000 0.000000000 0.000000000 0.019747309 0.096583996
0.15919513
C-90 0.005584642 0.000000000 0.005671902 0.022687609 0.067102967
0.07643979
C-127-1 0.000000000 0.000000000 0.011776706 0.013816766 0.033753709
0.36999258
C-164 0.000000000 0.000000000 0.000000000 0.009163186 0.024120738
0.31976823
C-198 0.000000000 0.000000000 0.000000000 0.009708738 0.035671430
0.15904876
C-226 0.000000000 0.000000000 0.000000000 0.000000000 0.019187779
0.07991803
C-268 0.000000000 0.000000000 0.000000000 0.008017960 0.028864657
0.06724396
C-294-C 0.004623288 0.000000000 0.000000000 0.009589041 0.032448630
0.06446918
C-310 0.000000000 0.000000000 0.000000000 0.000000000 0.010871603
0.02858482
C-357-2 0.008525755 0.000000000 0.000000000 0.039520426 0.017850799
0.03596803
C-375 0.007081596 0.000000000 0.004406326 0.018176096 0.030293493
0.06428515
C-399 0.008050940 0.000000000 0.003659518 0.041206177 0.077581790
0.09104882
C-414 0.008423269 0.000000000 0.000000000 0.025927876 0.053698342
0.10858121
C-428 0.004066090 0.000000000 0.000000000 0.005163289 0.006454111
0.04485607
C-434 0.000000000 0.000000000 0.000000000 0.014529545 0.014097440
0.09122826
C-454 0.006096595 0.000000000 0.000000000 0.020348377 0.013460016
0.07624703
C-465 0.000000000 0.000000000 0.000000000 0.029669076 0.051477114
0.10904019
C-479 0.007429222 0.000000000 0.000000000 0.023358544 0.019878188
0.10293822
C-525 0.005839724 0.000000000 0.000000000 0.010835151 0.009990853
0.05832688
C-532 0.000000000 0.000000000 0.000000000 0.018876507 0.018876507
0.05390039
C-541 0.006378889 0.000000000 0.000000000 0.010660608 0.000000000
0.03416637
C-567 0.000000000 0.000000000 0.000000000 0.018852788 0.022763738
0.12996390
C-605 0.000000000 0.000000000 0.000000000 0.015993146 0.120234185
0.14065400
C-616 0.009669768 0.000000000 0.000000000 0.014960774 0.035668674
0.05893085
C-630-1 0.011308562 0.000000000 0.000000000 0.008885299 0.162493269
0.04671513
C-630-2 0.008951265 0.000000000 0.000000000 0.007514643 0.133384904
0.04099900
C-667 0.005172106 0.000000000 0.000000000 0.016229713 0.087836633
0.14071696
C-687 0.010054618 0.000000000 0.009309831 0.027681231 0.241559086
0.16335650
C-694 0.011289799 0.004304743 0.012264457 0.032163743 0.235298895
0.16902209
C-722 0.007263246 0.000000000 0.000000000 0.010429276 0.085203464
0.06453115
C-729 0.012428930 0.000000000 0.000000000 0.012693376 0.218960730
0.09956366
C-750 0.011836777 0.000000000 0.000000000 0.020558613 0.121378881
0.11535666
C-811 0.000000000 0.000000000 0.000000000 0.013054830 0.019938286
0.15475908
X77 X92 X95 X96 X107
X109
26Y 0.011736659 0.000000000 0.009536035 0.019622226 0.000000000
0.000000000
C-50 0.004679457 0.000000000 0.005053814 0.005240992 0.000000000
0.000000000
C-90 0.000000000 0.000000000 0.007591623 0.000000000 0.000000000
0.007940663
H??ctor L. Ayala-del-R??o, Ph.D.
Center for Microbial Ecology &
Center for Genomic and Evolutionary Studies
on Microbial Life at Low Temperatures
Michigan State University
545 Plant & Soil Sciences Building
East Lansing, MI 48824-1325
Phone: 517-353-9021
Fax: 517-353-2917
On Sun, Apr 18, 2004 at 11:28:09PM -0400, Hector L. Ayala-del-Rio wrote:> Dear R-helpers, > > I will like to know if there is a way to generate a stacked column > graph using both patterns and colors to fill the bars. I have many > categories for the number of color available in R, so I will like R to > start with solid colors and then use patterns an colors. I have been1. Density patterns: see the help of barplot (?barplot), density gives the number of lines per inch, angle gives the shading angle. Both can be vectors, and will be recycled. 2. Look at the package RColorBrewer, a package with predefined palettes of three types, each with colors that are easy to distinguish visually. Combining the above two will give you a lot of variation. Experiment.> they belong to different categories. How many different colors are > available in R?? I know it is a silly question but I have lookedR has a continous palette, so I would say it has 2^24 ~ 16 million colors on most devices. The question doesn't make sense, though: your eyes will only be able to distinguish a few shades in the spectrum.> everywhere and I can not find it. I have also tried to add the legend, > with the difficulty that overlaps with the plot. Does anybody know how > to adjust the size of the graph and the legend so they can fit in the > same page??? Below is how part of the data looks and the code I haveexperiment with commands like par(xpd=NA) par(mar=c(3.1,4.1,1.1,2.1)) which disable clipping and extend the margin. Use the legend() function after barplot, it lets you specify the coordinates.> >barplot(t(Control.cfo.norm.mat),beside=F,space=.3,legend.text=colnames( > Control.cfo.norm.mat),col=(0:100),las=3, > density=rep(c(85,55,-1),5),angle=rep(c(45,90,180),5))Everything makes sense except col=(0:100). Use either color names (eg "green") or hexadecimal colors (eg "#00FF00"), many functions can be used to generate the latter, eg heat.colors() and its friends, RColorBrewer, etc. Using rep(..., each=..., times=...) you can generate useful combinations of patterns/colors/angles. Best, Tamas -- Tam??s K. Papp E-mail: tpapp at axelero.hu Please try to send only (latin-2) plain text, not HTML or other garbage.