I followed the first approach, which is very close to the solution proposed by
Marc Schwartz
yesterday.
Thanks a lot to both of you.
Héctor Villalobos
On 20 Jun 2007 at 12:08, Greg Snow wrote:
>
> There are 2 approaches that should work for you (actually there are
> probably more, but these 2 are what I would suggest).
>
> The first is to wrap barplot in your own function that also adjusts
> the parameters and adds the axis. The other is to use the output from
> subplot to go back and annotate the plots with the additional axis.
>
> Here is a quick example that shows both versions that you don't want
> (the top to barplots) and the 2 approaches I mention (the bottom 2).
>
> library(TeachingDemos)
> plot(0:10, 0:10, type='n')
> subplot( barplot(1:3, names=letters[1:3]), 2,8 )
> op <- par(mgp=c(3,0,0))
> subplot( barplot(1:3, names=letters[1:3]), 8,8 )
> par(op)
>
> tmp.bar <- function(...){
> op <- par(mgp=c(3,0,0))
> barplot(..., yaxt='n')
> par(op)
> axis(2)
> }
> subplot( tmp.bar(1:3, names=letters[1:3]), 8,2 )
> op <- par(no.readonly=TRUE)
> tmp <- subplot( barplot(1:3, names=letters[1:3], yaxt='n'),
> 2, 2, pars=list(mgp=c(3,0,0)))
> tmp$mgp = c(3,1,0)
> par(tmp)
> axis(2)
> par(op)
>
> Hope this helps (and that the pasted code is readable),
>
>
>
>
> From: [EMAIL PROTECTED] on behalf of Héctor Villalobos
> Sent: Tue 6/19/2007 2:31 PM To: [email protected] Subject: [R]
> axis labels in multiple plots Hi,
>
> I'am trying to make a multiple bar plot over a map and I'm having
> difficulties with the distance between axes labels and the axis.
> Trying to control this with mgp does not help because it controls both
> axes simultaneously. For example, with default values (mgp = c(3, 1,
> 0)) y-axis labels are ok, but x-axis labels are not. Setting mgp =
> c(3, 0, 0) gives good x-axis labels but the y-axis labels are over the
> axis. Since I'm using subplot() from TechingDemos package I don't know
> how to pass the mgp argument for every axis (like : axis(2, mgp = c(3,
> 1, 0)).
>
> I'm using R version 2.5.0 with Windows XP
>
>
> ##
> sim.data <- array(runif(420), dim = c(4, 5, 7, 3),
> dimnames = list(paste("var", 1:4, sep = ""), paste("year", 1:5, sep =
> ""), paste("lat", 1:7, sep = ""), paste("lon", 1:3, sep = "")) )
> x.pos <- c(3, 6, 9)
> y.pos <- c(1,2,3,4,5,6,7)
>
>
> ## This will be the map, its empty in this example
> plot(x = 1:10, y = 1:10, type = "n", xlim = c(1, 10), ylim = c(1,8) )
>
> ## And now the bar plots
> for (l in 7:1) {
> for (m in 1:3) {
>
> subplot(barplot(sim.data[, , l, m], las = 1, names.arg =
> paste("year", 1:5), mgp = c(3, 0, 0), cex.axis = 0.7, cex.names =
> 0.7,), x = x.pos[m], y = y.pos[l], size = c(1.3,0.5), vadj = 0 ) } }
>
>
> Any hints ?
>
> Héctor
>
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.