df <- structure(list(ID = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L), .Label = c("1",
"2", "3", "4", "5", "6", "7"), class = "factor"), TYPE = structure(c(1L,
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L,
1L, 2L, 3L, 4L, 5L, 6L, 1L, …Run Code Online (Sandbox Code Playgroud) 可能重复:
左对齐两个图形边(ggplot)
我试图ggplot在同一页面上,顶部和底部放置两个图,以便它们的宽度相同.数据来自相同的时间序列,x轴是时间,因此重要的是具有相同时间的数据点不会相对于彼此水平移位.我尝试grid.arrange从包gridExtra:
grid.arrange(p1, p2)
Run Code Online (Sandbox Code Playgroud)
但由于y轴标签的宽度不同,图表的宽度不同.我查看了这篇涉及类似问题的帖子,但我无法应用这些信息来解决我的问题.

在R中,我准备了多个ggplot2数字,保存到这样的变量:
flashplot <- ggplot(flash, aes(x=flash$Year, y=flash$Proc))
+ stat_smooth(method="lm", formula = "flash$Proc ~ poly(flash$Year, 2, raw=TRUE)", n=14, level=0.9)
+ geom_point(shape=19) + ylab("Percentage of total existing versions")
+ xlab("Years of Existence") + scale_x_continuous(breaks = c(0,2,4,6,8,10,12,14,16,18,20))
Run Code Online (Sandbox Code Playgroud)
绘制单个图形按预期工作,但我想使用多色图绘制4个数字(2乘2),如R cookbook中所述.
当我收到错误时,我尝试了食谱中的例子,我应该会这样做,但它给了我同样的错误:
> multiplot(p1, p2, p3, p4, cols=2)
Error in UseMethod("getModelInfo", model) :
no applicable method for 'getModelInfo' applied to an object of class "c('gg', 'ggplot')"
Run Code Online (Sandbox Code Playgroud)
我,使用R 2.15.2在Windows 7下,和最新的软件包ggplot2和coefplot:
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit) …Run Code Online (Sandbox Code Playgroud)