[R] RES: Barplot Labels Problem

Rodrigo Aluizio r.aluizio at gmail.com
Wed Nov 5 14:59:05 CET 2008


Sorry for don't make the data available. My bad.
But anyway the Richard's fourth solution works quite well.

Thank you very much!

Rodrigo.

-----Mensagem original-----
De: Richard.Cotton em hsl.gov.uk [mailto:Richard.Cotton em hsl.gov.uk] 
Enviada em: quarta-feira, 5 de novembro de 2008 10:59
Para: Rodrigo Aluizio
Cc: r-help em r-project.org; r-help-bounces em r-project.org
Assunto: Re: [R] Barplot Labels Problem

> I’m using barplot function. I pretend to create a horizontal barplot 
with
> two different information (side by side) for a species list. Well I can
> generate the graph easily, but the problem is that the labels with the
> species names are cut by device window!! I’ve tried lots of par 
functions
> none seems to work properly.
> 
> Below are the script.
> 
> 
> 
> Height is a matrix of species and two column of numerical data. I used
> par(las=) function to make the labels horizontal. When I do this they 
are
> cut by the device window. If I don’t do that the label stay vertical and
> make nonsense with the graph.
> 
> 
> 
> library(xlsReadWrite)
> 
> Spp<-read.xls('SppPrincipaisFVeFT.xls',sheet=1,rowNames=T)
> 
> Spp<-as.matrix(Spp)
> 
> 
barplot(t(Spp),axis.lty='solid',horiz=T,beside=T,las=1,col=c('lightgray','bl
> ack'),main='Main Speceis')
> 
> legend('topright',c('Living Fauna','Dead
> Fauna'),fill=c('lightgray','black'),bty='n')

I can't recreate your code, since you haven't made the file 
SppPrincipaisFVeFT.xls available.  I guess it's something like this:

x = c(monkey=25, giraffe=13, rhinocerous=46, squirrel=5, "sting ray"=36, 
cheetah=2, penguin=69, chicken=43)
par(las=1)
barplot(x)

On my machine, not all the animal names are shown when the device window 
opens.  You have several options to solve this.

1. Make the device bigger.  Either drag the corner of the window or, if 
you are writing directly to a file, try something like:
png("animal barplot.png", width=1200, height=800)
par(las=1)
barplot(x)
dev.off()

2. Make the axis text smaller, e.g.
barplot(x, cex.names=0.5)

3. Abbreviate the names, e.g.
barplot(x, names.arg=abbreviate(names(x)))

4. You can also get a little extra room by decreasing the plot margins and 
the amount of space between bars, e.g.
par(las=1, mar=c(2.5,3,0.5, 0.3))
barplot(x, space=0.05)

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list