我想绘制一个置信椭圆。我搜索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
我没有打电话给“plot.new”,R为什么这么说?
你链接到描述链接中的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();