簡體   English   中英

用 Rsquare 和方程繪制散點圖

[英]Plotting a scatter plot with Rsquare and equation

我想使用 ggpubr 繪制帶有回歸方程和 R 平方的散點圖。 但是我收到以下錯誤消息“找不到數據中的 y 元素”。

這是一個可重現的例子:

    x <- c(841.564927857936, 841.564927857936, 841.424690409534, 841.284499691372, 
420.782463928968, 420.88768585043, 420.432103842432, 420.572177840048, 
420.712345204767, 420.782463928968, 420.747401645497)
y <- c(43692.05, 51561, 34637.8270288285, 36198.5838053982, 36909.925, 
30733.6584146036, 32350.3164029975, 31906.371814093, 30367.0638226962, 
32410.975, 31970.2108157654)
df <- data.frame(x,y)

ggscatter(df,x, y, add = "reg.line") +
  stat_cor(label.x = 3, label.y = 34) +
  stat_regline_equation(label.x = 3, label.y = 32)

謝謝

您需要將 x 和 y 的名稱放在引號中,例如:

library(ggpubr)
ggscatter(df,x="x", y="y", add = "reg.line") +
  stat_cor(label.x = 3, label.y = 3000) +
  stat_regline_equation(label.x = 3, label.y = 5000)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM