
Xplot <- ggboxplot(iris, x = "Species", y = "Sepal.Length",Ĭolor = "Species", fill = "Species", palette = "jco", # Marginal boxplot of x (top panel) and y (right panel) Size = 3, alpha = 0.6, ggtheme = theme_bw()) Rel_widths = c(2, 1), rel_heights = c(1, 2))Īdd marginal boxplot: # Scatter plot colored by groups ("Species")

Plot_grid(xplot, NULL, sp, yplot, ncol = 2, align = "hv", Xplot <- xplot + clean_theme() + rremove("legend") Yplot <- yplot + clean_theme() + rremove("legend") Yplot <- ggdensity(iris, "Sepal.Width", fill = "Species", Xplot <- ggdensity(iris, "Sepal.Length", fill = "Species", # Marginal density plot of x (top panel) and y (right panel) Sp <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width", # Scatter plot colored by groups ("Species") In the R code below, we provide a solution using the cowplot package. One limitation of ggExtra is that it can’t cope with multiple groups in the scatter plot and the marginal plots.

P <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width",
#PERFECT FACE OUTLINE TRANSPARENT INSTALL#
The function ggMarginal(), can be used to easily add a marginal histogram, density or boxplot to a scatter plot.įirst, install the ggExtra package as follow: install.packages(“ggExtra”) then type the following R code: # Add density distribution as marginal plot lect: character vector specifying some labels to show.To specify only the size and the style, use font.label = list(size = 14, face = “plain”). For example font.label = list(size = 14, face = “bold”, color =“red”). font.label: a list which can contain the combination of the following elements: the size (e.g.: 14), the style (e.g.: “plain”, “bold”, “italic”, “alic”) and the color (e.g.: “red”) of labels.label: the name of the column containing point labels.
