我无法将存储在变量中的POSIXct作为geom_rect的xmin/xmax传递.我试图构建一个独立的例子而不是轻视我正在尝试做的事情......
我们的想法是采用ggplot2绘图对象,其x是POSIXt,并在特定范围内"放大".变焦位于前80%,整个系列位于底部20%,并指示顶部放大的部分.
我的问题是我似乎无法将xmin/xmax传递给geom_rect - 我尝试过的每件事(除了手工组装绘图而不是函数)都给了我一个不同的错误.我尝试使用aes(),aes_string(),作为参数而不是美学传递,只传递字符串等.
下面的例子告诉我:
Error in eval(expr, envir, enclos) : object 'lims' not found
Run Code Online (Sandbox Code Playgroud)
我认为我的问题是,当美学得到处理时,我用来设置美学的变量不在范围内,但我无法弄清楚如何去做.救命.
library(ggplot2)
subplot <- function(x, y) viewport(layout.pos.col=x, layout.pos.row=y)
vplayout <- function(x, y) {
grid.newpage()
pushViewport(viewport(layout=grid.layout(y,x)))
}
anm_zoom <- function(limits, p) {
lims <- as.POSIXct(limits)
limlab <- paste(lims, collapse=" to ")
top <- p + scale_x_datetime(limlab, limits=lims, expand=c(0,0))
bottom <- p;
bottom <- bottom + opts(title="")
bottom <- bottom + opts(legend.position="none")
bottom <- bottom + opts(axis.title.y=theme_blank())
bottom <- bottom + scale_x_datetime("", expand=c(0,0))
bottom <- bottom …Run Code Online (Sandbox Code Playgroud)