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()