2014-11-04 1 views
6

나는 다음과 같은 화살에 레이블을 얻으려고합니다 :레이블에 표현식 (cos (alpha))을 얻는 방법은 무엇입니까?

|| x || cos (alpha)

하지만 작동하지 않는 것처럼 보입니다.

문제없이 ||x||을 쓸 수 있으며 문제없이 cos (알파)을 쓸 수 있지만 한 문장으로 가져 오는 방법을 모르겠습니다.

아이디어가 있으십니까?

library(plotrix) 
library(shape) 

xlim <- c(-2, 6) 
ylim <- c(-2, 6) 
plot(0, type = "n", xlim = xlim, ylim = ylim,asp=1) 


Arrows(1,1,5,1) 
boxed.labels(3,1,labels="||x|| cos (a)",border=NA,xpad=1,ypad=1) 


Arrows(1,2,5,2) 
boxed.labels(3,2,labels=expression(cos (alpha)),border=NA,xpad=1,ypad=1) 

답변

9

연구 help("plotmath") 및 데모 예를 들면 다음과 같습니다.

plot(0, type = "n", xlim = xlim, ylim = ylim,asp=1) 
text(2,1,labels=expression(group("||", x, "||") %.% cos(alpha)),adj=c(1.2,-1.5)) 
text(2,3,labels=expression(group("||", x, "||") ~ cos(alpha)),adj=c(1.2,-1.5)) 

resulting plot

+0

감사합니다! 완벽하게 작동합니다! – Martin

2

이에 대한 expression 작품에 붙여 넣은 요소를 전달 :

여기 내 코드입니다.

plot.new() 
plot.window(xlim=c(0, 1), ylim=c(0, 1)) 
text(0.5, 0.5, expression(paste("||x|| cos(", alpha, ")"))) 

enter image description here

5

또한 사용할 수 있습니다 bquote :

plot(1, type = "n") 
text(1, 1, bquote("||x||" ~ cos(alpha))) 

enter image description here

관련 문제