“控制”;srt“;在text()中有选择地在R中工作

“控制”;srt“;在text()中有选择地在R中工作,r,if-statement,plot,R,If Statement,Plot,我在曲线上画了一个单词(,如图所示)。我想知道我怎么能在text()中有srt以这种方式有条件地运行: srt=对于x值小于“-2”srt=-45、大于“+2”、srt=“45”、否则srt=“0”的打印字 我的R代码在图片下方。 这是我的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.

我在曲线上画了一个单词(,如图所示)。我想知道我怎么能在
text()
中有
srt
以这种方式有条件地运行:

srt=对于x值小于“-2”srt=-45、大于“+2”、srt=“45”、否则srt=“0”的打印字

我的R代码在图片下方。

这是我的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

这个角度的选择不是我的,但你可以根据自己的喜好进行调整

每个
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) 
曲线(dnorm(x),-4,4,bty='n',yaxt='n')
x、 on.curve=seq(-4,4,len=21)
y、 曲线上=dnorm(x曲线上)
文本(x.on.曲线[x.on.曲线<-2],y.on.曲线[x.on.曲线<-2],
“数据”,列=绿色,字体=2,位置=3,xpd=T,srt=-45)
文本(x.on.曲线[x.on.曲线>2],y.on.曲线[x.on.曲线>2],
“数据”,列=绿色,字体=2,位置=3,xpd=T,srt=45)
文本(x.on.curve[x.on.curve>=-2&x.on.curve=-2&x.on.curve