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

I am using the function car::ellipse to find the outliers for a dataset. That is from the tutorial from this
DataCamp Course.
I get this error Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet, which already happened before on Community, Here is the link.

Here is the dataset.

hailinsurance <- '[,1] [,2]
[1,] 159913.6 812.27784
[2,] 194875.8 2149.80381
[3,] 181637.8 1458.59068
[4,] 183036.3 1148.18759
[5,] 225498.1 2243.20875
[6,] 186949.7 1481.59199
[7,] 216373.8 2222.87543
[8,] 172315.3 2278.38129
[9,] 167291.9 2210.77064
[10,] 227001.4 117.11734
[11,] 223275.6 1664.59919
[12,] 227712.6 2058.90656
[13,] 214991.6 1955.04805
[14,] 226973.4 56.77483
[15,] 221756.9 1892.38808
[16,] 184904.2 1496.65346
[17,] 175162.2 1298.33624
[18,] 231780.8 2677.76865
[19,] 216426.3 1804.82374
[20,] 183836.1 921.58861
[21,] 238633.1 2540.89572
[22,] 168921.6 802.40331
[23,] 181903.8 1923.84121
[24,] 234812.4 2175.69223
[25,] 159415.9 1084.16309
[26,] 171601.3 2272.39004
[27,] 188040.2 1610.17462
[28,] 253948.1 3133.10863
[29,] 167540.6 192.17004
[30,] 205504.1 1719.79776
[31,] 232411.1 2797.03792
[32,] 188470.5 1236.73799
[33,] 220554.4 1810.96179
[34,] 211594.9 1516.49396
[35,] 220363.4 2313.04967
[36,] 141781.9 365.80618
[37,] 281625.8 3511.29732
[38,] 168589.7 2254.99510
[39,] 176479.7 1243.17811
[40,] 163145.2 1037.87344
[41,] 193902.9 1897.81392
[42,] 250667.6 2929.12516
[43,] 180745.6 1099.61793
[44,] 164929.4 866.18165
[45,] 185255.5 1376.99318
[46,] 202815.7 1296.03983
[47,] 221569.6 1785.95748
[48,] 224789.4 2050.94978
[49,] 168671.0 2281.83434
[50,] 207136.9 1576.85244
[51,] 227542.0 172.95471
[52,] 184539.1 1074.88786
[53,] 186648.0 852.43243
[54,] 199035.3 1169.07874
[55,] 249405.5 2972.55676
[56,] 201242.6 1175.88073
[57,] 169452.1 2217.84047
[58,] 215316.0 2213.51309
[59,] 175360.7 504.08400
[60,] 206761.8 1666.92913
[61,] 212835.6 2290.35188
[62,] 170957.6 2207.58316
[63,] 183427.7 1437.55325
[64,] 220157.6 2083.70037
[65,] 155520.9 556.62912
[66,] 238234.6 1912.01900
[67,] 206057.6 1996.03682
[68,] 201822.0 821.21363
[69,] 154541.8 534.92270
[70,] 165824.2 924.47148
[71,] 199217.7 902.84098
[72,] 172584.7 2247.59985
[73,] 232511.1 102.46895
[74,] 223121.2 1997.20661
[75,] 169486.5 2193.99792
[76,] 221094.4 1717.00922
[77,] 169202.8 1071.07023
[78,] 170529.1 2180.64373
[79,] 148968.6 -37.39962
[80,] 203128.9 1524.51663
[81,] 188606.3 1418.52369
[82,] 172370.2 804.12715
[83,] 210352.4 1565.72034
[84,] 147858.8 256.52071
[85,] 232026.0 2185.00770
[86,] 187090.8 1606.57635
[87,] 255851.0 2815.24444
[88,] 219936.3 1663.08934
[89,] 205273.1 2214.39668
[90,] 226886.6 121.57575
[91,] 177660.3 1142.98712
[92,] 222106.2 2161.28756
[93,] 181385.0 896.89030
[94,] 145985.6 147.25480
[95,] 140447.8 154.44362
[96,] 224385.2 1996.91403
[97,] 170458.0 980.75394
[98,] 233040.7 3006.31231
[99,] 213813.3 1014.17635
[100,] 202301.3 1476.22827'

And here is the reproducible code.

hailinsurance <- 
    fread(here::here('data','hailinsurance.csv'),sep=' ') %>% 
    dplyr::select(-V1) %>% 
    as.matrix()
# Compute the sample mean and sample covariance matrix
clcenter <- colMeans(hailinsurance)
clcov <- cov(hailinsurance)
rad <- 
    sqrt(qchisq(0.975, ncol(hailinsurance))) %>% 
    sqrt
library(car)
ellipse(center = clcenter, shape = clcov, radius = rad, col = "blue", lty = 2)
# Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet

As in the datacamp course you linked to, you need to call plot before using ellipse.
ellipse require to have a plot opened to be able to work. This is also what the error message says

plot.new has not been called yet

Read the documentation and example for more.

1 Like

Thanks, I forget running plot function.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.