美文网首页
R语言相关性分析

R语言相关性分析

作者: MJades | 来源:发表于2021-03-30 23:00 被阅读0次

    1.  R语言自带函数cor(data, method=" ")可以快速计算出相关系数,数据类型:data.frame

     如data.frame为:zz, 绘图如下:

    a. single protein:线性回归画法

    1. ggplot(zz,aes(x=a, y=HDL))+

       geom_point(alpha=1,colour="#FFA54F")+

       geom_smooth(method = lm,colour="#8B658B")+

       #scale_color_brewer(palette = "Set1")+

       theme_bw()+

       labs(x="Ferritin",y="HDL.C",title="Pearson’s correlation test of ferritin and HDL.C")+

       annotate("text", x = 1000, y = 2.5, label = "r = -0.51",colour="black",size=4)

    2. library(ggstatsplot)

     ggscatterstats(data = alldata,

                   y = TRANSFUSION.UNIT,

                    x = NPTXR,

                    centrality.para = "mean",  #"mean" or "median"                         

                   margins = "both",                                       

                    xfill = "#D8BFD8",

                    yfill = "#EEDD82",

                    #line.size= ,

                    line.color="#8B6969",

                   point.color="#2F4F4F",

                    marginal.size=4,

                   marginal.type = "density", # "histogram", "boxplot", "density", "violin", "densigram")

                    title = "Relationship between TRANSFUSION.UNIT and NPTXR")

    b. ggcorrplot, 全部蛋白global correlation map 画法

    ggcorrplot(cor(alldata))

    2.  summary(lm(y~x),method=" ") %>%.[["coefficients"]]  正规线性回归

         (其实就是:a<-lm(y~x1+x2+...,data)

          plot(summary(lm(y~x),method=" ")) #绘图

    3.  ggcor部分数据绘图:  数据类型为data.frame,纵坐标为各指标or各蛋白,行为观测值。

    data <- fortify_cor(alldata[,10:11],alldata,cluster.type = "col")

    ggcor<-ggcor(data,label_size=0.5) +

      geom_colour()+

      theme(axis.text.x = element_text(colour = "black",size = 4.7),

                                                            axis.text.y=element_text(size=5.5),

                                                            axis.ticks=element_blank())+

      geom_num(aes(num=r),colour="black",size=1.5)

    4. corrr包画法

    datasets::mtcars %>%

      correlate() %>%

      focus(-cyl, -vs, mirror = TRUE) %>%

      rearrange() %>%

      network_plot(min_cor = .2)

    相关文章

      网友评论

          本文标题:R语言相关性分析

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