R | tidymodels 之 corrr

2022-08-13  本文已影响0人  shwzhao

tidymodels 的非核心包。
没用过 ggcor,不知道对比起来怎么样。

参考:
https://github.com/tidymodels/corrr

image.png
install.packages("corrr")
library(corrr)
library(tidyverse)
df <- tibble(a = c(1,3,5,9), b = c(2,4,9,6), c = c(5,7,3,5))
cor(df, method  = "pearson")
#>           a          b          c
#> a  1.0000000  0.6046107 -0.2390457
#> b  0.6046107  1.0000000 -0.6835859
#> c -0.2390457 -0.6835859  1.0000000
cor_df <- correlate(df, method = "pearson")
#> 
#> Correlation method: 'pearson'
#> Missing treated using: 'pairwise.complete.obs'
#> 
#> # A tibble: 3 x 4
#>   term       a      b      c
#>   <chr>  <dbl>  <dbl>  <dbl>
#> 1 a     NA      0.605 -0.239
#> 2 b      0.605 NA     -0.684
#> 3 c     -0.239 -0.684 NA
cor_df <- correlate(mtcars, method = "pearson") %>%
  focus(-mpg, mirror = T) %>%
  rearrange() %>%
  shave(upper = T)
  # fashion()
rplot(cor_df, colors = c("green", "red"), shape = 18)
image.png
cor_df2 <- cor_df %>%
  column_to_rownames("term")

pheatmap::pheatmap(cor_df2, cluster_rows = F, cluster_cols = F)
image.png

没有那个图的绘制函数,哪个图?懂的都懂那个图。

上一篇 下一篇

猜你喜欢

热点阅读