You can use the labeller
argument of ggpairs
to pass a function to be applied to the facet strip text.
ggplot
does have a nice ready function label_wrap_gen()
that wrap the long labels.
By default ggpairs
use the column names as labels, and those can't contain spaces. label_wrap_gen()
need spaces to split the labels on multiple rows.
This is a solution:
library(ggplot2)
library(GGally)
df <- iris
colnames(df) <- make.names(c('Long colname',
'Quite long colname',
'Longer tha usual colname',
'I\'m not even sure this should be a colname',
'The ever longest colname that one should be allowed to use'))
ggpairs(df,
columnLabels = gsub('.', ' ', colnames(df), fixed = T),
labeller = label_wrap_gen(10))
