A scatterplot is a graph in which the values of two variables are plotted along two axes, the pattern of the resulting points revealing any correlation present.
It is sometimes important to check the distribution of variables of the X and Y axis. This can be done by adding marginal plots. The ggExtra library allows one to do it easily thanks to Dean Attali.
# The mtcars dataset is proposed in R
# classic plot :
p=ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, size=cyl)) +
# with marginal histogram
# marginal density
# marginal boxplot
Note that you can customize the margins’ width or their features, and you can show the margin for only one axis.
# Set relative size of marginal plots (main plot 10x bigger than marginals)
ggMarginal(p, type="histogram", size=10)
# Custom marginal plots:
ggMarginal(p, type="histogram", fill = "slateblue", xparams = list( bins=10))
# Show only marginal plot for x axis
ggMarginal(p, margins = 'x', color="purple", size=4)
Not what you are looking for ? Make a new search !