I have this code:
library(echarts4r) iris |> dplyr::group_by(Species) |> e_charts(Sepal.Length) |> e_scatter(Petal.Length, symbol_size = 5) |> e_tooltip()
How to insert ellipses with color opacity in groups?
Something like:
You can use the stat_ellipse function:
stat_ellipse
We can use this example to perform a Linear Discriminant Analysis in R, similar to yours and easy to reproduce with the code here.
Then, you can use ggplot and stat_ellipse function, as already suggested,
ggplot
and to vary the opacity of the ellipse's color as you wish, you can change the alpha value, 1 for very opaque and 0 for transparent,
alpha
ggplot(lda_plot, aes(LD1, LD2)) + geom_point(aes(color = Species)) + stat_ellipse(geom="polygon", aes(fill = Species), alpha = 0.2, show.legend = FALSE, level = 0.95) + ggtitle("a) Opacity 0.2") ggplot(lda_plot, aes(LD1, LD2)) + geom_point(aes(color = Species)) + stat_ellipse(geom="polygon", aes(fill = Species), alpha = 0.8, show.legend = FALSE, level = 0.95) + ggtitle("b) Opacity 0.8")
such as,
I hope I have answered your question
You can use the
stat_ellipse
function:We can use this example to perform a Linear Discriminant Analysis in R, similar to yours and easy to reproduce with the code here.
Then, you can use
ggplot
andstat_ellipse
function, as already suggested,and to vary the opacity of the ellipse's color as you wish, you can change the
alpha
value, 1 for very opaque and 0 for transparent,such as,
I hope I have answered your question