[R] labels and barchart

Robert Ruser robert.ruser at gmail.com
Tue Dec 21 11:36:05 CET 2010

I'm wondering how to set a value of mar ( par( mar=c(.......)) ) in
order to allow labels to be visible in barplot. Is there any relation
between the number of characters in a label and the second value of
mar? Look at my example.

x <- seq(20, 100, by=15)
ety <- rep( "Effect on treatment group", times=length(x))
barplot(x, names.arg=ety, las=1, horiz=TRUE)

Labels are not visible. But trial and error method with the second mar
argument I get what I want.

par(mar=c(3,12,2,1), cex=0.8)
barplot(x, names.arg=ety, las=1, horiz=TRUE)

I would like something like that: second.mar = max( nchar(ety) )/2

Taking the opportunity I have 2 another question:
1. Space between labels and bars is too big - how to change it to the
value of 1 character?
2. In the example above the x axis is too short. How to make R draw a
line little longer then maximum bar length. I know that I could set
xlim=c(0,max(x)) but because of main increase equals 20 and the last
value 95 it doesn't solve the problem. The increase is ok. but only
line should be longer.

Thank you

More information about the R-help mailing list