2014-11-04 56 views
6

我試圖讓,說一個箭頭的標籤:如何獲取表達式(cos(alpha))到標籤中?

|| X || cos(alpha)

但我似乎無法讓它工作。

我可以寫出||x||沒有問題,和cos(alpha)沒有問題,但我不知道如何讓他們成爲一個聲明。

任何想法?

這裏是我的代碼:

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 2014-11-04 10:07:56

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

相關問題