I'd like to add a subplot to an existing plot in R. The subplot (inset) should have a different background color. I tried the following:
#install.packages("TeachingDemos", dependencies=T)
library(package="TeachingDemos")
d0 <- data.frame(x = rnorm(150, sd=5), y = rnorm(150, sd=5))
d0_inset <- data.frame(x = rnorm(1500, sd=5), y = rnorm(1500, sd=5))
plot(d0)
subplot(
fun = plot(
d0_inset
, col = 2
, pch = '.'
, mgp = c(1,0.4,0)
, ann = F
, cex.axis=0.5
)
, x = grconvertX(c(0.75,1), from='npc')
, y = grconvertY(c(0,0.25), from='npc')
, type = 'fig'
, pars = list(
mar = c(1.5,1.5,0,0) + 0.1
, bg = "blue" # this should change the background color
)
)
In the help of subplot()
it says for pars
:
a list of parameters to be passed to par before running
fun
.
It seems to be very difficult to change the backgroundcolor of a plot, since the graphic parameter has a different meaning in plot()
. So one has to set the background color using par()
. but why does this not work for subplot
? (I also tried to put the plot-function into a extaernal function that calls par()
and plot()
, but this did not help).
Why does subplot not work properly?