Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weight parameter for stat_ellipse() #5272

Open
jammainen opened this issue Apr 15, 2023 · 1 comment · May be fixed by #6186
Open

Weight parameter for stat_ellipse() #5272

jammainen opened this issue Apr 15, 2023 · 1 comment · May be fixed by #6186

Comments

@jammainen
Copy link

Geom_density, geom_barplot, geom_histogram and geom_barplot all support aes weight. Stat_ellipse() doesnt support.

I figured out that data[rep(data$rownumber,data$weight),] is a workaround, but that doesnt work too well(or at all) when weights are large. Scaling the weights could work, but then it would lose the accuracy of original data.

Would it be possible to add stat_ellipse() to suppport weight aesthetics?

@teunbrand
Copy link
Collaborator

I'm not familiar with the theory behind these data ellipses, but would this be as simple as passing weights to the stats::cov.wt()/MASS::cov.trob() functions in the lines below?

ggplot2/R/stat-ellipse.R

Lines 98 to 105 in e3b7822

if (type == "t") {
v <- MASS::cov.trob(data[,vars])
} else if (type == "norm") {
v <- stats::cov.wt(data[,vars])
} else if (type == "euclid") {
v <- stats::cov.wt(data[,vars])
v$cov <- diag(rep(min(diag(v$cov)), 2))
}

@teunbrand teunbrand linked a pull request Nov 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants