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
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 at r-project.org> On Behalf Of ani jaya
> Sent: Friday, January 7, 2022 8:25 AM
> To: r-help <r-help at 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 at 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.
Hi Ani,
Blame Mercator. Maps draws an approximately 2x1 plot. Maybe this:
mappar<-par("usr")
rect(mappar[1],mappar[3],mappar[2],mappar[4])
Jim
On Fri, Jan 7, 2022 at 6:25 PM ani jaya <gaaauul at gmail.com>
wrote:>
> 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 at 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.