I think it is because your command:
> coul <- array()
means that the first element of coul is NA, even after you've added the
colour names.
On 22/09/06, Octave Julien <ktawo@free.fr> wrote:>
> Dear wise ones,
>
> I have a problem assigning different colors to bars in a barplot.
> The data I'm using is the following dataframe (truncated) :
>
> > L0
> r n p t
> [...]
> 18 19 1 1 RFM
> 19 20 1 1 RFM
> 20 21 2 1 RFM
> 21 23 6 1 RIH
> 22 24 2 1 ROC
> 23 25 1 1 ROC
> 24 26 1 1 ROC
> 25 27 2 1 ROC
> 26 28 2 1 RFT
> 27 29 1 1 RFT
> 28 30 2 1 RFT
> 29 31 1 1 ROH
> [...]
>
> My barplot should display ascending bars according to L0$n. Their width
> depends on L0$p, which can be greater than 1. Last, I want a different
> color for each of the five values of L0$t.
> I use the following array to assign a colour for each type given in
> L0$t :
>
> > coul <- array()
> > coul['ROC'] <- 'khaki1'
> > coul['RFM'] <- 'palegreen'
> > coul['RFT'] <- 'lightorange'
> > coul['RIH'] <- 'blue'
> > coul['ROH'] <- 'lightblue'
>
> And here's the barplot command I'm using :
>
> > barplot(sort(L0$n), ylim=c(0,10), width=L0$p[order(L0$n)],
> col=coul[L0$t[order(L0$n)]], main="Nombre de genres",
sub="Livrets")
>
> The barplot uses the sort() and order() functions to display ascending
> bars with the right values. The width parameter works fine, but the
> color doesn't. I get :
>
> Erreur dans rect(y1, x1, y2, x2, ...) : nom de couleur incorrect
> (error in rect(y1, x1, y2, x2, ...) : incorrect color name)
>
> I tried to fiddle with coul[] or its indice but it didn't help.
> Does anybody know what's wrong ?
> Many thanks,
>
> Octave
>
> ______________________________________________
> R-help@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.
>
--
================================David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP
[[alternative HTML version deleted]]