相关性分析
library(psych)
genedat <- read.table('index.txt', header = TRUE, sep = '\t')
antidat <- read.table('meta.txt',header = TRUE, sep = '\t')

res <- corr.test(genedat, antidat, use = 'pairwise', 
                 method = 'spearman', adjust = 'holm',
                 alpha = 0.05)
res$p.adj
res$r

library(pheatmap)
pdat <- res$r
pdat2 <- matrix(ifelse(abs(pdat) <= 0.3, 0, pdat), nrow(pdat))
pdat2 <- matrix(ifelse(res$p.adj >= 0.05, 0, pdat2), nrow(pdat))

colnames(pdat2) <- colnames(pdat)
rownames(pdat2) <- rownames(pdat)

bk <- seq(-1, 1, by = 0.1)
bk
length(bk)

mycol <- c(colorRampPalette(c('blue', 'white'))(9), 
           colorRampPalette(c('white', 'white'))(3),
           colorRampPalette(c('white', 'red'))(9))

pheatmap(pdat2, cellwidth = 15, cellheight = 15,
         cluster_cols = FALSE,
         color = mycol,
         legend_breaks = seq(-1,1,by = 0.2),
         breaks = bk)

pdat3 <- data.frame(x = rep(colnames(pdat2), each = 23),
                       y = rep(rownames(pdat2), 13),
                       r = as.vector(res$r),
                       p = as.vector(
                         ifelse(res$p.adj >= 0.05, 1, res$p.adj)
                       ))
#########1###############
library(ggplot2)
ggplot(pdat3, aes(x,y, colour = r, size = -log10(p))) +
  geom_point(aes(alpha = -log10(p))) + 
  scale_color_gradient2(low = 'blue',
                        mid = 'grey',
                        high = 'red',
                        midpoint = 0) +
  scale_size_area() + theme_bw() +
  theme(axis.text.x = element_text(angle = 90))
########################
library(readr)
df1<-read_tsv("index.txt")
head(df1)
df2<-read_tsv("meta.txt")
head(df2)
library(psych)
cor.result<-corr.test(df1,df2,method = "pearson")
library(tidyverse)
cor.result$p %>% 
  as.data.frame() %>% 
  rownames_to_column() %>% 
  pivot_longer(!rowname) %>% 
  mutate(p_value=case_when(
    value > 0.05 ~ "A",
    value >0.01 & value <= 0.05 ~ "B",
    value > 0.001 & value <= 0.01 ~ "D",
    value <= 0.001 ~ "E"
  )) -> new_df1

ggplot()+
  geom_tile(data=new_df1,
            aes(x=rowname,y=name,fill=p_value))+
  scale_fill_manual(values = c("white","#c0c0c0",
                               "#808080","#3f3f3f"))+
  theme(legend.key = element_rect(colour="black"),
        axis.text.x = element_text(angle = 90,hjust=1,vjust=0.5))+
  coord_equal()
cor.result$r %>% 
  as.data.frame() %>% 
  rownames_to_column() %>% 
  pivot_longer(!rowname) %>% 
  mutate(abs_cor=abs(value)) -> new_df2
###########2###############
library(paletteer)
ggplot()+
 # geom_tile(data=new_df1,
  #          aes(x=rowname,y=name,fill=p_value))+
  scale_fill_manual(values = c("white","#c0c0c0",
                               "#808080","#3f3f3f"))+
  theme(legend.key = element_rect(colour="black"),
        axis.text.x = element_text(angle = 90,hjust=1,vjust=0.5))+
  coord_equal()+
  geom_point(data=new_df2,
             aes(x=rowname,y=name,
                 size=abs_cor,
                 color=value))+
  scale_color_paletteer_c(palette = "ggthemes::Classic Red-Blue")
###########3###############
ggplot()+
  geom_tile(data=new_df1,
            aes(x=rowname,y=name,fill=p_value,alpha=p_value))+
  scale_fill_manual(values = c("white","#c0c0c0",
                               "#808080","#3f3f3f"),
                    label=c(">0.05",
                            "0.01~0.05",
                            "0.001~0.01",
                            "<0.01"))+
  scale_alpha_manual(values = c(0,1,1,1))+
  guides(alpha=F)+
  theme_bw()+
  theme(legend.key = element_rect(colour="black"),
        axis.text.x = element_text(angle = 90,
                                   hjust=1,
                                   vjust=0.5),)+
  coord_equal()+
  geom_point(data=new_df2,
             aes(x=rowname,y=name,
                 size=abs_cor,
                 color=value))+
  scale_color_paletteer_c(palette = "ggthemes::Classic Red-Blue")
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇