[R] Barplot coloring question

Shravan Vasishth vasishth at coli.uni-sb.de
Thu Jul 25 18:35:41 CEST 2002

```Hi all,

I have the following dataset, call it test.data (30 columns, and one row
named "0"):

ADVP  ADVP AP    AP   CONJ  CONJ CP    CP   DU    DU    INF   INF  MWU
MWU  NP    NP    PP    PP    PPRT PPRT REL   REL  SMN SMN SSB  SSB SV1
SV1 TI    TI
0 96.85 2.05 89.07 2.54 70.91 2.37 94.92 3.46 82.31 11.33 40.96 2.25 98.06
3.43 90.77 17.63 86.60 10.78 60.27 1.32  93.27 0.97 77.60 12.46 64.98 3.32
88.54 3.70 24.33 0.28

I'm trying to plot these data points so that any pair of identical columns
(e.g., ADVP) are plotted closer to each other than any neighbouring pairs.

This much is easy to do:

colorlist <- c("red")

# build basic barplot:

barplot(data,
beside=FALSE,     # don't put bars beside each other
col=colorlist,    # list of colors
xlim = c(1,40),   # x-axis limits
width = .65,      # width of bar plots
ylim=c(0, 140),   # y-axis limits
space = c(1,.5),  # space between bars, and between bar-pairs
axes = F          # don't plot y-axis yet
)

This gives a graph with the same color for each bar.

The problem is that I want the first instance of a pair of identical
columns to have a certain colour, and the other one a different one. So,
the bars should really have an alternating pattern like red green red
green... and so on, not just one colour.

For the above dataset I could set beside=TRUE and transform the dataset to
two rows and 15 columns rather than the current 1x30, so something like:

0a 96.85
0b  2.05

but I will eventually need to plot a matrix like

1 30   40
2 20   20
3 10   5

and there I will want beside=FALSE because I want the 1, 2, 3 rows to
appear *within* a bar, but I still want pairs of bars for ADVP.

This is why I don't want to set beside=FALSE.

I'll be very grateful for any suggestions.

Many thanks,

--
Dr. Shravan Vasishth                           Phone: +49 (681) 302 4504
Computational Linguistics, Universität des Saarlandes, Postfach 15 11 50
D-66041 Saarbrücken, Germany         http://www.coli.uni-sb.de/~vasishth

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```