[R] Barplot Labels Problem

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Wed Nov 5 13:58:48 CET 2008


> 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 information intended
for the addressee(s) only. If this message was sent to you in error,
you must not disseminate, copy or take any action in reliance on it and
we request that you notify the sender immediately by return email.

Opinions expressed in this message and any attachments are not
necessarily those held by the Health and Safety Laboratory or any person
connected with the organisation, save those by whom the opinions were
expressed.

Please note that any messages sent or received by the Health and Safety
Laboratory email system may be monitored and stored in an information
retrieval system.
------------------------------------------------------------------------

------------------------------------------------------------------------
Scanned by MailMarshal - Marshal's comprehensive email content security
solution. Download a free evaluation of MailMarshal at www.marshal.com
------------------------------------------------------------------------


More information about the R-help mailing list