我试图创建一个指数而不是R^2

我试图创建一个指数而不是R^2,r,ggplot2,R,Ggplot2,我正在使用ggplot2创建一个包含2个变量的散点图。我想把这些打印在ggplot的标题部分: 线性回归方程 r2值 p值 我使用括号、新行和存储值将所有内容连接在一起。我尝试使用expression()、parse()和bquote()函数,但它只打印变量名,而不打印存储的值。 . 除了R^2部分外,其他一切看起来都很棒。括号似乎造成了很多问题,但我想保留它们(在我看来看起来更好)。。我只关心结尾的标题部分。很难使用您作为示例提供的代码(请参见注释:可复制示例),但我最近让我的学生完成了一

我正在使用ggplot2创建一个包含2个变量的散点图。我想把这些打印在ggplot的标题部分:

  • 线性回归方程
  • r2值
  • p值
我使用括号、新行和存储值将所有内容连接在一起。我尝试使用expression()、parse()和bquote()函数,但它只打印变量名,而不打印存储的值。
. 除了R^2部分外,其他一切看起来都很棒。括号似乎造成了很多问题,但我想保留它们(在我看来看起来更好)。。我只关心结尾的标题部分。

很难使用您作为示例提供的代码(请参见注释:可复制示例),但我最近让我的学生完成了一个类似的作业练习,并且可以提供一个您可以从中概括的示例。我的方法是使用
latex2exp
包中的
TeX()
函数

心理学家感兴趣的是,她是否能够根据学生在研究生成绩考试(GRE)中的早期成绩预测研究生院的平均成绩。

建立玩具数据和回归模型

如果您包含一个简单的示例输入和所需的输出,可以用来测试和验证可能的解决方案,那么就更容易为您提供帮助。请不要发布代码的图片,因为我们必须重新键入所有内容才能尝试。编辑您的问题,将代码作为文本包含。R^2部分有什么不好的地方?
GPA <- c(3.70,3.18,2.90,2.93,3.02,2.65,3.70,3.77,3.41,2.38,
         3.54,3.12,3.21,3.35,2.60,3.25,3.48,2.74,2.90,3.28)
GRE <- c(637,562,520,624,500,500,700,680,655,525,
         593,656,592,689,550,536,629,541,588,619)

gpa.gre <- data.frame(GPA, GRE)
mod <- lm(GPA ~ GRE, data = gpa.gre)
mod.sum <- summary(mod)
print(cofs <- round(mod$coefficients, digits = 4))
aY <- cofs[[1]]
bY <- cofs[[2]]
print(Rsqr <- round(cor(GPA,GRE)^2, digits = 2))
require(ggplot2)
require(latex2exp)

p <- ggplot(data = gpa.gre, aes(x = GRE, y = GPA)) +
  geom_smooth(formula = 'y ~ x', color ="grey40", method = "lm", 
              linetype = 1, lwd = 0.80, se = TRUE, alpha = 0.20) +
  geom_point(color = "grey10", size = 1) +
  labs(y = "Grade Point Average", x = "GRE Score") +
  coord_cartesian(ylim = c(2.28, 3.82), xlim = c(498, 702), clip = "off") +
  scale_y_continuous(breaks = seq(2.30, 3.80, 0.25)) +
  scale_x_continuous(breaks = seq(500, 700, 50)) +
  theme_classic() + 
  theme(axis.title.x = element_text(margin = unit(c(3.5,0,0,0), "mm"), size = 11.5),
        axis.title.y = element_text(margin = unit(c(0,3.5,0,0), "mm"), size = 11.5),
        axis.text = element_text(size = 10),
        plot.margin = unit(c(0.25,4,1,0.25), "cm"))

# Use TeX function to use LaTeX

str_note <- TeX("\\textit{Note. ***p} < .001")
str_eq <- TeX("$\\hat{\\textit{y}} = 0.4682 + 0.0045 \\textit{x}$")
str_rsq <- TeX("$\\textit{R}^2 = .54***$")

# Create annotations

p + annotate("text", x = 728, y = 3.70, label = str_eq, size = 3.5,
             hjust = 0, na.rm = TRUE) +
  annotate("text", x = 728, y = 3.57, label = str_rsq, size = 3.5,
           hjust = 0, na.rm = TRUE) +
  annotate("text", x = 490, y = 1.80, label = str_note, size = 3.5,
           hjust = 0, na.rm = TRUE) 
ggsave(filename = '~/Documents/gregpa.png', # your favourite file path here 
       width = unit(5, "in"), # width of plot
       height = unit(4, "in"),  # height of plot
       dpi = 400) # resolution in dots per inch