[R] barplot fill patterns
tpapp at axelero.hu
Mon Apr 19 06:43:17 CEST 2004
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 been
1. 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
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 looked
R 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 have
experiment with commands like
which disable clipping and extend the margin. Use the legend()
function after barplot, it lets you specify the coordinates.
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.
Tamás K. Papp
E-mail: tpapp at axelero.hu
Please try to send only (latin-2) plain text, not HTML or other garbage.
More information about the R-help