setwd("C:\\Users\\Administrator.DESKTOP-4UQ3Q0K\\Desktop")
library(dplyr)
library(ggplot2)
library(ggrepel)
library("readxl")
data<-read.csv("mk_fm.csv")
data$padj<-as.numeric(data$padj)
data$log10FDR <- -log10(data$padj)
data$group <- case_when(data$log2FoldChange > 1 & data$padj < 0.05 ~ "Up",
data$log2FoldChange < -1 & data$padj < 0.05 ~ "Down",
abs(data$log2FoldChange) <= 1 ~ "None",
data$padj >= 0.05 ~ "None")
top10sig <- filter(data,group!="None") %>% distinct(Symbol,.keep_all = T) %>% top_n(10,abs(log2FoldChange))
up <- filter(top10sig,group=="Up")
down <- filter(top10sig,group=="Down")
data$size <- case_when(!(data$Symbol%in% top10sig$Symbol)~ 1,data$Symbol %in% top10sig$Symbol ~ 2)
df <- filter(data,size==1)
df$group <- factor(df$group,
levels = c("Up","Down","None"),
ordered = T)
p0 <-ggplot(data=df,aes(log2FoldChange,log10FDR,color=group))
#添加散点;
p1 <- p0+geom_point(size=3)
p1
#自定义半透明颜色(红绿);
mycolor <- c("#FF99CC","#99CC00","gray80")
p22 <- p1 + scale_colour_manual(name="",values=alpha(mycolor,0.7))
p22
p2 <- p22+geom_point(data=up,aes(log2FoldChange,log10FDR),
color="#FF9999",size=4,alpha=0.9)+
geom_point(data=down,aes(log2FoldChange,log10FDR),
color="#7cae00",size=4,alpha=0.9)
p2
set.seed(007)
p6 <- p2+geom_label_repel(data = up,aes(log2FoldChange,log10FDR,label=Symbol),
nudge_x = 0.5,
nudge_y = 0.5,
color = "white",
alpha = 0.9,
point.padding = 0.8,
size = 5,
fill = "#96C93D",
segment.size = 0.6,
segment.color = "grey50",
direction = "y",
hjust = 0.5)
right.mar=0.2
bottom.mar=0.2
left.mar=0.2
top.mar=0.2
right.mar=0.2
bottom.mar=0.2
left.mar=0.2
p6
mytheme<-theme_classic()+
theme(text=element_text(family = "sans",colour ="gray30",size = 12),
axis.line = element_line(size = 0.6,colour = "gray30"),
axis.ticks = element_line(size = 0.6,colour = "gray30"),
axis.ticks.length = unit(1.5,units = "mm"),
plot.margin=unit(x=c(top.mar,right.mar,bottom.mar,left.mar),
units="inches"))
p6+mytheme
发现之前的KEGG得到结果有问题……将代码作了修改
KEGG
setwd("C:\\Users\\Administrator.DESKTOP-4UQ3Q0K\\Desktop")
library(clusterProfiler)
d<-read.csv("mk_fm_grp2all.csv")
## assume that 1st column is ID
## 2nd column is fold change
geneList <- d[,1]
geneList<-rownames(d) 这个
## feature 1: numeric vector
library(org.Mm.eg.db)
library(org.Hs.eg.db)
library(AnnotationHub)
library(dbplyr)
library(BiocFileCache)
geneList = d$X
## R里面的data.frame格式,可以用$colName的形式来提取特定列
geneList <- sort(geneList, decreasing = TRUE)
## feature 3: decreasing order(vector降序)
# R包msigdbr已经整理打包了MsigDB基因集,可以直接被clusterProfile采用.
library(msigdbr)
library(DOSE)
msigdbr_show_species()
m_df <- msigdbr(species = "Homo sapiens")
head(m_df, 2) %>% as.data.frame
data(geneList, package="DOSE") #富集分析的背景基因集
geneList<-rownames(d)
geneEntrezID <- bitr(geneList, fromType="SYMBOL", toType=c("ENTREZID","UNIPROT"), OrgDb="org.Hs.eg.db")
kk <- enrichKEGG(gene= geneEntrezID[,2],organism= 'mouse',pvalueCutoff = 0.05)
head(kk)
write.table (kk, file ="kk.txt", sep ="\t", row.names =TRUE, col.names =TRUE, quote =TRUE)
ekk <- enrichKEGG(gene = geneEntrezID$ENTREZID,
organism = 'hsa',
pvalueCutoff = 0.05)
write.csv(summary(ekk),"KEGG-enrich.csv",row.names =F)
p1 <- dotplot(ekk, showCategory = 15 ,title = "dotplot for enricher")
p1 <- barplot(ekk, showCategory = 20 ,title = "barplot for enricher")
library(DOSE)
data(geneList)
de <- names(geneList)[abs(geneList) > 2]
edo <- enrichDGN(de)
library(enrichplot)
barplot(edo, showCategory=20)
网友评论