2016-08-25 2 views
1

ggplot2에서 범례를 사용자 정의 텍스트로 바꿀 수 있습니까? 나는 에 대해 알아 두었고이라고 표기하고 싶지만 그 옆에 (또는 그 아래에) 차트에 글을 쓰고 싶지는 않습니다. 정확히 어디에서 전설이 될 것인지, 합리적으로 간단한 방식으로 쓰고 싶습니다.r ggplot2 - 범례 대신 사용자 정의 텍스트

예. 이 간단한 도표에

library(data.table) 
library(ggplot2) 
library(ggrepel) 

id <- c(1:10) 
x1 <- sample(1:10, 10, replace=T) 
x2 <- sample(1:10, 10, replace=T) 
x3 <- sprintf("Point.%d",id) 
df<-data.frame(id,x1,x2,x3) 
dt<-data.table(df) 
setkeyv(dt,c("id")) 

p<-ggplot(data=dt,aes(x1,x2))+geom_point()+geom_text_repel(aes(label=x3))+ 
ggtitle("Graph")+xlab("X")+ylab("Y")+theme_bw() 
p 

나는 그 옆에 차트에 대해 (짧은) 글을 쓰고 싶다. ggplot2는 목적을 넘어서는 것이기 때문에 쉽게 가능하지 않을 수도 있지만 두렵습니다.

+0

이 스택 오버 플로우를 보았습니까 [링크] (http://stackoverflow.com/qu estions/12409960/ggplot2-annotate-plot-outside). 이 질문은 중복 될 수 있습니다. – steveb

+0

아니요, 차트 안에 쓰고 싶지 않습니다. 전체 차트 옆에 텍스트가 있습니다. 나는 주석에 대해 알고 있지만 그것이 (어떻게 든) 전설을 사용하는 더 좋은 방법이 될 수 있기를 바랍니다. – Martin

+1

다른 가능성 [here] (http://stackoverflow.com/questions/32506444/ggplot-function-to-add-text-just-below-legend). – Henrik

답변

7

이, 기본 텍스트로

gridExtra::grid.arrange(ggplot2::ggplot(), right = "this is a note") 

enter image description here

이 명시 적으로 textGrob를 사용 덮어, 90도 회전, 가장 쉬운 방법이 될 수

gridExtra::grid.arrange(ggplot2::ggplot(), right = grid::textGrob("this is a note")) 

enter image description here

+0

고마워,이게 내가 원하는거야. – Martin