使用" panel.ellipse"时出错在R中的功能

时间:2017-12-17 12:29:17

标签: r

我想画一个置信椭圆。我搜索R文档并找到函数:panel.ellipse。这是description website

然后我试过了。我使用下面的代码:

library(corrgram)
a<-c(1,2,3,4,5)
b<-c(2,4,6,5,3)
panel.ellipse(a, b)

但是会发生错误:

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

我没有打电话给#34; plot.new&#34;,为什么R说出来?

1 个答案:

答案 0 :(得分:1)

您要链接到说明链接中的latticeExtra::panel.ellipse函数,但似乎正在使用corrgram,它还具有panel.ellipse功能。所以我不确定您正在使用/想要使用哪个panel.ellipse功能。

来自?corrgram::panel.ellipse

# CAUTION: The latticeExtra package also has a 'panel.ellipse' function
# that clashes with the same-named function in corrgram. In order to us
# the right one, the example below uses 'lower.panel=corrgram::panel.ellipse'.
# If you do not have latticeExtra loaded, you can just use
# 'lower.panel=panel.ellipse'.

为什么不使用ggplot2::stat_ellipse

# Your sample data
a<-c(1,2,3,4,5)
b<-c(2,4,6,5,3)
df <- cbind.data.frame(a, b);

# Use stat_ellipse to draw confidence ellipse
require(ggplot2);
ggplot(df, aes(a, b)) + geom_point() + stat_ellipse();

enter image description here