美文网首页ggplot2绘图
2021-04-28corrmorrant包快速绘制相关图

2021-04-28corrmorrant包快速绘制相关图

作者: iColors | 来源:发表于2021-04-28 09:32 被阅读0次

安装包

remotes::install_github("r-link/corrmorant")

加载包和绘图

library(corrmornt)
library(tidyverse)
corrmorant(mpg)
image.png

换颜色绘图

corrmorant(drosera, style = "light")
image.png
corrmorant(drosera, style = "blue_red")
image.png

更复杂的绘图

ggcorrm(data = mpg)+
  lotri(geom_point(alpha=0.5))+
   lotri(geom_smooth())+
   utri_heatmap()+
   utri_corrtext()+
   dia_names(y_pos = 0.15,size=3)+
   dia_histogram(lower = 0.3,fill="grey80",color=1)+
   scale_fill_corr()+
   labs(title="Correlation Plot")
image.png
data1 <- MASS::mvrnorm(100, colMeans(mtcars),  cov(mtcars))[, 1:8]
colnames(data1) <- paste("Var.", 1:ncol(data1))

# create plot
ggcorrm(data1, 
        mapping = aes(col = .corr, fill = .corr),
        bg_dia = "grey20", 
        rescale = "by_sd") +
  lotri(geom_smooth(method = "lm", size = .3)) +
  lotri(geom_point(alpha = 0.5)) +
  utri_corrtext(nrow = 2, squeeze = 0.6) +
  dia_names(y_pos = 0.15, size = 3, color = "white") +
  dia_histogram(lower = 0.3, color = "grey80", fill = "grey60", size = .3) +
  scale_color_corr(aesthetics = c("fill", "color"))
image.png
select(mtcars, mpg, disp:qsec) %>% 
ggcorrm(rescale = "by_sd") +
  utri_heatmap(alpha = 0.5) +
  lotri_heatcircle(alpha = 0.5, col = 1) +
  utri_corrtext() +
  dia_names(y_pos = 0.15, size = 3) +
  dia_density(lower = 0.3, fill = "lightgrey", color = 1) +
  scale_fill_corr() 
image.png
# function to compute linear model slopes
lmslope <- function(x, y)  round(coef(lm(x ~ y))[2], 2)

# add slopes using a function
ggcorrm(drosera, mapping = aes(col = species, fill = species)) +
  lotri(geom_point(alpha = 0.4)) +
  lotri(geom_smooth(alpha = 0.4, method = "lm")) +
  utri_funtext(fun = lmslope, squeeze = 0.6) +
  dia_density(lower = 0.3, col = 1, alpha = 0.4) +
  dia_names(y_pos = 0.15)
image.png

相关文章

网友评论

    本文标题:2021-04-28corrmorrant包快速绘制相关图

    本文链接:https://www.haomeiwen.com/subject/zwnmrltx.html