本文介绍了R markdown中plot.new错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些R代码,使用mixtools包中的ellipse()函数绘制具有已知均值和方差的双变量法线的椭圆.但是,当我在Rmarkdown中运行此命令时,出现错误消息"plot.new尚未被调用".当我在同一块中将另一个图直接放在其上方时,它会运行,但否则会出现错误.是什么原因呢?

I have some R code to plot an ellipse for a bivariate normal with known mean and variance using the ellipse() function from the mixtools package. However when I run this in Rmarkdown I get an error saying "plot.new has not been called yet". When I put another plot directly above it in the same chunk it runs but otherwise I get the error. What's the reason for this?

plot(ellipse(params,covariance, npoints = 500, alpha=0.01),
 xlim = c(-2,3.5),
 ylim = c(0,.75), xlab="alpha", ylab = "beta")

仅在R中运行时,此代码才能正常工作,问题仅在于markdown.

This code works fine when just run in R, the issue is only in markdown.

推荐答案

mixtools函数ellipse()提供了plot参数,请查看手册.这样您就可以像这样绘制椭圆:

mixtools function ellipse() offers a plot argument, look at the manual. So you can plot your ellipse like this:

ellipse(params, covariance,
        npoints = 500, alpha=0.01,
        newplot = TRUE, draw = TRUE,
        xlim = c(-2,3.5), ylim = c(0,.75),
        xlab="alpha", ylab = "beta")

重要的参数是newplot = TRUEdraw = TRUE.它们为您提供了椭圆图,所有其他图形参数都可以通过三点参数提交给函数ellipse().如果newplot = TRUEdraw = TRUE,则在新图上绘制椭圆.如果newplot = FALSEdraw = TRUE,则将椭圆添加到现有绘图中.

The important arguments are newplot = TRUE and draw = TRUE. They offer you the plot of the ellipse and all other graphical parameters can be submitted to the function ellipse() via the three dot argument. If newplot = TRUE and draw = TRUE, plot the ellipse on a new plot. If newplot = FALSE and draw = TRUE, add the ellipse to an existing plot.

这篇关于R markdown中plot.new错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 19:29