2015-12-19 2 views
8

Ich habe folgendes versucht, aber es für mich nicht funktioniert:Wie wird +/- plus minus Operator in Text Annotation des Plots (ggplot2) platziert?

a <- ggplot() 
a <- a + geom_point(aes(x=seq(0,1,0.1), y=seq(0,1,0.1))) 
a <- a + annotate("text", x=0.5, y=0.3, label="myplot") 
a <- a + annotate("text", x=0.5,y=0.2,label=expression(%+-%)) 

Ich habe versucht, auch die folgenden, wie durch How to annotate() ggplot with latex ohne Glück wies darauf hin:

a <- a + annotate("text", x=0.5, y=0.1, label="%+-%", parse=TRUE) 

Und das doesn‘ t Arbeit entweder:

a <- a + annotate("text", x=0.5, y=0.1, label="\pm", parse=TRUE) 

Antwort

10

Es ist möglich, die Unicode-Darstellung (\u00B1) zu verwenden:

a <- ggplot() 
a <- a + geom_point(aes(x=seq(0,1,0.1), y=seq(0,1,0.1))) 
a <- a + annotate("text", x=0.5, y=0.3, label="myplot") 
a + annotate("text", x=0.5, y=0.2, label="\u00B1") 

Oder Sie können das ± Symbol direkt verwenden, durch Kopieren und es von irgendwo einfügen.

a + annotate("text", x=0.5, y=0.2, label="±") 
5

Dies funktioniert:

a0 <- ggplot() 
a0 <- a0 + geom_point(aes(x=seq(0,1,0.1), y=seq(0,1,0.1))) 
a0 + annotate("text", x=0.5, y=0.1, label="'' %+-% '' ", parse=TRUE) 

Die Schlüsselidee ist, dass %+-% ist ein Operator, so dass es sich auf etwas arbeiten muss, das heißt es hat x %+-% y in der Form sein; In diesem Fall habe ich x und y leere Zeichenfolgen gemacht.

+0

Phantom funktioniert auch, obwohl es fast vollständig – rawr

+0

Lesen undokumentiert und Re-Lektüre der plotmath Seite notwendig. Und tatsächlich ist es 'phantom()', das benötigt wird. –

Verwandte Themen