[R] Barplot coloring question

Shravan Vasishth vasishth at coli.uni-sb.de
Fri Jul 26 17:26:40 CEST 2002


On Fri, 26 Jul 2002, Marc Schwartz wrote in response:

> Some of the output that you are seeing from data3 is the result of the
> way in which barplot() is handling the sorting of the data labels and
> the space arguments that you have specified (which are backwards), not
> because the data is being grouped.

Yes, I realize that the data is not being grouped. I was trying to hack
my way around a problem that I discuss below in connection with data3.

> For example, reconfigure data2 so that it looks like:
> 
> A B C
> 0 5 15 70 
> 1 10 20 90
> 
> Then call barplot() as follows:
> 
> barplot(data2, 
>             beside=TRUE, 
>             col=colorlist2, 
>             width = c(1,.55), 
>             space = c(.25, 2.75), 
>             axes = F)

Right, this works for data2, but not for data3. For example, suppose I
transform data3 to something like this:

    A  B  C 
g10  5  15 70
g20  20 24 34
g30  40 23 12
g11  10 20 90
g21  15 56 70
g31  24 67 78

              (originally it looked like this:

               A  A  B  B  C  C
            1  5  10 15 20 70 90
            2  20 15 24 56 34 70
            3  40 54 23 67 12 78

)


Now, with this transformed data3 if I do:

colorlist3 <- c("orange","lightblue","darkblue")

data3 <- as.matrix(read.table("test3.data"))

barplot(data5, 
            beside=TRUE, 
            col=colorlist3, 
            width = c(1,.55), 
            space = c(.25, 2.75), 
            axes = F)

I get *everything* as beside = TRUE. For any given category, I need the
first three and last three rows to be beside = FALSE, but these two sets
of rows to be beside = TRUE.

I hope this is making sense, it's that time of day for me now when things
no longer do.

Thanks for all your help,

> Date: Fri, 26 Jul 2002 09:41:56 -0500
> From: Marc Schwartz <mschwartz at medanalytics.com>
> To: 'Shravan Vasishth' <vasishth at CoLi.Uni-SB.DE>, r-help at stat.math.ethz.ch
> Subject: RE: [R] Barplot coloring question 
> 
> > On Thu, 25 Jul 2002, Marc Schwartz wrote in response:
> > 
> > > The "list" of colors that you have specified for colorlist contains
> only
> > > one entry.
> > >
> > > If you specify:
> > >
> > > colorlist <- c("red", "blue", ...)
> > >
> > > You bars or their stacked segments will cycle through the colors,
> > > depending upon whether beside is TRUE or FALSE, respectively.
> > >
> > > Just be sure to specify one color for each group in your data.
> > 
> > Right. I had tried that earlier but that alone didn't work; sorry, I
> > should have mentioned that.  But having beside as TRUE works (with a
> list
> > of colours). I wanted to keep beside = FALSE because I wanted to
> control
> > the space between bars, as I decribe below with toy examples.
> > 
> > In the first kind of barplot I want, I have data like this:
> > 
> >    A A  B  B  C  C
> > 0  5 10 15 20 70 90
> > 
> > I can plot it using code like this:
> > 
> > data2 <- as.matrix(read.table("test2.data"))
> > 
> > colorlist2 <- c("orange","limegreen")
> > 
> > barplot(data2,
> >         beside=TRUE,
> >         col=colorlist2,
> >         width = c(1,.55),
> >         space = c(2.75,.25),
> >         axes = F
> >         )
> > 
> > I want to be able to manipulate the spaces between the bars pairwise:
> the
> > contiguous AA should be closer to each other than the contiguous AB. I
> > thought that a vector specification for space would do this, because
> this
> > works for the plot of a slightly different dataset that I have
> (below).
> > But it doesn't in the above case.
> > 
> > Here's an example where "space" DOES work as (I) expected:
> > 
> > The data set:
> > 
> >    A  A  B  B  C  C
> > 1  5  10 15 20 70 90
> > 2  20 15 24 56 34 70
> > 3  40 54 23 67 12 78
> > 
> > The code:
> > 
> > data3 <- as.matrix(read.table("test3.data"))
> > 
> > colorlist3 <- c("orange","lightblue","darkblue")
> > 
> > barplot(data3,
> >         beside=FALSE,
> >         col=colorlist3,
> >         xlim = c(1,6),
> >         width = c(.5,.35),
> >         space = c(2.75,.25),
> >         axes = F
> >         )
> > 
> > As expected, "colorlist" in both examples cycles through the list of
> > colors, but when beside = TRUE it uses each color for each column in
> the
> > data, and when beside = FALSE the list of colors is cycled through for
> > each bar's components. In the *first* case, I'm trying to get the two
> > colors to alternate (which works only when beside = TRUE), but for
> some
> > reason I then lose control over "space".
> > 
> > Any suggestions would be greatly appreciated.
> 

-- 
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list