Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有固定坐标的gtable rbind/cbind_R_Plot - Fatal编程技术网

具有固定坐标的gtable rbind/cbind

具有固定坐标的gtable rbind/cbind,r,plot,R,Plot,使用GTTable中的rbind/cbind,可以在多个grob对象之间保持打印宽度(或高度),但最好为某些grob保留固定的坐标。这对于将绘图与笛卡尔坐标和地理坐标相结合很方便。在我所看到的所有示例中,打印宽度(或高度)都保持正确,但固定坐标不正确,这取决于打印顺序 举个例子: library(ggplot2) library(gtable) states <- map_data('state') rands <- data.frame(x = rnorm(100), y = r

使用GTTable中的rbind/cbind,可以在多个grob对象之间保持打印宽度(或高度),但最好为某些grob保留固定的坐标。这对于将绘图与笛卡尔坐标和地理坐标相结合很方便。在我所看到的所有示例中,打印宽度(或高度)都保持正确,但固定坐标不正确,这取决于打印顺序

举个例子:

library(ggplot2)
library(gtable)

states <- map_data('state')
rands <- data.frame(x = rnorm(100), y = rnorm(100))

# first plot, coord fixed
p1 <- ggplot(states, aes(x=long, y=lat, group = group)) + 
  geom_polygon() + 
  coord_fixed()

# second plot, not fixed
p2 <- ggplot(rands, aes(x = x, y = y)) + 
  geom_point() 

# plot after combining with rbind
grid.draw(rbind(ggplotGrob(p1), ggplotGrob(p2), size = 'last'))

第二次放置地图将删除固定的坐标系。我在这里遗漏了什么吗?

我不知道这是否足够,但是网格。排列(p1,p2)允许您切换绘图,但大小不同。@MLavoie是的,这适用于纵横比,但我需要相同的宽度。
grid.draw(rbind(ggplotGrob(p2), ggplotGrob(p1), size = 'last'))