Scatter plots with joint and marginal distributions
We have seen how to create scatter plots with ggplot()
in previous chapters. Therefore, in this section, we will only focus on the parts that we have not seen before. Our objective is to create scatter plots that not only show the scatter plot, but extend it by showing the marginal distributions on both axes. These are called marginal plots and are useful for understanding how data is jointly (two variables) as well as marginally (one variable) distributed.
Pricing and profitability by protein source and continent
As usual, we start developing our graph function. We receive as parameters the data
, and the variables for the x axis (x
) and y axis (y
), and, in this case, we anticipate four cases that correspond to the combinations of including or not the color
and shape
variables for the graph. We do the standard checking and create the corresponding graph base. Here comes the different part, we call the ggMarginal()
function of the ggExtra
...