【发布时间】:2012-05-01 11:49:38
【问题描述】:
这是我的数据和绘图
nmar <- seq (1, 100, 5)
position= rep(nmar, 5)
n = length (nmar )
chr = rep(1:5, each = n )
mapdata <- data.frame (chr, position,
snpname = paste("SNP-", 1:length (position), sep = ""))
mapdata
chr.lab = 1 ; mbar.col = "blue"
layout(matrix(c(1,1,2),nc=1)) # works for two but I need to extend it to
n (which is level of chr = 5)
# plot level 1
mapdata1 <- mapdata[mapdata$chr == 1,]
m <- par()$mar
m[1] <- m[3] <- 0
par(mar=m)
# Set the limits of the plot
plot(mapdata1$position,mapdata1$position-mapdata1$position, type="n",
axes=FALSE,
xlab="", ylab="Chromsome", yaxt="n" )
polygon(
c(0,max(mapdata1$position + 0.08 * max(mapdata1$position)),max(mapdata1$position)+
0.08 * max(mapdata1$position),0),
.2*c(-0.3,-0.3,0.3,0.3),
col= mbar.col
)
segments(mapdata1$position, -.3, mapdata1$position, .3 )
text(mapdata1$position, -.7, mapdata1$snpname, srt = 90, cex.lab = chr.lab)
text(mapdata1$position, .7, mapdata1$position,cex.lab = chr.lab )
text(0, labels = c("Chr 2"))
二级
# plot level 2
mapdata2 <- mapdata[mapdata$chr == 2,]
m <- par()$mar
m[1] <- m[3] <- 0
par(mar=m)
# Set the limits of the plot
plot(mapdata2$position,mapdata2$position-mapdata1$position, type="n", axes=FALSE,
xlab="", ylab="Chromsome", yaxt="n" )
polygon(
c(0,max(mapdata2$position + 0.08 * max(mapdata2$position)),max(mapdata2$position)+
0.08 * max(mapdata2$position),0),
.2*c(-0.3,-0.3,0.3,0.3),
col= mbar.col
)
segments(mapdata2$position, -.3, mapdata2$position, .3 )
text(mapdata2$position, -.7, mapdata2$snpname, srt = 90, cex.lab = chr.lab)
text(mapdata2$position, .7, mapdata2$position,cex.lab = chr.lab )
text(0, labels = c("Chr 2"))
输出
(1) 如何实现 n 级的流程自动化 - 将相似图扩展到 n 级 chr (2) 如果您看到相同规格的条形尺寸发生了变化,可能是由于地块面积不同。我该如何调整它以使所有图都相同?
【问题讨论】:
-
有什么特别的理由想要坚持基本图吗? ggplot2 和 lattice 为创建此类复合图提供了简单的解决方案,请参阅这些链接以获取大量示例learnr.wordpress.com/2009/06/28/…learnr.wordpress.com/2009/06/29/…learnr.wordpress.com/2009/07/02/…
-
我同意 ggplot2 和 lattice 更好,但是我觉得它们很难操作,不是吗?
-
一旦你掌握了它的窍门,我发现 ggplot2 很容易使用。在我看来,切换到 ggplot2 或 lattice 绝对是值得的,尽管在与他们俩一起工作之后,我更喜欢 ggplot2。