1 散点图

1.1 基础散点图

Code
df <- data.frame(
  x = 1:100,
  y = rnorm(100) + 2 * (1:100)  # 生成具有线性关系的x和y数据
)

p <- ggplot(df, aes(x = x, y = y))+
    geom_point(color='red')
p

1.2 添加平滑曲线

R2 ,p值:f6c

Code
p <- p +
    geom_smooth(method = "lm",formula = "y~x",color="black",linewidth=.8)
p

1.3 添加表达式

Code
p + ggpmisc::stat_poly_eq(formula = y ~ x,
                 ggpmisc::use_label(c("eq", "adj.R2", "P")))
#> Registered S3 methods overwritten by 'ggpp':
#>   method                  from   
#>   heightDetails.titleGrob ggplot2
#>   widthDetails.titleGrob  ggplot2

Back to top