[R] Barplot: Vertical bars with long labels

Udo ukoenig at med.uni-marburg.de
Wed Oct 29 20:06:46 CET 2008


Thanks a lot, Henrique and Christos!

It works fine....


Quoting Christos Hatzis <christos.hatzis at nuverabio.com>:

> Udo,
>
> You can try inserting a newline where you need the break in your labels:
>
> > dd.names <- c('Conduct Disorders','Attention Deficit', 'Eating Disorders',
> 'Substance Abuse','Developmental Disorders')
> > dd.names.2 <- sapply(dd.names, function(x) gsub("\\s", "\\\n", x))
> > barplot(dd, names.arg=dd.names.2)
>
> -Christos
>
> > -----Original Message-----
> > From: r-help-bounces at r-project.org
> > [mailto:r-help-bounces at r-project.org] On Behalf Of Udo
> > Sent: Wednesday, October 29, 2008 2:43 PM
> > To: r-help at r-project.org
> > Subject: [R] Barplot: Vertical bars with long labels
> >
> > Dear List,
> > I need a barplot with vertical bars. Each bar should have a label.
> > The problem is, that the labels are too long, so they
> > overlap, or only every seccond label is displayed in the output.
> >
> > Here is a little syntax:
> >
> > dd <- c(100,110,90,105,95)
> > barplot(dd,names.arg=c('Conduct Disorders','Attention Deficit',
> >                        'Eating Disorders',
> >                        'Substance Abuse','Developmental Disorders'))
> >
> > My question is, if there is a chance to force a line break in
> > each label.
> >
> > The result shoud look like this:
> >
> >   Bar1        Bar2       Bar3         Bar4         Bar5
> > Conduct    Attention    Eating     Substance   Developmental
> > Disorders  Disorders   Disorders     Abuse        Disorders
> >
> >
> >
> > The result could also look like this:
> >
> >       Bar1         Bar2       Bar3         Bar4         Bar5
> >        |            |          |            |             |
> > Conduct Disorders   |    Eating Disordes    |
> > Developmental Disordes
> >                     |                       |
> >              Attention deficit       Substance Abuse
> >
> >
> >
> >
> > Many thanks in advance
> > Udo
> >
> >
> >
> > --------------------------------------------
> > Udo K    N     G
> >       Ö     I
> >
> > Clinic for Child an Adolescent Psychiatry Philipps University
> > of Marburg / Germany
> >
> > ______________________________________________
> > R-help at r-project.org 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.
> >
> >
>
>
>



--------------------------------------------
Udo K    N     G
      Ö     I

Clinic for Child an Adolescent Psychiatry
Philipps University of Marburg / Germany



More information about the R-help mailing list