Fit an ellipse around data points

Hello,

I am wanting to fit an ellipse around a set of data points in a plot().

An example is attached to this post with the drawn red line of what I'm wanting to plot.

Thanks!

`dataX <- c(18, 19, 19.5, 21)
dataY <- c(22, 19.5, 23, 20.5)

plot(dataX, dataY, type = "p", pch=21, cex=1.0, xaxp = c(16, 23, 7), yaxp = c(18, 25, 7), col = "black", bg = "green3", xlab = "X", ylab = "Y", xlim=c(16, 23), ylim=c(18, 25))`

Hi,

This geom_mark_ellipse function from ggforce might be useful if you're ok with using ggplot

Hope this helps,
PJ

Thanks for the suggestion Pieter. I managed to get some decent looking results with the stat_ellipse() function. Do you know if there are any critical differences between these two?

Hi,

I experimented with the stat_ellipse() too, but in that case you have to fiddle with the level parameter to have the ellipse enclose all data points as it is using statistical boundaries. But the result should be very similar.

PJ

car::dataEllipse() is meant for exactly this. Lots of options

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.