我结合了两个情节。arrangeGrob()压缩它们,使新图像的大小与单独的图像相同。如何在保留比例/尺寸的同时排列它们?
require(ggplot2)
require(gridExtra)
dat <- read.csv("http://www.ats.ucla.edu/stat/data/fish.csv")
frqncy <- as.data.table(table(dat$child))#
frqncy$V1 <- as.numeric(frqncy$V1)
plot1 <- ggplot(frqncy, aes(x=V1, y= N)) +
geom_histogram(stat="identity", binwidth = 2.5)
plot2 <- ggplot(frqncy, aes(x=V1, y= N)) +
geom_density(stat="identity")
plot <- arrangeGrob(plot1, plot2)
Run Code Online (Sandbox Code Playgroud)
Plot 看起来像

我没有发现任何参数ggplot()或arrangeGrob()固定输入比率的参数。
编辑:额外的复杂性源于中的轴标签的定义arrangeGrob(),即
plot <- arrangeGrob(plot1, plot2, left="LHS label")
Run Code Online (Sandbox Code Playgroud)
然后,新的文件不会automaticall收缩到的最小高度/宽度组合plot1和plot2。