通过grid.arrange所生成的行的高度改变时nrow = 1(altering height

2019-08-31 18:46发布

道歉,如果这个问题已经回答了,但我不能似乎找到我所需要的。

我公司生产的GGPLOT2两个地块里面我是用grid.arrange如下组合到同一个网格:

grid.arrange(p1,p2,main="Title", ncol=2)

这给了我并排该地块一侧,像这样:

(对不起,我不知道如何得到这个帖子中展示自己的形象,如果有人可以帮助我,作为一个搁置,这将是伟大的!我不希望使用链接惹恼人。)

我怎样才能改变这种代码,使图形仍然并排,但他们不长的物体的整个长度? 我想他们是正方形。

我知道,我可以添加参数“高度”,但不知道这是我需要的,还没有看到在这种情况下将在这里任何东西。

谢谢!

Answer 1:

您也可以指定相对高度,并使用宽度heightswidths参数grid.arrange像这样:

grid.arrange(p1 , p2 , widths = unit(0.5, "npc") , heights=unit(0.5, "npc") , main="Title", ncol=2)



Answer 2:

当您使用GGPLOT2使地块,其中一个方法是使用coord_fixed()来获得二次曲线,然后安排他们。 可以用实现这种coord_fixed()其中ratio=除以的范围内算出y通过的范围内的值x的值。

ratio.plot1<-abs(max(iris$Petal.Width)-min(iris$Petal.Width))/abs(max(iris$Petal.Length)-min(iris$Petal.Length))

ratio.plot2<-abs(max(iris$Sepal.Width)-min(iris$Sepal.Width))/abs(max(iris$Sepal.Length)-min(iris$Sepal.Length))

p1<-ggplot(iris,aes(Petal.Width,Petal.Length))+geom_point()+
  coord_fixed(ratio=ratio.plot1)
p2<-ggplot(iris,aes(Sepal.Width,Sepal.Length))+geom_point()+
  coord_fixed(ratio=ratio.plot2)
grid.arrange(p1,p2,main="Title",ncol=2)



文章来源: altering height of rows produced by grid.arrange when nrow=1
标签: r ggplot2