【问题标题】:Plot error doing genetics: Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet遗传学绘图错误:plot.xy(xy.coords(x, y), type = type, ...) 错误:尚未调用 plot.new
【发布时间】:2022-12-18 09:13:29
【问题描述】:

试图使用图例的一些函数来绘制可视化转换概率,但我得到了错误:

Error in plot.xy(xy.coords(x, y), type = type, ...) : 
  plot.new has not been called yet

不知道我在哪里搞砸了,但这是我的全部代码:

#here I construct probability matrices
N<-1
possible<-0:(2*N)

P<-NULL#vector para contener nuestras probabilidades
for(i in possible){
  P<-c(P,dbinom(possible, size=2*N, prob=i/(2*N)))
}
(Q<-matrix(P,ncol=2*N+1, byrow=T))

(x<-matrix(c(rep(0,2*N+1)), ncol=2*N+1, byrow=T))

x[,2]<-1
x

(R<-x%*%Q)

color <- c("brown","blue","grey")
shape <- c(15,19,17)

#then here comes the plot part that gives me the error
g <- rep(1,ncol(R))

plot(points(x=NULL, xlim=c(1,10), ylim=c(0,1),
              ylab="Probability",
              xlab="Generations"))
legend("bottomleft",
       legend=c("Extinct", "One copy","Fixed"),
       col=color, pch=shape,
       xpd=TRUE, inset=c(0,1),bty="n")
while(g[1]<=10){
  (R <- R%*%Q)
  g <- g+1
  points(g, R, col=color, pch=shape)
}

【问题讨论】:

    标签: r matrix plot genetics


    【解决方案1】:

    要严格修复该错误,您可以在绘图之前调用plot.new(),但此后会出现错误。如果你打算创建一个空白图,我会删除points,所以你应该有以下内容(注意:你也可以使用type="n"创建一个空白图):

    plot(x=NULL, xlim=c(1,10), ylim=c(0,1),
                  ylab="Probability",
                  xlab="Generations")
    

    输出:

    使用其余代码,您将获得以下内容:

    #here I construct probability matrices
    N<-1
    possible<-0:(2*N)
    
    P<-NULL#vector para contener nuestras probabilidades
    for(i in possible){
      P<-c(P,dbinom(possible, size=2*N, prob=i/(2*N)))
    }
    (Q<-matrix(P,ncol=2*N+1, byrow=T))
    
    (x<-matrix(c(rep(0,2*N+1)), ncol=2*N+1, byrow=T))
    
    x[,2]<-1
    x
    
    (R<-x%*%Q)
    
    color <- c("brown","blue","grey")
    shape <- c(15,19,17)
    
    #then here comes the plot part that gives me the error
    g <- rep(1,ncol(R))
    
    plot(x=NULL, xlim=c(1,10), ylim=c(0,1),
                  ylab="Probability",
                  xlab="Generations")
    legend("bottomleft",
           legend=c("Extinct", "One copy","Fixed"),
           col=color, pch=shape,
           xpd=TRUE, inset=c(0,1),bty="n")
    while(g[1]<=10){
      (R <- R%*%Q)
      g <- g+1
      points(g, R, col=color, pch=shape)
    }
    

    【讨论】:

      猜你喜欢
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多