# Add density distribution as marginal plot Geom_point(aes(color = Species), size = 3, alpha = 0.6) + P <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + ![]() The function ggMarginal() (Attali 2017), can be used to easily add a marginal histogram, density or box plot to a scatter plot.įirst, install the ggExtra package as follow: install.packages("ggExtra") then type the following R code: # Create a scatter plot See this article: Perfect Scatter Plots with Correlation and Marginal Histograms Stat_mean(aes(color = cyl, shape = cyl), size = 2) + Stat_conf_ellipse(aes(color = cyl, fill = cyl), # Add mean points and confidence ellipses Key R functions: stat_chull(), stat_conf_ellipse() and stat_mean() : # Convex hull of groups Instead of drawing the concentration ellipse, you can: i) plot a convex hull of a set of points ii) add the mean points and the confidence ellipse of each group. Stat_ellipse(aes(color = cyl), type = "t")+ level: The confidence level at which to draw an ellipse (default is 0.95), or, if type=“euclid”, the radius of the circle to be drawn.“euclid” draws a circle with the radius equal to level, representing the euclidean distance from the center. The default “t” assumes a multivariate t-distribution, and “norm” assumes a multivariate normal distribution. Add concentration ellipse around groups.Geom_smooth(aes(color = cyl, fill = cyl), Ggpubr::stat_cor(aes(color = cyl), label.x = 3) Geom_smooth(aes(color = cyl), method = lm, # Extend the regression lines: fullrange = TRUEī + geom_point(aes(color = cyl, shape = cyl)) + ![]() Geom_smooth(aes(color = cyl, fill = cyl), method = "lm") +
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |