[R] TeachingDemos question: my.symbols() alignment problems in complicated layout
Greg Snow
Greg.Snow at imail.org
Mon Jul 21 19:05:36 CEST 2008
The original poster also contacted me offline and now has a copy of my.symbols that works with layout (instead of resetting all the graphical parameters, it only resets the ones it changes).
The fixed version will be in the next release of the package, or anyone who would like a copy before then can e-mail me.
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Paul Murrell
> Sent: Sunday, July 20, 2008 6:06 PM
> To: maria at meteo.mcgill.ca
> Cc: r-help at r-project.org
> Subject: Re: [R] TeachingDemos question: my.symbols()
> alignment problems in complicated layout
>
> Hi
>
>
> maria at meteo.mcgill.ca wrote:
> > Hello,
> >
> > After usefull suggestions by Paul Murrell, i have been
> trying to use
> > my.symbols to plot arrows of varying angles on my plot in order to
> > create a time series of wind direction... however,i have
> been unable
> > to figure out how the allignment of symbols works...
> >
> > below i have included a simplified code that illustrates my problem:
> > (i am creating a .ps file ... so i've included this in my
> mock code,
> > in case it might be part of the problem...)
> >
> > ############################# TEST CODE
> > #################################
> >
> > postscript("test.ps", horizontal=FALSE, width=7.5,
> > height=11.5,pointsize=10, paper = "special" )
> >
> > library(TeachingDemos)
> >
> > opar <- par(omi=c(0,0.1,0.7,0.1),xpd=T,mar=par()$mar+c(0,-1.5,-1,5))
> >
> > layout_mat = matrix(c(1,2,3,4),nrow=4,ncol=1,byrow=TRUE)
> >
> > my_layout <-
> >
> layout(layout_mat,widths=c(1,1,1,1),heights=c(1.0,0.45,1.0,1.2),respec
> > t=FALSE)
> >
> > plot(1,1)
> > plot(2,2)
> > plot(3,3)
> > plot(1:100,rep(c(9,1.5,2,8),25))
> > points(40,4,col="red")
> > points(50,8,col="red")
> > my.symbols(40,4,ms.polygon,n=3,inches=0.2,add=TRUE)
> > my.symbols(40,4,ms.arrows,angle=pi/2,inches=0.2,add=TRUE)
> > my.symbols(50,8,ms.arrows,angle=pi/4,inches=0.2,add=TRUE)
> > dev.off()
> >
> > ######################## END of TEST CODE
> > ###############################
> >
> > If i look at the output test.ps ... the first symbol is
> exactly where
> > i want it to be i.e. at x=40,y=4 ... while the position of the two
> > other ones is offset by some mysterious(!!) value
> >
> > then if i comment out the first my.symbols(...) command...
> the second
> > symbol is at the right place, while the third is offset ...etc
> >
> > However if i simply do:
> >
> > plot(1:100,rep(c(9,1.5,2,8),25))
> > points(40,4,col="red")
> > points(50,8,col="red")
> > my.symbols(40,4,ms.polygon,n=3,inches=0.2,add=TRUE)
> > my.symbols(40,4,ms.arrows,angle=pi/2,inches=0.2,add=TRUE)
> > my.symbols(50,8,ms.arrows,angle=pi/4,inches=0.2,add=TRUE
> >
> >
> > then everything is exactly where i want it ... suggesting
> there is a
> > problem with the layout ???
>
>
> I think the issue is that my.symbols() does a lot of this ...
>
> op <- par(no.readonly = TRUE)
> on.exit(par(op))
>
> ... which is not absolutely guaranteed to get you back to
> where you started (see the comment in the 'Value' section of
> the help page ?par).
> Fixing that will need the cooperation of the author of
> TeachingDemos.
>
> Here are a couple of options:
>
> (i) use the 'gridBase' package and do these arrow
> annotations using the 'grid' package, which allows you to
> control coordinate systems in a more rational manner.
> There's an example (perhaps slightly more complicated than
> you need) in:
> http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf
>
> (ii) draw your main plot using 'lattice' and the annotations
> using 'grid' or possibly 'grImport'. There's a hint of an
> example of the latter on slide 18 of:
> http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf
>
> (iii) draw the whole thing using 'grid'. You can start to
> get acquainted with grid here:
> http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter5.pdf
>
> Unfortunately, all of these require a reasonable amount of
> extra learning on your part.
>
> Paul
>
>
> > Any help would be really appreciated,
> > Thank You a lot,
> > maria
> >
> > ______________________________________________
> > R-help at 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.
>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> paul at stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list