在R中为变量加上标

在R中为变量加上标,r,variables,plot,superscript,R,Variables,Plot,Superscript,我是R的初学者,我试图把一个包含上标变量的方程放在绘图上。我知道如何在绘图上打印上标字母,但我想不出插入变量的方法。这是我的密码: DF <- data.frame(X <- c(1, 2, 3, 4, 5, 6, 7), Y <- c(0, 0, 1, 0, 1, 1, 1)) # Logistic regression model <- glm(Y ~ X, family = binomial, data = DF) # Plot raw data raw_plo

我是R的初学者,我试图把一个包含上标变量的方程放在绘图上。我知道如何在绘图上打印上标字母,但我想不出插入变量的方法。这是我的密码:

DF <- data.frame(X <- c(1, 2, 3, 4, 5, 6, 7), Y <- c(0, 0, 1, 0, 1, 1, 1))

# Logistic regression
model <- glm(Y ~ X, family = binomial, data = DF)

# Plot raw data
raw_plot <- plot(DF$X, DF$Y,
        xlab = 'X', ylab = 'Y'
        )

# Add prediction curve
curve(predict(model, data.frame(X = x), type = 'response'), add = TRUE)

# Get coefficients
intercept <- summary(model)$coefficients[1] # -4.361418
coefficient <- summary(model)$coefficients[2] # 1.250679

superscript.part <- sprintf('%.2f + %.2f*x', intercept, coefficient)

text(5, 0.2, labels = expression(paste('y = 1/(1 + 1/e'^'superscript.part'*')')))
# This will superscript 'superscript' and not the actual variable
DF这项工作:


text(5,2,bquote(“y=1/(1+1/e)^{(上标部分)}}~”)

如果你必须
text(5,0.2,labels=expression(粘贴(y=1/(1+1/e^{-4.36+1.25*x})),你可以这样做。
我喜欢
替换
,因为我觉得它更容易记住(然后
bquot
e和
expression
):
text(5,0.2,labels=substitute(“y=1/(1+1/e“^X*”),list(X=superscript.part))
谢谢!我读过关于substitute的文章,但没能让它起作用,但你的例子起了作用!我认为这样的排版稍微好一些。
text(5,5,bquote(y==1/(1+1/e^~(superscript.part)))
但是???谢谢!他们两人都很努力,给了我想要的东西。这里的人真的很有帮助,反应很快,对于像我这样的初学者来说,这真的很有帮助!