SMR locus plot常见报错

1.Error in plot.new() : figure margins too large

一般是Rstudio的plots窗口太小出现报错

解决方法:

(1)直接拉大窗口:如图

(2)使用pdf()函数,自己设置比例大小

# Plot the SMR results in a genomic region centred around a probe:
pdf("LocusPlot.pdf", width = 13, height = 6.7)
SMRLocusPlot(data=smrdata,smr_thresh = 0.05,heidi_thresh = 0.05,plotWindow = 1000,anno_selfdef=FALSE)
dev.off()

2.Error in image.scale(snpCorr^2, col = pal(length(breaks) - 1), breaks = breaks,  :    could not find function "image.scale"

你的R中可能没有image.scale这个功能,虽然会发生这个报错,但是还是可以出图,但是心细的小伙伴会发现图中会少一个标签,具体原因可以去了解一下画图的原理:

解决方法:下载这个链接的代码,然后source:https://oceanwatch.pifsc.noaa.gov/files/scale.R

#This function creates a color scale for use with e.g. the image()
#function. Input parameters should be consistent with those
#used in the corresponding image plot. The "horiz" argument
#defines whether the scale is horizonal(=TRUE) or vertical(=FALSE).
#Depending on the orientation, x- or y-limits may be defined that
#are different from the z-limits and will reduce the range of
#colors displayed.

image.scale <- function(z, zlim, col = heat.colors(12),
                        breaks, horiz=TRUE, ylim=NULL, xlim=NULL, ...){
  if(!missing(breaks)){
    if(length(breaks) != (length(col)+1)){stop("must have one more break than colour")}
  }
  if(missing(breaks) & !missing(zlim)){
    breaks <- seq(zlim[1], zlim[2], length.out=(length(col)+1)) 
  }
  if(missing(breaks) & missing(zlim)){
    zlim <- range(z, na.rm=TRUE)
    zlim[2] <- zlim[2]+c(zlim[2]-zlim[1])*(1E-3)#adds a bit to the range in both directions
    zlim[1] <- zlim[1]-c(zlim[2]-zlim[1])*(1E-3)
    breaks <- seq(zlim[1], zlim[2], length.out=(length(col)+1))
  }
  poly <- vector(mode="list", length(col))
  for(i in seq(poly)){
    poly[[i]] <- c(breaks[i], breaks[i+1], breaks[i+1], breaks[i])
  }
  xaxt <- ifelse(horiz, "s", "n")
  yaxt <- ifelse(horiz, "n", "s")
  if(horiz){YLIM<-c(0,1); XLIM<-range(breaks)}
  if(!horiz){YLIM<-range(breaks); XLIM<-c(0,1)}
  if(missing(xlim)) xlim=XLIM
  if(missing(ylim)) ylim=YLIM
  plot(1,1,t="n",ylim=ylim, xlim=xlim, xaxt=xaxt, yaxt=yaxt, xaxs="i", yaxs="i", ...)  
  for(i in seq(poly)){
    if(horiz){
      polygon(poly[[i]], c(0,0,1,1), col=col[i], border=NA)
    }
    if(!horiz){
      polygon(c(0,0,1,1), poly[[i]], col=col[i], border=NA)
    }
  }
}

然后就可以美美出图啦:

source('image.scale.R')
# Plot effect sizes from GWAS against those from eQTL study:
pdf("EffectPlot.pdf", width = 6.5, height = 6.5)
SMREffectPlot(data=smrdata, trait_name="HCC",) 
# trait_name: name of the trait or disease. 
dev.off()

  • 12
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值