2017-08-22 3 views
1

の色を変更する、ggbiplot関数は黒で赤い矢印と単位ラベルとして負荷を有するグラフを与える:ggbiplot - デフォルトで標識

library(ggbiplot) 
data("USArrests") 
us <- princomp(USArrests) 
ggbiplot(us, labels = rownames(us$scores)) 

Hereそのコード

どのようにした結果であります私はこれらのラベルの色を変え、それに付随してサイズやフォントを変えますか?

答えて

1
library(ggbiplot) 
library(grid) 
data("USArrests") 
us <- princomp(USArrests) 

# Cut the third score into 4 intervals using quantiles 
cols <- cut(us$scores[,3], quantile(us$scores[,3], probs=seq(0,1,0.25)), include.lowest=T) 

# Change label colors using the "group" option 
# Change label font size using the "label.size" option 
p <- ggbiplot(us, labels = rownames(us$scores), groups=cols, labels.size=4) 

# Change label font family 
g <- ggplotGrob(p) 
g$grobs[[6]]$children[[4]]$gp$fontfamily <- "mono" 
grid.draw(g) 

enter image description here

全体としてラベルの色を変更するには:

p <- ggbiplot(us, labels = rownames(us$scores), groups=1, labels.size=4) + 
    theme(legend.position = "none") 

# Change label colors 
g <- ggplotGrob(p) 
g$grobs[[6]]$children[[4]]$gp$col <- "#FF9900" 
grid.draw(g) 

enter image description here

+0

私は私が探していたものだと思うが_ "グループ" _と_」のラベルでした。サイズ "_オプション。ありがとうございました! – KermittDuss

+0

update:最終的には、「グループ」は正しく機能するためのグループが必要なため、正しいパラメータではないようです。要素や値によらず、ラベル全体の色を変更したいと思います。 おそらく私の質問が十分に正確ではなかった – KermittDuss

+0

ありがとう!それは完全に動作します。 – KermittDuss

関連する問題