On Apr 15, 2012, at 4:18 PM, Fino Fontana wrote:

Thanks David, for helping out. Works great. A question about your added lines of code:


with

 your are setting the margins, and you store them in opar
next,  par(opar) does nothing,

I disagree (and you offer no counter-examples, as would most experienced users of R I believe. Look at the first two examples on help(par). The warning applies to situations where you are building functions. I was just offering a solution that would work at the console.

Here's my counter-example to your claim.

> par("mar")
[1] 5.1 4.1 4.1 2.1
> opar <- par(mar=c(8,3,2,2))
> par("mar")
[1] 8 3 2 2
> str(opar)
List of 1
 $ mar: num [1:4] 5.1 4.1 4.1 2.1
> par(opar)
> par("mar")
[1] 5.1 4.1 4.1 2.1

par() like many graphics functions works via side-effects.

--
David.


I think because it just sets the same margins again.

shouldn't this be something like the following:

opar <- par( 'all graphics parameter') # store all current graphic parameters (in correct R language of course)
par(mar=c(8,3,2,2) # set new margins
barplot(...)
par(opar) # restore former graphics parameters.

Regards,
Fino


----- Original Message -----
From: David Winsemius <dwinsem...@comcast.net>
To: David Winsemius <dwinsem...@comcast.net>
Cc: Fino Fontana <finofont...@yahoo.com>; "r-help@r-project.org" <r-help@r-project.org >
Sent: Sunday, April 15, 2012 3:23 AM
Subject: Re: [R] (no subject)


On Apr 14, 2012, at 9:21 PM, David Winsemius wrote:


On Apr 14, 2012, at 8:11 PM, Fino Fontana wrote:

I am wrestling with the following in creating a barplot in R:
I have a data set with 18 entries. It is plotted in a bargraph. The x-axis should have 18 tick marks each with its own label. What happens is, only a few labels are shown; there is not enough space for all labels. The tick marks are concentrated on the left side of the axis.

The mar parameter to par() will give you control of the lower margin and the 'las' parameter will give you control of the axis label orientation:

barplot(times$duur, names.arg= times$taak, las=3, mar=c(8,3,2,2) )

Make that:

opar <- par(mar=c(8,3,2,2))
barplot(times$duur, names.arg= times$taak, las=3 )
par(opar)


I'd like to have all labels shown, in vertical direction.

This is part of the data:

times
        taak  duur
1   algemeen 48.75
2   swimming 14.25
3   football 24.25
4     tennis 36.75
5  bicycling  1.50

Under 'taak' are the labels.
This is the code that should do the job:

barplot(
width= bar_width,
times$duur,
names.arg=times$taak,
col=fill_colors,
border="NA",
space=0.3,
xlab="taak",
ylab="uren",
main="Uren per taak")

axis(1,at=1:length(times$taak),lab=times$taak)


Could anyone give me advise on how to get rid of this horrible x axis?

Thanks and r


David Winsemius, MD
West Hartford, CT

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to