I'm using the crab data set from MASS library in R Studio. I want to create a scatterplot matrix of the five quantitative variables and an interaction variable of sp.sex as the only categorical variable using ggpairs. I have reordered the factor levels as B.M, B.F, O.M, and O.F.
I would like to use a diverging 4-class RdYlBu color scheme from RColorBrewer, where blue represents blue species and red represents orange species. Additionally, I would like to have two darker colors from the palette for male crabs and two lighter colors for females.
I have this code so far, but continue to get an error and no matrix output:
crabs$sp.sex <- factor(paste(crabs$sp, crabs$sex, sep="."), levels=c("B.M", "B.F", "O.M", "O.F"))
ggpairs(crabs, columns = 4:9, aes(color = sp.sex),
mapping = aes_string(fill = "sp.sex"),
lower = list(continuous = wrap("density", alpha = 0.5)),
diag = list(continuous = wrap("density", alpha = 0.5)),
upper = list(continuous = wrap("cor", size = 2)),
title = "Scatterplot Matrix of Crab Data") +
scale_color_manual(values = c("blue", "blue4", "orange4", "orange"),
labels = c("B.M", "B.F", "O.M", "O.F")) +
scale_fill_manual(values = brewer.pal(4, "RdYlBu"),
labels = c("B.M", "B.F", "O.M", "O.F")) +
theme_bw()
The error I get is this:
Error in stop_if_params_exist(params) :
'params' is a deprecated argument. Please 'wrap' the function to supply arguments. help("wrap", package = "GGally")
There is no output coming up in the plot window.
I first tried to tinker with each part of your code and noticed this specific code has no issues running, as it removes the list arguments you have for
upper,lower, anddiagonal. I just added the fill and color arguments toaes_stringbecause it was otherwise redundant:If you run all of the list arguments I mentioned previously, you get the following error:
It appears there is some odd mapping issue going on here between the wrappers and what you are trying to achieve. One way of getting around this is to port in your own functions as shown in this ggpairs vignette. I show below:
Then just insert them into the wrappers of the plot: