Liechi 这个包我装不上去,不知道为啥。
> devtools::install_github("thomasp85/patchwork")
Downloading GitHub repo thomasp85/patchwork@master
Error in poll(list(self), ms) :
LOGICAL() can only be applied to a 'logical', not a 'integer'
多图布局经常使用的 grid 包。于是我作了个弊,把图例挪了一下,就可以了:
xrange <- c(min(tb$date) - 1, max(tb$date) + 1)
p1 <- ggplot(tb, aes(date, q, color = type)) +
geom_line() +
scale_x_date(limits = xrange) +
theme(legend.justification = c(0, 1), legend.position = c(0,1), legend.background = element_rect(fill = FALSE))
p2 <- ggplot(tb, aes(date, p, fill = type)) +
geom_bar(stat = "identity", ) +
guides(fill=FALSE) +
scale_x_date(limits = xrange)
require(grid)
myvp <- viewport(layout = grid.layout(2, 1))
pushViewport(myvp)
print(p1, vp=viewport(layout.pos.row=1))
print(p2, vp=viewport(layout.pos.row=2))
``´