# NOT RUN {
# Load data
data("mtcars")
df <- mtcars
df$cyl <- as.factor(df$cyl)
# scatter plot with convex hull
ggscatter(df, x = "wt", y = "mpg", color = "cyl")+
stat_chull(aes(color = cyl))
ggscatter(df, x = "wt", y = "mpg", color = "cyl")+
stat_chull(aes(color = cyl, fill = cyl), alpha = 0.1, geom = "polygon")
# }
Run the code above in your browser using DataLab