用户名 Email 自动登录 找回密码 密码 立即注册

# 一页面放多张图

64主题 681积分   681 发表于 2017-7-23 12:27:57 | 显示全部楼层 |阅读模式
 试一试哦，后期会有这个R其中武器之ggplot的小结 [mw_shl_code=applescript,true]# 先产生三幅图 library(ggplot2) ( a <- qplot(date, unemploy, data = economics, geom = "line")) (b <- qplot(uempmed, unemploy, data = economics) + geom_smooth(se = F)) (c <- qplot(uempmed, unemploy, data = economics, geom="path")) library(grid) #  viewport 占据整个窗口 vp1 <- viewport(width = 1, height = 1, x = 0.5, y = 0.5) vp1 <- viewport() # 占半个窗, # located in the middle of the plot. vp2 <- viewport(width = 0.5, height = 0.5, x = 0.5, y = 0.5) vp2 <- viewport(width = 0.5, height = 0.5) # A viewport that is 2cm x 3cm located in the center vp3 <- viewport(width = unit(2, "cm"), height = unit(3, "cm")) #b和c放一张图，从加了坐标 pdf("polishing-subplot-1.pdf", width = 4, height = 4) #先给图片加属性 subvp <- viewport(width = 0.4, height = 0.4, x = 0.75, y = 0.35)#c的比例 b print(c, vp = subvp) dev.off() #b和c放一张图 csmall <- c + theme_gray(9) + labs(x = NULL, y = NULL) + theme(plot.margin = unit(rep(0, 4), "lines")) pdf("polishing-subplot-2.pdf", width = 4, height = 4) b print(csmall, vp = subvp) dev.off() #生成polishing-layout.pdf,三张图放在一张图 pdf("polishing-layout.pdf", width = 8, height = 6) grid.newpage() pushViewport(viewport(layout = grid.layout(2, 2))) #设置为2*2的图片格式 vplayout <- function(x, y)   viewport(layout.pos.row = x, layout.pos.col = y) print(a, vp = vplayout(1, 1:2))#第一行，1到2列 print(b, vp = vplayout(2, 1)) print(c, vp = vplayout(2, 2)) dev.off() [/mw_shl_code]

 您需要登录后才可以回帖 登录 | 立即注册 本版积分规则 回帖后跳转到最后一页 |手机版|小黑屋|生信技能树 ( 粤ICP备15016384号 GMT+8, 2020-2-20 02:18 , Processed in 0.019793 second(s), 25 queries .