How to create faceted correlation plot using GGPLOT

前端 未结 3 1983
失恋的感觉
失恋的感觉 2021-02-10 06:07

I have a data frame created the following way.

library(ggplot2)

x <- data.frame(letters[1:10],abs(rnorm(10)),abs(rnorm(10)),type=\"x\")
y <- data.frame(le         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-10 06:42

    There is an additional package ggpubr available now addressing exactly this issue with the stat_cor() function.

    library(tidyverse)
    library(ggpubr)
    ggplot(all, aes(val1, val2))+ 
      geom_smooth(method = "lm")  + 
      geom_point() +  
      facet_grid(~type) +
      stat_cor()
    

提交回复
热议问题