[R] unexpected (?) behavior of box()

ani jaya g@@@uu| @end|ng |rom gm@||@com
Fri Jan 7 10:04:29 CET 2022


Got it. Thank you very much.

On Fri, Jan 7, 2022 at 5:36 PM PIKAL Petr <petr.pikal using precheza.cz> wrote:
>
> Hi Ani
>
> No need to apologise. I may by wrong as I did not dig into the map code and do
> not use the package so I only guess. You could check how mar changes by
>
> > par("mar")
> [1] 5.1 4.1 4.1 2.1
>
> So
> par("mar")
> par(mar=c(2, 6, 5, 4))
> par("mar")
> m<-map('world', xlim = c(91, 142), ylim = c(25, 40), lwd=1.5, col =
> "grey",border=NA, fill = T,  bg="white")
> par("mar")
> box()
>
> should give you info how mar looks like before each step and which one is to
> blame.
>
> Jim gave you also some possible workaround.
>
> Cheers
> Petr
>
> > -----Original Message-----
> > From: ani jaya <gaaauul using gmail.com>
> > Sent: Friday, January 7, 2022 9:12 AM
> > To: PIKAL Petr <petr.pikal using precheza.cz>; r-help <r-help using r-project.org>
> > Subject: Re: [R] unexpected (?) behavior of box()
> >
> > Hi Petr,
> >
> > Thank you for pointing that out! Silly newbie here.
> > So, just want to make sure my mind,
> > using my example:
> >
> > par(mar=c(2, 6, 5, 4))
> > m<-map('world', xlim = c(91, 142), ylim = c(25, 40),
> >        lwd=1.5, col = "grey",border=NA, fill = T,  bg="white")
> > box()
> >
> > first, map use the first mar=c(2,6,5,4), and then defines the new mar that
> > is
> > mar=c(4.1, 4.1, par("mar")[3], 0.1)=c(4.1, 4.1, 5, 0.1).
> > And then box using the new mar=c(4.1, 4.1, 5, 0.1). Is that right?
> >
> > I am sorry if out of topic. Maybe further I will post at r-sig-geo. Thank
> > you.
> >
> > On Fri, Jan 7, 2022 at 4:39 PM PIKAL Petr <petr.pikal using precheza.cz> wrote:
> > >
> > > Hi.
> > >
> > > Why do you consider it unexpected?
> > >
> > > see
> > >
> > > map(database = "world", regions = ".", exact = FALSE, boundary = TRUE,
> > >   interior = TRUE, projection = "", parameters = NULL, orientation = NULL,
> > >   fill = FALSE, col = 1, plot = TRUE, add = FALSE, namesonly = FALSE,
> > >   xlim = NULL, ylim = NULL, wrap = FALSE, resolution = if (plot) 1 else 0,
> > >   type = "l", bg = par("bg"), mar = c(4.1, 4.1, par("mar")[3], 0.1),
> > >   myborder = 0.01, namefield="name", lforce="n", ...)
> > >
> > > map function redefines mar so your first par is probably changed
> > > during plotting map and after you define it again box use new mar values.
> > >
> > > Cheers
> > > Petr
> > >
> > > > -----Original Message-----
> > > > From: R-help <r-help-bounces using r-project.org> On Behalf Of ani jaya
> > > > Sent: Friday, January 7, 2022 8:25 AM
> > > > To: r-help <r-help using r-project.org>
> > > > Subject: [R] unexpected (?) behavior of box()
> > > >
> > > > Dear R expert,
> > > >
> > > > I try to box a figure using box(). However it box the default
> > > > margin, not the specified margin.
> > > >
> > > > #working as expected
> > > > barplot(1:20)
> > > > box()
> > > >
> > > > #working as expected, the box follow the margin par(mar=c(2, 6, 5,
> > > > 4))
> > > > barplot(1:20)
> > > > box()
> > > >
> > > > #not working
> > > > install.packages("maps")
> > > > library(maps)
> > > > par(mar=c(2, 6, 5, 4))
> > > > m<-map('world', xlim = c(91, 142), ylim = c(25, 40),
> > > >        lwd=1.5, col = "grey",border=NA, fill = T,  bg="white")
> > > > box()
> > > >
> > > > #the turnaround
> > > > par(mar=c(2, 6, 5, 4))
> > > > m<-map('world', xlim = c(91, 142), ylim = c(25, 40),
> > > >        lwd=1.5, col = "grey",border=NA, fill = T,  bg="white")
> > > > par(mar=c(2, 6, 5, 4))
> > > > box()
> > > >
> > > > I just curious with this behavior. Is it the problem with the
> > > > package "map" or box() function?
> > > > Thank you.
> > > >
> > > > > sessionInfo()
> > > > R version 4.0.2 (2020-06-22)
> > > > Platform: i386-w64-mingw32/i386 (32-bit) Running under: Windows 10
> > > > x64 (build 19043)
> > > >
> > > >
> > > >
> > > > Ani
> > > >
> > > > ______________________________________________
> > > > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > > 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