我想知道是否可以在points()
的左侧插入mtext()
? 换句话说,有没有办法可以获得mtext()
的 x,y ,这样我才能确定points()
的正确位置出现?
这是我的R代码:
curve(dnorm(x),-3,3)
mtext(bquote(paste("Medium: ",bold('CT'[12])," = ", .(round(1/3,3)))),line=3)
答案 0 :(得分:3)
如果您使用text
代替mtext
,则变得非常简单,因为您可以对文本和点使用x
和y
。
#Plot the curve
curve(dnorm(x),-3,3)
#Enable drawing outside the plot region
par(xpd = TRUE)
#STEP 3. Add text at certain x and y.
text(x = 0, y = 0.45,
bquote(paste("Medium: ",bold('CT'[12])," = ", .(round(1/3,3)))))
#Determine the width of the text you added
text_width = strwidth( bquote(paste("Medium: ",bold('CT'[12])," = ", .(round(1/3,3)))) )
#Find out x poistion just left of the text.
#Since the text is centre aligned by default,
#you can subtract half the text_width to the x value
#that you had used to add text in STEP 3
#You may also add 10% extra space
points_x = (0 - text_width/2) - (0.1*text_width)
#Add a point just to the left of the text
points(x = points_x, y = 0.45, pch = 20, cex = 3)