2014-11-04 6 views
6

Ich versuche, ein Etikett auf einem Pfeil zu erhalten, die sagt:Wie bekomme ich einen Ausdruck (cos (alpha)) in ein Label?

|| x || cos (alpha)

Aber ich kann nicht scheinen, damit es funktioniert.

Ich kann die ||x|| ohne Probleme schreiben, und die cos (alpha) ohne Probleme, aber ich weiß nicht, wie man sie in eine Aussage bekommt.

Irgendwelche Ideen?

Hier ist mein Code:

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) 

Antwort

9

Study help("plotmath") und der Demo.

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

Vielen Dank! Es funktioniert perfekt! – Martin

2

Pass geklebt Elemente expression Werke für diese. Zum Beispiel:

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

Sie auch bquote verwenden können:

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

enter image description here

Verwandte Themen