2017-04-06 43 views
0

我使用ggpairs和而矩陣策劃,我收到一個矩陣如下裹列名的文本中的R

enter image description here

正如你可以看到,一些文字長度大,因此文字不完整。無論如何,我可以包裝文字,使其完全可見。

代碼

ggpairs(df) 

我希望文本換行,這樣可以看到這樣的事情

enter image description here

回答

2

您可以使用ggpairslabeller參數傳遞函數爲應用於小平面文本。

ggplot確實有一個很好的就緒功能label_wrap_gen()包裹長標籤。

默認情況下ggpairs使用列名稱作爲標籤,並且不能包含空格。 label_wrap_gen()需要空格來分割多行上的標籤。

這是一個解決方案:

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))