2016-10-24 8 views
1

로딩 레이블의 위치를 ​​조정하여 화살표 꼭대기에 떨어지지 않게하고 싶습니다. 그러나 나는 조정이 필요한 곳을 모른다. geom_text은 사이트 위치의 위치를 ​​조정하는 데 사용할 수 있지만 벡터가 저장되는 위치는 str(g)입니다.autoplot - 라벨로드 조절 방법은 무엇입니까?

library(ggplot2) 
library(ggfortify) 
df <- data.frame(replicate(10,sample(-10:10,10,rep=TRUE))) 
names(df) <- c('up','down','left','right','circle','square','triangle','x','r1','l1') 
rownames(df) <- paste('Dummy Site', seq(0,9,1)) 
g <- autoplot(prcomp(df[,-11], scale=TRUE), data=df, 
       loadings.label=TRUE, loadings=TRUE, 
       loadings.label.size=8, loadings.colour='blue', 
       label.size=5) + 
    geom_text(vjust=-1, label=rownames(df)) + 
    theme(plot.background=element_blank(), 
      panel.background=element_rect(fill='transparent',color='black',size=1), 
      legend.text=element_text(hjust=1), 
      legend.key=element_blank()) 
g 

나는 ggplot2::theme에서 살펴본 autoplot에 대한 도움말 문서를 검토했지만, 조정 라벨 위치에 대한 언급을 찾을 수 없습니다. 화살표의 벡터에 따라 조정할 수 있다면 보너스 포인트이지만 정적 조정은 허용됩니다. 당신은 layer_data(g, 2)에 의해 좌표를 얻을 수 있습니다 An example of what the above code generates

답변

1

:

현재, 여기처럼 줄거리는 모습입니다. 그러나 autoplot(prcomp.obj)ggbiplot()에 다른 인수를 전달하므로 ggbiplot()의 인수 (예 : ?ggbiplot)를 사용하여 labelloadings.label 위치를 변경할 수 있습니다.

예제 코드 :
arrow_ends <- layer_data(g, 2)[,c(2,4)] 

autoplot(prcomp(df[,-11], scale=TRUE), data=df, 
     loadings.label=TRUE, loadings=TRUE, 
     loadings.label.size=8, loadings.colour='blue', 
     label.size=5, loadings.label.vjust = 1.2) +  # change loadings.label position 
    geom_point(data = arrow_ends, aes(xend, yend), size = 3) + # the coordinates from layer_data(...) 
    geom_text(vjust=-1, label=rownames(df)) + 
    theme(plot.background=element_blank(), 
      panel.background=element_rect(fill='transparent',color='black',size=1), 
      legend.text=element_text(hjust=1), 
      legend.key=element_blank()) 

enter image description here