2017-04-14 50 views
0

選擇性地工作,我有(如圖吹塑)繪製在曲線線的字。我不知道我怎麼會text()內有srt有條件地這樣操作:控制在文本「SRT」()來作爲R

SRT =用於繪製的字,其x值比「-2」 SRT = -45,比「+2」較大較小,srt =「45」,否則srt =「0」?

我的R代碼在圖片下方。

enter image description here

這裏是我的R代碼裏面:

curve(dnorm(x), -4, 4, bty = 'n', yaxt = 'n') 

x.on.curve = seq(-4, 4, len = 21) 
y.on.curve = dnorm(x.on.curve) 

text(x.on.curve, y.on.curve, "Data", col = 'green', font = 2, pos = 3, xpd = T) 
    ## This is where I want "srt" to work 

回答

1

角度的這種選擇也不會是我的,但你可以調整你認爲合適的。

每個text只能使用一個srt,但您可以使用多個text命令。

curve(dnorm(x), -4, 4, bty = 'n', yaxt = 'n') 
x.on.curve = seq(-4, 4, len = 21) 
y.on.curve = dnorm(x.on.curve) 

text(x.on.curve[x.on.curve < -2], y.on.curve[x.on.curve < -2], 
    "Data", col = 'green', font = 2, pos = 3, xpd = T, srt=-45) 
text(x.on.curve[x.on.curve > 2], y.on.curve[x.on.curve > 2], 
    "Data", col = 'green', font = 2, pos = 3, xpd = T, srt=45) 
text(x.on.curve[x.on.curve >= -2 & x.on.curve <= 2], 
    y.on.curve[x.on.curve >= -2 & x.on.curve <= 2], 
    "Data", col = 'green', font = 2, pos = 3, xpd = T, srt=0) 

Slanted text