scatterplot
function
The car
package contains a function named scatterplot
which creates scatter plots in base R with marginal box plots. Note that by default the function also adds smoothed and linear regression lines, which we omitted.
Scatter plot with marginal box plots
The boxplots
argument of the function defaults to "xy"
. However, if you set boxplots = "x"
only the box plot for the X-axis will be displayed.
Equivalently, if you set boxplots = "y"
only the Y-axis box plot will be drawn.
layout
function
The function of the last section is very useful for adding marginal box plots quickly. However, it doesn’t allow further customization of the box plots or change the position of the box plots.
The layout
function can be used to add marginal charts, allowing you to customize each plot and placing it where you want. If you are not familiar with this function check the tutorial about combining plots.
See also