Reputation: 2191
I am using the Auto dataset from the ISLR library and the function ggpairs() from gpairs library to create a scatterplot of all possible combinations of variables. My code is the following:
data(Auto)
setDT(Auto)
ggpairs(Auto[, -c("name"), with = FALSE] ,
lower = list(continuous = wrap("points", color = "red", alpha = 0.5),
combo = wrap("box", color = "orange", alpha = 0.3),
discrete = wrap("facetbar", color = "yellow", alpha = 0.3) ),
diag = list(continuous = wrap("densityDiag", color = "blue", alpha = 0.5) ))+
theme(axis.text.x = element_text(angle = 90, hjust = 1))
There are some issues with this plot:
The axes tick labels are not readable. How could I remove the numbers and possibly rotate the tick lables to be vertical to the axes?
How could I enforce different colors for the combo pairs (categorical - continuous)
Your advice will be appreciated.
Upvotes: 1
Views: 3204
Reputation: 2070
Very tricky stuff, the comb wrapper uses factor levels as input to change colors (as shown in the example by @KoenV) and not discrete which is a bit of a misnomer. Changing the class however changes the upper/diag part.
The only alternative I found was manually changing plots using putPlot
.
# remove ticks (I don't get labels when plotting it)
p = ggpairs(Auto[, -c("name"), with = FALSE] ,
lower = list(continuous = wrap("points", color = "red", alpha = 0.5),
combo = wrap("box", color = "orange", alpha = 0.3),
discrete = wrap("facetbar", color = "yellow", alpha = 0.3)),
diag = list(continuous = wrap("densityDiag", color = "blue", alpha = 0.5) ))+
theme(axis.text = element_blank(),axis.ticks = element_blank())
And change a individual plot and adding a boxplot/ + color (perhaps loop over the desired plots
cp = ggplot(Auto) +
geom_boxplot(aes(as.factor(cylinders), mpg),color="orange")
putPlot(p, cp, 2,1)
Upvotes: 0
Reputation: 4283
Maybe the proposed solution is not a perfect match with your wishes, but I hope it helps.
The following code may do the trick:
library(ISLR)
library(data.table)
library(GGally)
library(ggplot2)
data(Auto, package = "ISLR")
# remove unwanted column and make categorical variables
Auto2 <- Auto[, -9]
Auto2$cylinders <- factor(Auto2$cylinders)
Auto2$origin <- factor(Auto2$origin)
ggpairs(Auto2 ,
lower = list(continuous = wrap("points", color = "red", alpha = 0.5),
combo = wrap("box", color = "orange", alpha = 0.3),
discrete = wrap("facetbar", color = "yellow", alpha = 0.3) ),
diag = list(continuous = wrap("densityDiag", color = "blue", alpha = 0.5) ))
This yields the following picture:
Please let me know whether this is what you want.
Upvotes: 2