搜索
查看: 2440|回复: 0

一页面放多张图

[复制链接]

64

主题

138

帖子

681

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
681
发表于 2017-7-23 12:27:57 | 显示全部楼层 |阅读模式
试一试哦,后期会有这个R其中武器之ggplot的小结
[AppleScript] 纯文本查看 复制代码
# 先产生三幅图
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() 






上一篇:转录组入门(3):了解fastq测序数据
下一篇:转录组入门(2-3)下载数据及质量控制
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|生信技能树 ( 粤ICP备15016384号  

GMT+8, 2019-10-14 22:11 , Processed in 0.037623 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.