简体   繁体   中英

Plotting a scatter plot with Rsquare and equation

I would like to use ggpubr to plot a scatter plot with the regression equation and the R squared. But I get the following error message " Can't find the y elements in the data ".

Here is a reproducible exemple :

    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)

Thanks

You need to put name of x and y in quotes, for example:

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)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM