【发布时间】:2013-06-10 21:46:51
【问题描述】:
我想在 R 中的现有图上添加一个子图。子图(插图)应该有不同的背景颜色。我尝试了以下方法:
#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
)
)
在subplot() 的帮助下,它表示pars:
运行
fun之前要传递给par的参数列表。
更改绘图的背景颜色似乎非常困难,因为图形参数在plot() 中具有不同的含义。所以必须使用par() 设置背景颜色。但是为什么这不适用于subplot? (我还尝试将绘图函数放入调用par() 和plot() 的外部函数中,但这没有帮助)。
为什么子图不能正常工作?
【问题讨论】:
标签: r background plot subplot insets