2017-04-14 48 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